Add htmx and format

This commit is contained in:
Andros Fenollosa 2021-11-12 13:52:41 +01:00
parent e43ed81638
commit 35e173697b
14 changed files with 83 additions and 51 deletions

View File

@ -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}'
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 exec -it formacion-htmx_django_1 bash

View File

@ -2,5 +2,5 @@ from django.apps import AppConfig
class WebsiteConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app.website'
default_auto_field = "django.db.models.BigAutoField"
name = "app.website"

View File

@ -8,9 +8,7 @@ class Profile(AbstractBaseUser):
"""User model"""
email = models.EmailField("Email", unique=True)
full_name = models.CharField(
max_length=100, verbose_name="Full name", default=""
)
full_name = models.CharField(max_length=100, verbose_name="Full name", default="")
avatar = models.ImageField(verbose_name="Avatar", upload_to="uploads/avatars/")
USERNAME_FIELD = "email" # make the user log in with the email

View 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>

View File

@ -0,0 +1,5 @@
{% extends 'layouts/base.html' %}
{% block content %}
Hola
{% endblock %}

View File

@ -1,3 +1,5 @@
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, "pages/posts.html")

View File

@ -11,6 +11,6 @@ import os
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()

View File

@ -35,40 +35,40 @@ if not os.environ.get("ALLOWED_HOSTS") == None:
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'channels',
'app.website',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_extensions",
"channels",
"app.website",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = 'event.urls'
ROOT_URLCONF = "event.urls"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "app", "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "app", "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
@ -94,16 +94,16 @@ DATABASES = {
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
# 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
@ -153,12 +153,10 @@ CHANNEL_LAYERS = {
}
# Default primary key field type
# 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:
CACHES = {

View File

@ -15,7 +15,9 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from app.website.views import index
urlpatterns = [
path('admin/', admin.site.urls),
path("", index, name="index"),
path("admin/", admin.site.urls),
]

View File

@ -11,6 +11,6 @@ import os
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()

View File

@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'event.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "event.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if __name__ == "__main__":
main()

View File

@ -1,9 +1,10 @@
from app.website.models import Category
from faker import Faker
def run():
fake = Faker()
# 5 categories
for word in [fake.unique.sentence(nb_words=1)[0:-1] for i in range(5)]:
Category(name=word).save()
Category(name=word).save()

View File

@ -8,6 +8,7 @@ import time
from tempfile import NamedTemporaryFile
from random import randint
def run():
fake = Faker()

View File

@ -8,17 +8,20 @@ import time
from tempfile import NamedTemporaryFile
from random import randint
def run():
fake = Faker()
# 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(
title=title,
category=Category.objects.order_by("?")[0],
author=Profile.objects.order_by("?")[0],
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()
@ -28,4 +31,4 @@ def run():
img_temp = NamedTemporaryFile(delete=True)
img_temp.write(r.content)
img_temp.flush()
my_talk.image.save(f"random_{int(time.time() * 1000)}.jpg", File(img_temp))
my_talk.image.save(f"random_{int(time.time() * 1000)}.jpg", File(img_temp))