Features: 1) Fallback to default avatar image in avatar_url method; 2) Added header component for admin dashboard template; 3) Improved layout sections in admin dashboard templates for consistent spacing;

Fixes: 1) Prevent `.initialized` file creation in debug mode;

Extra: 1) Refactored and reorganized admin dashboard templates for better readability and maintainability.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-12-10 21:44:17 +03:00
parent 76cea49c06
commit 625fe6e350
5 changed files with 103 additions and 84 deletions

View file

@ -185,6 +185,7 @@ class Command(BaseCommand):
(User.objects.filter(Q(language="") | ~Q(language__in=valid_codes)).update(language=settings.LANGUAGE_CODE))
try:
if not settings.DEBUG:
initialized_path.write_text(settings.RELEASE_DATE.isoformat(), encoding="utf-8")
except Exception as exc:
logger.error("Failed to update .initialized file: %s", exc)

View file

@ -1,6 +1,6 @@
{% load i18n unfold %}
<div class="flex flex-wrap items-center gap-2">
<div class="font-semibold text-2xl text-font-important-light tracking-tight dark:text-font-important-dark{% if class %} {{ class }}{% endif %}">
<a>{% trans "Dashboard" %}</a>
{% with cur=tf|default:30 %}
<a href="?tf=7"
class="px-3 py-1 rounded-full text-sm border transition-colors {% if cur == 7 %} bg-gray-900 text-white dark:bg-white dark:text-gray-900 border-transparent {% else %} border-gray-300 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800 {% endif %}">7d</a>

View file

@ -1,5 +1,6 @@
{% load i18n unfold %}
<div class="mt-6 md:mt-8">
{% component "unfold/components/card.html" %}
{% component "unfold/components/title.html" %}
{% trans "Most wished product" %}
@ -33,7 +34,8 @@
{% endcomponent %}
{% endif %}
{% endcomponent %}
</div>
<div class="mt-6 md:mt-8">
{% component "unfold/components/card.html" %}
{% component "unfold/components/title.html" %}
{% trans "Most popular product" %}
@ -67,3 +69,4 @@
{% endcomponent %}
{% endif %}
{% endcomponent %}
</div>

View file

@ -17,33 +17,44 @@
{% component "unfold/components/container.html" %}
<div class="flex flex-col min-h-screen">
{% component "unfold/components/title.html" %}
{% trans "Dashboard" %}
{% include "admin/dashboard/_filters.html" %}
{% include "admin/dashboard/_header.html" %}
{% endcomponent %}
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_kpis.html" %}
<div class="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start">
{% include "admin/dashboard/_daily_sales.html" %}
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_low_stock.html" %}
</div>
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_most_returned.html" %}
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_customers_mix.html" %}
{% if shipped_vs_digital.digital_qty|default:0 > 0 and shipped_vs_digital.shipped_qty|default:0 > 0 %}
{% include "admin/dashboard/_shipped_vs_digital.html" %}
{% endif %}
</div>
{% include "admin/dashboard/_top_categories.html" %}
{% include "admin/dashboard/_product_lists.html" %}
{% if shipped_vs_digital.digital_qty|default:0 > 0 and shipped_vs_digital.shipped_qty|default:0 > 0 %}
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_shipped_vs_digital.html" %}
</div>
{% endif %}
{% component "unfold/components/separator.html" %}
{% endcomponent %}
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_top_categories.html" %}
</div>
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_product_lists.html" %}
</div>
<div class="mt-6 md:mt-8">
{% include "admin/dashboard/_daily_sales.html" %}
</div>
{% component "unfold/components/separator.html" %}{% endcomponent %}
<div class="mt-4 mt-auto">
{% component "unfold/components/text.html" with class="text-center text-xs text-gray-500 dark:text-gray-400" %}

View file

@ -19,6 +19,7 @@ from django.db.models import (
TextField,
UUIDField,
)
from django.templatetags.static import static
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
@ -100,8 +101,11 @@ class User(AbstractUser, NiceModel): # type: ignore [django-manager-missing]
objects = UserManager() # type: ignore [misc, assignment]
@cached_property
def avatar_url(self):
def avatar_url(self) -> str:
try:
return self.avatar.url
except ValueError:
return static("person.png")
def add_to_recently_viewed(self, product_uuid):
recently_viewed = self.recently_viewed