diff --git a/backend/core/settings/unfold_conf.py b/backend/core/settings/unfold_conf.py index a8693a0..e7105d4 100644 --- a/backend/core/settings/unfold_conf.py +++ b/backend/core/settings/unfold_conf.py @@ -119,6 +119,7 @@ UNFOLD = { "title": _("نظرات"), "icon": "chat", "link": reverse_lazy("admin:product_commentmodel_changelist"), + "badge": "utils.admin.comment_count", }, { "title": _("قیمت دلار"), @@ -210,6 +211,7 @@ UNFOLD = { "title": _("تیکت"), "icon": "confirmation_number", "link": reverse_lazy("admin:ticket_ticket_changelist"), + "badge": "utils.admin.new_ticket_count", }, ], diff --git a/backend/core/views.py b/backend/core/views.py index 212a5bc..22fde64 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -8,6 +8,9 @@ from django.utils.translation import gettext_lazy as _ from django.views.generic import RedirectView, TemplateView from unfold.views import UnfoldModelAdminViewMixin from order.models import OrderModel +from ticket.models import Ticket + + class HomeView(RedirectView): pattern_name = "admin:index" @@ -16,8 +19,10 @@ class HomeView(RedirectView): def dashboard_callback(request, context): pending_count = OrderModel.objects.filter(status='ADMIN_PENDING').count() + open_tickets_count = Ticket.objects.filter(status__in=['open', 'in_progress']).count() context.update(random_data()) context.update({'pending_count': pending_count}) + context.update({'open_tickets_count': open_tickets_count}) return context diff --git a/backend/templates/formula/service.html b/backend/templates/formula/service.html index 1ddcb8b..664e402 100644 --- a/backend/templates/formula/service.html +++ b/backend/templates/formula/service.html @@ -5,8 +5,8 @@

notifications - سفارش جدید داری - {{ pending_count }} + سفارش جدید داری + {{ pending_count }}

@@ -18,4 +18,25 @@ {% endcomponent %} + +{% endif %} + +{% if open_tickets_count%} +
+
+

+ confirmation_number + تیکت جدید داری + {{ open_tickets_count }} +

+
+ +
+ {% component "unfold/components/flex.html" with class="flex-col gap-4 lg:flex-row" %} + {% component "unfold/components/button.html" with href="/admin/ticket/ticket/" %} + نمایش تیکت ها + {% endcomponent %} + {% endcomponent %} +
+
{% endif %} \ No newline at end of file diff --git a/backend/utils/admin.py b/backend/utils/admin.py index f4dc1be..dda3dfd 100644 --- a/backend/utils/admin.py +++ b/backend/utils/admin.py @@ -1,5 +1,8 @@ from order.models import OrderModel -from product.models import DollorModel +from product.models import DollorModel, CommentModel +from ticket.models import Ticket + + def admin_pending_count(request): pending_count = OrderModel.objects.filter(status='ADMIN_PENDING').count() return str(pending_count) @@ -7,3 +10,9 @@ def admin_pending_count(request): def dollor_price(request): dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique') return str(dollor_object.price)[:2] + +def comment_count(request): + return CommentModel.objects.all().count() + +def new_ticket_count(request): + return Ticket.objects.filter(status__in=['open', 'in_progress']).count() \ No newline at end of file