You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
from django.db.models import QuerySet
|
|
from django.urls import reverse_lazy
|
|
from django.views.generic import TemplateView, RedirectView, ListView
|
|
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 AllowedVehiclesView(ListView):
|
|
template_name = 'common/allowed-vehicles.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
lines_vehicles = {}
|
|
queryset = Booking.objects.filter(status='active')
|
|
for booking in queryset:
|
|
if lines_vehicles.get(booking.line.name) is None:
|
|
lines_vehicles[booking.line.name] = set()
|
|
vehicles = lines_vehicles[booking.line.name]
|
|
vehicles.update(booking.vehicles_left.split(','))
|
|
lines_vehicles[booking.line.name] = vehicles
|
|
context['objects'] = lines_vehicles
|
|
|
|
context['objects'] = [
|
|
type('Obj', (), {
|
|
'id': line_name,
|
|
'line': line_name,
|
|
'vehicles': ', '.join(sorted(vehicles))
|
|
}) for line_name, vehicles in lines_vehicles.items()
|
|
]
|
|
|
|
return context
|
|
|
|
def get_queryset(self):
|
|
return DepotUser.objects.none()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# class ClientPreinfoView(TemplateView):
|
|
# template_name = 'client-preinfo-content.html'
|
|
#
|
|
#
|
|
#
|
|
# def get(self, request, *args, **kwargs):
|
|
# return render(request, self.template_name, self.extra_context) |