fixed client dashboard

fixed employee sidebar nomenclatures buttons
This commit is contained in:
2025-08-03 17:25:23 +03:00
parent 9167092f27
commit f501be9794
13 changed files with 154 additions and 236 deletions
+41 -5
View File
@@ -1,24 +1,60 @@
from datetime import timedelta
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.shortcuts import render
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic import TemplateView, ListView, CreateView, UpdateView
from DepoT.mixins.LineFiltweFormMixin import LineFilterFormMixin
from booking.models import Booking
from common.forms.company import CompanyCreateForm, CompanyUpdateForm
from common.forms.line import LineCreateForm, LineUpdateForm
from common.models import CompanyModel, LinesModel
from common.utils.utils import filter_queryset_by_user
from containers.models import Container
from payments.models import Payment
from preinfo.models import Preinfo
from django.db.models import Q
class ClientDashboardView(TemplateView):
class ClientDashboardView(LoginRequiredMixin, TemplateView):
template_name = 'client-dashboard-content.html'
extra_context = {
'title': 'Client Dashboard',
'description': 'This is the client dashboard page.',
}
def get(self, request, *args, **kwargs):
return render(request, self.template_name, self.extra_context)
def test_func(self):
return self.request.user.user_type in ('CA', 'CL')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user = self.request.user
today = timezone.now()
last_week = today - timedelta(days=7)
containers_queryset = filter_queryset_by_user(Container.objects, user)
preinfo_queryset = filter_queryset_by_user(Preinfo.objects.filter(deleted=False), user)
bookings_queryset = filter_queryset_by_user(Booking.objects.filter(~Q(status='deleted')), user)
payment_queryset = Payment.objects.filter(company=user.company)
containers = containers_queryset.filter(expedited=False).count()
containers_week = containers_queryset.filter(received_on__gte=last_week).count()
preinfos = preinfo_queryset.filter(received=False).count()
preinfos_week = preinfo_queryset.filter(created_on__gte=last_week).count()
bookings = bookings_queryset.filter(status='active').count()
bookings_week = bookings_queryset.filter(created_on__gte=last_week).count()
context['containers'] = containers
context['preinfos'] = preinfos
context['bookings'] = bookings
context['containers_week'] = containers_week
context['preinfos_week'] = preinfos_week
context['bookings_week'] = bookings_week
context['recent_containers'] = containers_queryset.order_by('-expedited_on', '-received_on')[:10]
context['recent_payments'] = payment_queryset.order_by('-created_on')[:10]
return context
@@ -30,7 +66,7 @@ class ClientCompanyListView(LoginRequiredMixin, UserPassesTestMixin, ListView):
# base_template = 'client-base.html'
def test_func(self):
return True # self.request.user.has_employee_perm('can_view_preinfo') or self.request.user.user_type == 'CA'
return self.request.user.user_type in ('CA', 'CL')
# def get_context_data(self, **kwargs):
# context = super().get_context_data(**kwargs)