fix: cleanup
This commit is contained in:
@@ -4,6 +4,3 @@ from django.apps import AppConfig
|
||||
class WebConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'web'
|
||||
|
||||
def ready(self):
|
||||
from .signals import rebuild_theme
|
||||
|
||||
@@ -10,4 +10,5 @@ def web_settings(request):
|
||||
'web_title': settings.web_title,
|
||||
'logo': settings.logo_32.url if settings.logo_32 else '',
|
||||
'navbar_categories': navbar_categories,
|
||||
'favicon': settings.favicon_16.url if settings.favicon_16 else '',
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.management import call_command
|
||||
from web.models import WebSettings
|
||||
|
||||
|
||||
@dataclass
|
||||
class Color:
|
||||
name: str
|
||||
index: int
|
||||
value: str
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Usage:
|
||||
|
||||
python manage.py build_tailwind_theme
|
||||
"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
web_settings = WebSettings.load()
|
||||
path = os.path.join(settings.BASE_DIR, 'web', 'static', 'css', 'main.css')
|
||||
|
||||
colors = []
|
||||
for color_name, data in web_settings.theme_colors.items():
|
||||
for index, value in data.items():
|
||||
color = Color(color_name, index, value)
|
||||
colors.append(color)
|
||||
|
||||
result = str(render_to_string('theme/main.css.template', context={'colors': colors}))
|
||||
with open(path, 'w') as f:
|
||||
f.write(result)
|
||||
|
||||
subprocess.run(['tailwindcss', '-i', 'web/static/css/main.css', '-o', 'web/static/css/styles.css', '--minify'])
|
||||
call_command('collectstatic', '--no-input')
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 6.0.2 on 2026-03-20 08:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('web', '0004_websettings_logo_32_websettings_logo_64'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='websettings',
|
||||
name='favicon_16',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='assets', verbose_name='favicon 16x16'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='websettings',
|
||||
name='favicon_32',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='assets', verbose_name='favicon 32x32'),
|
||||
),
|
||||
]
|
||||
+10
-3
@@ -50,16 +50,20 @@ class WebSettings(SingletonModel):
|
||||
logo_128 = models.ImageField(upload_to='assets', blank=True, null=True, verbose_name=_('logo 128x128'))
|
||||
logo_64 = models.ImageField(upload_to='assets', blank=True, null=True, verbose_name=_('logo 64x64'))
|
||||
logo_32 = models.ImageField(upload_to='assets', blank=True, null=True, verbose_name=_('logo 32x32'))
|
||||
|
||||
favicon_32 = models.ImageField(upload_to='assets', blank=True, null=True, verbose_name=_('favicon 32x32'))
|
||||
favicon_16 = models.ImageField(upload_to='assets', blank=True, null=True, verbose_name=_('favicon 16x16'))
|
||||
|
||||
theme_colors = models.JSONField(default=dict, verbose_name=_('colores del tema'), blank=True)
|
||||
|
||||
def get_resized_logo(self, size):
|
||||
def get_resized_logo(self, size, extension: str = 'png'):
|
||||
width, height = size
|
||||
image = Image.open(self.logo)
|
||||
image = image.resize(size, Image.Resampling.LANCZOS)
|
||||
buffer = BytesIO()
|
||||
image.save(fp=buffer, format='PNG')
|
||||
image.save(fp=buffer, format=extension.upper())
|
||||
|
||||
return ContentFile(buffer.getvalue(), name=f'logo_{width}.png')
|
||||
return ContentFile(buffer.getvalue(), name=f'logo_{width}.{extension}')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.logo:
|
||||
@@ -68,6 +72,9 @@ class WebSettings(SingletonModel):
|
||||
self.logo_128 = self.get_resized_logo((128, 128))
|
||||
self.logo_256 = self.get_resized_logo((256, 256))
|
||||
|
||||
self.favicon_16 = self.get_resized_logo((16, 16), extension='ico')
|
||||
self.favicon_32 = self.get_resized_logo((32, 32), extension='ico')
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -15,11 +15,3 @@ def clear_cart(sender, **kwargs):
|
||||
@receiver(send_order_email, dispatch_uid='send_order_email')
|
||||
def create_payment_from_redsys(sender, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
@receiver(post_save, sender=WebSettings)
|
||||
def rebuild_theme(sender, instance: WebSettings, **kwargs):
|
||||
try:
|
||||
call_command('build_tailwind_theme')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
+2155
-2
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
<nav class="flex justify-between navbar bg-base-300 shadow-md px-4 fixed top-0 z-10 left-0 w-full">
|
||||
<nav class="navbar">
|
||||
<div class="text-base-content">
|
||||
<a href="{% url 'web:index' %}" class="flex text-xl">
|
||||
<img class="mr-4" src="{{ logo }}" alt="{{ web_title }} logo">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% load i18n %}
|
||||
<article class="rounded-lg border-primary p-6 shadow-sm">
|
||||
<article class="card">
|
||||
|
||||
<a class="h-56 w-full" href="{% url 'web:product_detail' pk=product.pk slug=product.slug %}">
|
||||
<img class="mx-auto h-full " src="{{ product.images.all.0.m.url }}" alt="{{ product.name }}"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<link rel="manifest" href="{% url 'web:manifest_json' %}">
|
||||
|
||||
{% include "theme/seo.html" %}
|
||||
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
|
||||
<link rel="shortcut icon" type="image/png" href="{{ favicon }}"/>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" />
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@import "tailwindcss";
|
||||
@import "./components.css";
|
||||
|
||||
|
||||
@theme {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
|
||||
<ul class="mb-4 grid gap-4 sm:grid-cols-2 md:mb-8 lg:grid-cols-3 xl:grid-cols-4 3xl:grid-cols-5">
|
||||
<ul class="product-grid">
|
||||
{% for product in page %}
|
||||
<li>
|
||||
{% include 'components/product_card.html' %}
|
||||
|
||||
Reference in New Issue
Block a user