From eb425cc0a6a607d3e24afa2310065313cc4ce11d Mon Sep 17 00:00:00 2001 From: Pablo Moreno Date: Thu, 5 Dec 2024 21:14:57 +0100 Subject: [PATCH] feat: added new settings and styling --- config/settings/environ.py | 8 +- scripts/build_static.sh | 2 + web/migrations/0001_initial.py | 123 +++++++++++++++++- web/models.py | 67 ++++++++++ web/templates/components/cart/cart.html | 13 +- .../components/cart/cart_navbar.html | 2 +- web/templates/users/login.html | 11 +- web/urls.py | 3 + web/views/web.py | 39 +++++- 9 files changed, 250 insertions(+), 18 deletions(-) diff --git a/config/settings/environ.py b/config/settings/environ.py index 8321115..8818fed 100644 --- a/config/settings/environ.py +++ b/config/settings/environ.py @@ -15,8 +15,12 @@ if os.path.exists(env_file): SECRET_KEY = env.str("SECRET_KEY", "this-is-the-default-secret-key") DEBUG = env.bool("DEBUG", True) -CORS_ORIGIN_WHITELIST = env.str("CORS_ORIGIN_WHITELIST", "http://localhost:8000").split(",") -CSRF_TRUSTED_ORIGINS = env.str("CSRF_TRUSTED_ORIGINS", "http://localhost:8000").split(",") +CORS_ORIGIN_WHITELIST = env.str("CORS_ORIGIN_WHITELIST", "http://localhost:8000").split( + "," +) +CSRF_TRUSTED_ORIGINS = env.str("CSRF_TRUSTED_ORIGINS", "http://localhost:8000").split( + "," +) DATABASE_URL = env.db_url("DATABASE_URL", "sqlite:///db.sqlite3") diff --git a/scripts/build_static.sh b/scripts/build_static.sh index 31fb33c..01415ce 100644 --- a/scripts/build_static.sh +++ b/scripts/build_static.sh @@ -11,6 +11,8 @@ python manage.py tailwind install python manage.py tailwind build python manage.py collectstatic --noinput +# Clean npm rm -rf ~/.nvm rm -rf ~/.npm rm -rf ~/.bower +rm -rf /code/theme/static_src/node_modules/ diff --git a/web/migrations/0001_initial.py b/web/migrations/0001_initial.py index 8ee4864..b14f983 100644 --- a/web/migrations/0001_initial.py +++ b/web/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.3 on 2024-12-01 11:25 +# Generated by Django 5.1.3 on 2024-12-05 20:12 from django.db import migrations, models @@ -44,6 +44,127 @@ class Migration(migrations.Migration): verbose_name="logo de la web", ), ), + ( + "business_name", + models.CharField( + blank=True, + help_text="nombre fiscal del comercio", + max_length=128, + null=True, + verbose_name="nombre de negocio", + ), + ), + ( + "business_vat_id", + models.CharField( + blank=True, + max_length=16, + null=True, + verbose_name="CIF del negocio", + ), + ), + ( + "business_brand", + models.CharField( + blank=True, + help_text="marca o nombre comercial que se va a mostrar en la web", + max_length=64, + null=True, + verbose_name="marca de negocio", + ), + ), + ( + "business_address", + models.CharField( + blank=True, + max_length=64, + null=True, + verbose_name="dirección de negocio", + ), + ), + ( + "business_state", + models.CharField( + blank=True, + max_length=32, + null=True, + verbose_name="unidad territorial del negocio", + ), + ), + ( + "business_zip", + models.CharField( + blank=True, + max_length=16, + null=True, + verbose_name="código postal del negocio", + ), + ), + ( + "business_phone", + models.CharField( + blank=True, + max_length=16, + null=True, + verbose_name="número de teléfono de contacto", + ), + ), + ( + "business_email", + models.EmailField( + blank=True, + max_length=80, + null=True, + verbose_name="e-mail de contacto", + ), + ), + ( + "business_email_2", + models.EmailField( + blank=True, + max_length=80, + null=True, + verbose_name="e-mail secundario de contacto", + ), + ), + ( + "bg_color", + models.CharField( + blank=True, + default="", + max_length=9, + null=True, + verbose_name="color de fondo", + ), + ), + ( + "theme_color", + models.CharField( + blank=True, + default="", + max_length=9, + null=True, + verbose_name="color de tema", + ), + ), + ( + "logo_240", + models.ImageField( + blank=True, + null=True, + upload_to="assets", + verbose_name="logo 240x240", + ), + ), + ( + "logo_128", + models.ImageField( + blank=True, + null=True, + upload_to="assets", + verbose_name="logo 128x128", + ), + ), ], options={ "verbose_name": "ajustes de la web", diff --git a/web/models.py b/web/models.py index aae4eab..e6cdcbc 100644 --- a/web/models.py +++ b/web/models.py @@ -15,6 +15,73 @@ class WebSettings(SingletonModel): blank=True, null=True, upload_to="assets", verbose_name=_("logo de la web") ) + business_name = models.CharField( + max_length=128, + blank=True, + null=True, + verbose_name=_("nombre de negocio"), + help_text=_("nombre fiscal del comercio"), + ) + business_vat_id = models.CharField( + max_length=16, blank=True, null=True, verbose_name=_("CIF del negocio") + ) + business_brand = models.CharField( + max_length=64, + blank=True, + null=True, + verbose_name=_("marca de negocio"), + help_text=_("marca o nombre comercial que se va a mostrar en la web"), + ) + + business_address = models.CharField( + max_length=64, blank=True, null=True, verbose_name=_("dirección de negocio") + ) + business_state = models.CharField( + max_length=32, + blank=True, + null=True, + verbose_name=_("unidad territorial del negocio"), + ) + business_zip = models.CharField( + max_length=16, + blank=True, + null=True, + verbose_name=_("código postal del negocio"), + ) + + business_phone = models.CharField( + max_length=16, + blank=True, + null=True, + verbose_name=_("número de teléfono de contacto"), + ) + business_email = models.EmailField( + max_length=80, blank=True, null=True, verbose_name=_("e-mail de contacto") + ) + business_email_2 = models.EmailField( + max_length=80, + blank=True, + null=True, + verbose_name=_("e-mail secundario de contacto"), + ) + + bg_color = models.CharField( + max_length=9, + default="", + blank=True, + null=True, + verbose_name=_("color de fondo"), + ) + theme_color = models.CharField( + max_length=9, default="", blank=True, null=True, verbose_name=_("color de tema") + ) + logo_240 = models.ImageField( + upload_to="assets", blank=True, null=True, verbose_name=_("logo 240x240") + ) + logo_128 = models.ImageField( + upload_to="assets", blank=True, null=True, verbose_name=_("logo 128x128") + ) + class Meta: verbose_name = _("ajustes de la web") verbose_name_plural = _("ajustes de la web") diff --git a/web/templates/components/cart/cart.html b/web/templates/components/cart/cart.html index 64fe5a6..475566e 100644 --- a/web/templates/components/cart/cart.html +++ b/web/templates/components/cart/cart.html @@ -33,16 +33,13 @@
- {{ item.product.name }} + + {{ item.product.name }} +
- -
{% csrf_token %} diff --git a/web/templates/components/cart/cart_navbar.html b/web/templates/components/cart/cart_navbar.html index 2d37cd4..ed099b2 100644 --- a/web/templates/components/cart/cart_navbar.html +++ b/web/templates/components/cart/cart_navbar.html @@ -27,7 +27,7 @@ {% for cart_item in cart.items.all %}
- {{ cart_item.product.name }} diff --git a/web/templates/users/login.html b/web/templates/users/login.html index eaf0b1d..eadc1e9 100644 --- a/web/templates/users/login.html +++ b/web/templates/users/login.html @@ -1,4 +1,5 @@ {% extends 'theme/base.html' %} +{% load i18n %} {% load web %} {% block main %} @@ -14,7 +15,7 @@ class="w-full bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700">

- Sign in to your account + {% translate 'Inicia sesión en tu cuenta' %}

{% csrf_token %} @@ -40,11 +41,11 @@ {% endfor %} -

- Don’t have an account yet? - Sign up +

+ {% translate '¿Aún no tienes cuenta?' %} + {% translate 'Regístrate aquí' %}

diff --git a/web/urls.py b/web/urls.py index 88930d6..702c4a1 100644 --- a/web/urls.py +++ b/web/urls.py @@ -7,6 +7,7 @@ from web.views.web import ( cart_detail, delete_cart_item, index, + manifest, product_detail, ) @@ -28,4 +29,6 @@ urlpatterns = [ # api path("web/add-cart-item/", add_cart_item, name="add_cart_item"), path("web/delete-cart-item//", delete_cart_item, name="delete_cart_item"), + # manifest + path("manifest.json", manifest, name="manifest_json"), ] diff --git a/web/views/web.py b/web/views/web.py index 4747fbf..e379c6c 100644 --- a/web/views/web.py +++ b/web/views/web.py @@ -1,4 +1,4 @@ -from django.http.response import HttpResponse +from django.http.response import HttpResponse, JsonResponse from django.shortcuts import get_object_or_404 from django.utils.text import gettext_lazy as _ from django.views.decorators.http import require_http_methods @@ -97,6 +97,43 @@ def delete_cart_item(request, pk, *args, **kwargs): return HttpResponse(status=204, headers={"HX-Trigger": "updated-cart"}) +def manifest(request, *args, **kwargs): + settings = WebSettings.load() + + data = { + "name": settings.web_title, + "short_name": settings.web_title, + "start_url": "/", + "background_color": settings.bg_color, + "theme_color": settings.theme_color, + "icons": [], + "display": "standalone", + "orientation": "portrait", + } + + if settings.logo_240: + data["icons"].append( + { + "src": settings.logo_240.url, + "sizes": "240x240", + "type": "image/png", + "purpose": "maskable any", + } + ) + + if settings.logo_128: + data["icons"].append( + { + "src": settings.logo_128.url, + "sizes": "240x240", + "type": "image/png", + "purpose": "maskable any", + } + ) + + return JsonResponse(data) + + index = IndexView.as_view() product_detail = ProductDetail.as_view() cart_detail = CartDetail.as_view()