feat: added new settings and styling

This commit is contained in:
2024-12-05 21:14:57 +01:00
parent 313fb0cb3b
commit eb425cc0a6
9 changed files with 250 additions and 18 deletions
+6 -2
View File
@@ -15,8 +15,12 @@ if os.path.exists(env_file):
SECRET_KEY = env.str("SECRET_KEY", "this-is-the-default-secret-key") SECRET_KEY = env.str("SECRET_KEY", "this-is-the-default-secret-key")
DEBUG = env.bool("DEBUG", True) DEBUG = env.bool("DEBUG", True)
CORS_ORIGIN_WHITELIST = env.str("CORS_ORIGIN_WHITELIST", "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(",") ","
)
CSRF_TRUSTED_ORIGINS = env.str("CSRF_TRUSTED_ORIGINS", "http://localhost:8000").split(
","
)
DATABASE_URL = env.db_url("DATABASE_URL", "sqlite:///db.sqlite3") DATABASE_URL = env.db_url("DATABASE_URL", "sqlite:///db.sqlite3")
+2
View File
@@ -11,6 +11,8 @@ python manage.py tailwind install
python manage.py tailwind build python manage.py tailwind build
python manage.py collectstatic --noinput python manage.py collectstatic --noinput
# Clean npm
rm -rf ~/.nvm rm -rf ~/.nvm
rm -rf ~/.npm rm -rf ~/.npm
rm -rf ~/.bower rm -rf ~/.bower
rm -rf /code/theme/static_src/node_modules/
+122 -1
View File
@@ -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 from django.db import migrations, models
@@ -44,6 +44,127 @@ class Migration(migrations.Migration):
verbose_name="logo de la web", 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={ options={
"verbose_name": "ajustes de la web", "verbose_name": "ajustes de la web",
+67
View File
@@ -15,6 +15,73 @@ class WebSettings(SingletonModel):
blank=True, null=True, upload_to="assets", verbose_name=_("logo de la web") 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: class Meta:
verbose_name = _("ajustes de la web") verbose_name = _("ajustes de la web")
verbose_name_plural = _("ajustes de la web") verbose_name_plural = _("ajustes de la web")
+5 -8
View File
@@ -33,16 +33,13 @@
</div> </div>
<div class="w-full min-w-0 flex-1 space-y-4 md:order-2 md:max-w-md"> <div class="w-full min-w-0 flex-1 space-y-4 md:order-2 md:max-w-md">
<a href="#" <a href="{% url 'web:product_detail' pk=item.product.pk slug=item.product.slug %}"
class="text-base font-medium text-gray-900 hover:underline dark:text-white">{{ item.product.name }}</a> class="text-base font-medium text-gray-900 hover:underline dark:text-white"
>
{{ item.product.name }}
</a>
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<button type="button"
class="inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-900 hover:underline dark:text-gray-400 dark:hover:text-white">
{% include 'components/icons/like.svg' %}
{% translate 'Añadir a favoritos' %}
</button>
<form class="flex" hx-post="{% url 'web:delete_cart_item' pk=item.pk %}" <form class="flex" hx-post="{% url 'web:delete_cart_item' pk=item.pk %}"
hx-swap="none"> hx-swap="none">
{% csrf_token %} {% csrf_token %}
@@ -27,7 +27,7 @@
{% for cart_item in cart.items.all %} {% for cart_item in cart.items.all %}
<div> <div>
<a href="#" <a href="{% url 'web:product_detail' pk=cart_item.product.pk slug=cart_item.product.slug %}"
class="truncate text-sm font-semibold leading-none text-gray-900 dark:text-white hover:underline"> class="truncate text-sm font-semibold leading-none text-gray-900 dark:text-white hover:underline">
{{ cart_item.product.name }} {{ cart_item.product.name }}
</a> </a>
+6 -5
View File
@@ -1,4 +1,5 @@
{% extends 'theme/base.html' %} {% extends 'theme/base.html' %}
{% load i18n %}
{% load web %} {% load web %}
{% block main %} {% 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"> 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">
<div class="p-6 space-y-4 md:space-y-6 sm:p-8"> <div class="p-6 space-y-4 md:space-y-6 sm:p-8">
<h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white"> <h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
Sign in to your account {% translate 'Inicia sesión en tu cuenta' %}
</h1> </h1>
<form action="{% url 'web:login' %}" method="post"> <form action="{% url 'web:login' %}" method="post">
{% csrf_token %} {% csrf_token %}
@@ -40,11 +41,11 @@
{% endfor %} {% endfor %}
<button <button
class="w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"> class="w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
Login {% translate 'Iniciar sesión' %}
</button> </button>
<p class="text-sm font-light text-gray-500 dark:text-gray-400"> <p class="text-sm font-light text-gray-500 mt-4 dark:text-gray-400">
Dont have an account yet? {% translate '¿Aún no tienes cuenta?' %}
<a href="#" class="font-medium text-primary-600 hover:underline dark:text-primary-500">Sign up</a> <a href="#" class="font-medium text-primary-600 hover:underline dark:text-primary-500">{% translate 'Regístrate aquí' %}</a>
</p> </p>
</form> </form>
</div> </div>
+3
View File
@@ -7,6 +7,7 @@ from web.views.web import (
cart_detail, cart_detail,
delete_cart_item, delete_cart_item,
index, index,
manifest,
product_detail, product_detail,
) )
@@ -28,4 +29,6 @@ urlpatterns = [
# api # api
path("web/add-cart-item/", add_cart_item, name="add_cart_item"), path("web/add-cart-item/", add_cart_item, name="add_cart_item"),
path("web/delete-cart-item/<int:pk>/", delete_cart_item, name="delete_cart_item"), path("web/delete-cart-item/<int:pk>/", delete_cart_item, name="delete_cart_item"),
# manifest
path("manifest.json", manifest, name="manifest_json"),
] ]
+38 -1
View File
@@ -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.shortcuts import get_object_or_404
from django.utils.text import gettext_lazy as _ from django.utils.text import gettext_lazy as _
from django.views.decorators.http import require_http_methods 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"}) 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() index = IndexView.as_view()
product_detail = ProductDetail.as_view() product_detail = ProductDetail.as_view()
cart_detail = CartDetail.as_view() cart_detail = CartDetail.as_view()