Add htmx and format
This commit is contained in:
parent
e43ed81638
commit
35e173697b
2
Makefile
2
Makefile
@ -3,7 +3,7 @@ help:
|
|||||||
@perl -nle'print $& if m{^[a-zA-Z_-|.]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
|
@perl -nle'print $& if m{^[a-zA-Z_-|.]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
run.format: ## Format style with black
|
run.format: ## Format style with black
|
||||||
docker-compose -f docker-compose.dev.yaml exec -T django bash -c "black --exclude='/(postgres|venv|migrations|node_modules|\.git)/' ."
|
docker-compose -f docker-compose.yaml exec -T django bash -c "black --exclude='/(postgres|venv|migrations|node_modules|\.git)/' ."
|
||||||
|
|
||||||
docker.bash: ## Enter bash terminal
|
docker.bash: ## Enter bash terminal
|
||||||
docker exec -it formacion-htmx_django_1 bash
|
docker exec -it formacion-htmx_django_1 bash
|
||||||
|
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
|
|
||||||
class WebsiteConfig(AppConfig):
|
class WebsiteConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = 'app.website'
|
name = "app.website"
|
||||||
|
@ -8,9 +8,7 @@ class Profile(AbstractBaseUser):
|
|||||||
"""User model"""
|
"""User model"""
|
||||||
|
|
||||||
email = models.EmailField("Email", unique=True)
|
email = models.EmailField("Email", unique=True)
|
||||||
full_name = models.CharField(
|
full_name = models.CharField(max_length=100, verbose_name="Full name", default="")
|
||||||
max_length=100, verbose_name="Full name", default=""
|
|
||||||
)
|
|
||||||
avatar = models.ImageField(verbose_name="Avatar", upload_to="uploads/avatars/")
|
avatar = models.ImageField(verbose_name="Avatar", upload_to="uploads/avatars/")
|
||||||
|
|
||||||
USERNAME_FIELD = "email" # make the user log in with the email
|
USERNAME_FIELD = "email" # make the user log in with the email
|
||||||
|
22
app/website/templates/layouts/base.html
Normal file
22
app/website/templates/layouts/base.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>htmx demo</title>
|
||||||
|
<link rel="icon" type="image/png" href="favicon.png">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
|
||||||
|
<meta name="author" content="Andros Fenollosa">
|
||||||
|
<meta name="generator" content="Django">
|
||||||
|
<meta name="description" content="Demo WebSockets over HTML with htmx">
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
{# Styles #}
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static "css/normalize.css" %}">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static "css/pico.min.css" %}">
|
||||||
|
{# JavaScript #}
|
||||||
|
<script defer src="{% static "js/htmx.min.js" %}"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
5
app/website/templates/pages/posts.html
Normal file
5
app/website/templates/pages/posts.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{% extends 'layouts/base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
Hola
|
||||||
|
{% endblock %}
|
@ -1,3 +1,5 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
|
def index(request):
|
||||||
|
return render(request, "pages/posts.html")
|
||||||
|
@ -11,6 +11,6 @@ import os
|
|||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'event.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "event.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
|
@ -35,40 +35,40 @@ if not os.environ.get("ALLOWED_HOSTS") == None:
|
|||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
"django.contrib.admin",
|
||||||
'django.contrib.auth',
|
"django.contrib.auth",
|
||||||
'django.contrib.contenttypes',
|
"django.contrib.contenttypes",
|
||||||
'django.contrib.sessions',
|
"django.contrib.sessions",
|
||||||
'django.contrib.messages',
|
"django.contrib.messages",
|
||||||
'django.contrib.staticfiles',
|
"django.contrib.staticfiles",
|
||||||
'django_extensions',
|
"django_extensions",
|
||||||
'channels',
|
"channels",
|
||||||
'app.website',
|
"app.website",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
"django.middleware.security.SecurityMiddleware",
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
'django.middleware.common.CommonMiddleware',
|
"django.middleware.common.CommonMiddleware",
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'event.urls'
|
ROOT_URLCONF = "event.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
'DIRS': [os.path.join(BASE_DIR, "app", "templates")],
|
"DIRS": [os.path.join(BASE_DIR, "app", "templates")],
|
||||||
'APP_DIRS': True,
|
"APP_DIRS": True,
|
||||||
'OPTIONS': {
|
"OPTIONS": {
|
||||||
'context_processors': [
|
"context_processors": [
|
||||||
'django.template.context_processors.debug',
|
"django.template.context_processors.debug",
|
||||||
'django.template.context_processors.request',
|
"django.template.context_processors.request",
|
||||||
'django.contrib.auth.context_processors.auth',
|
"django.contrib.auth.context_processors.auth",
|
||||||
'django.contrib.messages.context_processors.messages',
|
"django.contrib.messages.context_processors.messages",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -94,16 +94,16 @@ DATABASES = {
|
|||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -111,9 +111,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'es-es'
|
LANGUAGE_CODE = "es-es"
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = "UTC"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
@ -153,12 +153,10 @@ CHANNEL_LAYERS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
CACHES = {
|
CACHES = {
|
||||||
|
@ -15,7 +15,9 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
from app.website.views import index
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path("", index, name="index"),
|
||||||
|
path("admin/", admin.site.urls),
|
||||||
]
|
]
|
||||||
|
@ -11,6 +11,6 @@ import os
|
|||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'event.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "event.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
@ -6,7 +6,7 @@ import sys
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'event.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "event.settings")
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
@ -18,5 +18,5 @@ def main():
|
|||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from app.website.models import Category
|
from app.website.models import Category
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import time
|
|||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
|
|
||||||
|
@ -8,17 +8,20 @@ import time
|
|||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
|
|
||||||
# 100 talks
|
# 100 talks
|
||||||
for title in [fake.unique.sentence(nb_words=10)[0:-1] for i in range(100)]:
|
for title in [fake.unique.sentence(nb_words=5)[0:-1] for i in range(100)]:
|
||||||
my_talk = Talk(
|
my_talk = Talk(
|
||||||
title=title,
|
title=title,
|
||||||
category=Category.objects.order_by("?")[0],
|
category=Category.objects.order_by("?")[0],
|
||||||
author=Profile.objects.order_by("?")[0],
|
author=Profile.objects.order_by("?")[0],
|
||||||
is_draft=False,
|
is_draft=False,
|
||||||
content=fake.text(max_nb_chars=1000),
|
content="<p>"
|
||||||
|
+ "</p><p>".join(fake.paragraph(nb_sentences=randint(5, 10)))
|
||||||
|
+ "</p>",
|
||||||
)
|
)
|
||||||
my_talk.save()
|
my_talk.save()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user