from django.urls import reverse_lazy from django.views.generic import TemplateView, RedirectView from django.shortcuts import render from accounts.models import DepotUser from booking.models import Booking from containers.models import Container from preinfo.models import Preinfo # Create your views here. class IndexView(TemplateView): template_name = 'landing-page.html' extra_context = { 'title': 'Home', 'description': 'This is the home page of the container application.', } def get(self, request, *args, **kwargs): return render(request, self.template_name, self.extra_context) class DashboardRedirectView(RedirectView): is_permanent = False def get_redirect_url(self, *args, **kwargs): # if self.request.user.is_authenticated: if self.request.user.user_type == DepotUser.UserType.COMPANY_ADMIN: return reverse_lazy('client_dashboard') elif self.request.user.user_type == DepotUser.UserType.CLIENT: return reverse_lazy('client_dashboard') elif self.request.user.user_type == DepotUser.UserType.BARRIER_STAFF: return reverse_lazy('barrier_dashboard') elif self.request.user.user_type == DepotUser.UserType.EMPLOYEE: return reverse_lazy('employee_dashboard') elif self.request.user.user_type == DepotUser.UserType.ADMIN: return reverse_lazy('employee_dashboard') return reverse_lazy('index') class ClientDashboardView(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) class BarrierDashboardView(TemplateView): template_name = 'barrier-dashboard.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) class EmployeeDashboardView(TemplateView): template_name = 'employee-dashboard-content.html' extra_context = { 'title': 'Employee Dashboard', 'description': 'This is the depot employee dashboard page.', } def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) containers = Container.objects.filter(expedited=False).count() preinfos = Preinfo.objects.filter(received=False).count() bookings = Booking.objects.filter(status='active').count() context['containers'] = containers context['preinfos'] = preinfos context['bookings'] = bookings return context # class ClientPreinfoView(TemplateView): # template_name = 'client-preinfo-content.html' # # # # def get(self, request, *args, **kwargs): # return render(request, self.template_name, self.extra_context)