buttons in table footer
This commit is contained in:
@@ -1,52 +1,62 @@
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView, ListView
|
||||
|
||||
from booking.forms import BookingCreateForm
|
||||
from DepoT.mixins.LineFiltweFormMixin import LineFilterFormMixin
|
||||
from booking.forms import BookingCreateForm, BookingUpdateForm
|
||||
from booking.models import Booking
|
||||
from common.utils.utils import filter_queryset_by_user
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class CreateBookingView(CreateView):
|
||||
template_name = 'client-booking-content.html'
|
||||
class ClientBookingView(LoginRequiredMixin, UserPassesTestMixin, ListView):
|
||||
model = Booking
|
||||
form_class = BookingCreateForm
|
||||
success_url = reverse_lazy('client_booking')
|
||||
template_name = 'client/booking-list.html'
|
||||
paginate_by = 4
|
||||
context_object_name = 'objects'
|
||||
base_template = 'client-base.html'
|
||||
|
||||
def test_func(self):
|
||||
return self.request.user.has_company_perm('can_view_booking') or self.request.user.user_type == 'CA'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
queryset = self.model.objects.all().order_by('-created_on')
|
||||
user = self.request.user
|
||||
# !!! important
|
||||
queryset = filter_queryset_by_user( queryset, user)[:10]
|
||||
# !!! important
|
||||
context['recent'] = queryset
|
||||
context['base_template'] = self.base_template
|
||||
return context
|
||||
|
||||
def get_form(self, form_class=None):
|
||||
form = super().get_form(form_class)
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
user = self.request.user
|
||||
result = filter_queryset_by_user(queryset, user)
|
||||
return result
|
||||
|
||||
# If user has a specific line, limit the line choices
|
||||
if user.line:
|
||||
form.fields['line'].queryset = form.fields['line'].queryset.filter(pk=user.line.pk)
|
||||
form.fields['line'].initial = user.line
|
||||
form.fields['line'].widget.readonly = True #attrs['disabled'] = True
|
||||
return form
|
||||
|
||||
class CreateBookingView(LoginRequiredMixin, UserPassesTestMixin, LineFilterFormMixin, CreateView):
|
||||
template_name = 'client/booking-create.html'
|
||||
model = Booking
|
||||
form_class = BookingCreateForm
|
||||
success_url = reverse_lazy('client_booking')
|
||||
|
||||
def form_valid(self, form):
|
||||
# todo more validation
|
||||
form.instance.created_by = self.request.user.id
|
||||
form.instance.updated_by = self.request.user.id
|
||||
form.instance.vehicles_left = form.cleaned_data.get('vehicles')
|
||||
if self.request.user.line:
|
||||
form.instance.line = self.request.user.line
|
||||
return super().form_valid(form)
|
||||
|
||||
def test_func(self):
|
||||
return True # self.request.user.has_company_perm('can_edit_preinfo') or self.request.user.user_type == 'CA'
|
||||
|
||||
class BookingListView(ListView):
|
||||
template_name = 'employee/booking-list.html'
|
||||
|
||||
class ClientBookingUpdateView(LoginRequiredMixin, UserPassesTestMixin, LineFilterFormMixin, CreateView):
|
||||
template_name = 'client/booking-edit.html'
|
||||
model = Booking
|
||||
context_object_name = 'bookings'
|
||||
paginate_by = 30 # Number of containers per page
|
||||
form_class = BookingUpdateForm
|
||||
success_url = reverse_lazy('client_booking')
|
||||
|
||||
def form_valid(self, form):
|
||||
# todo more validation
|
||||
form.instance.updated_by = self.request.user.id
|
||||
return super().form_valid(form)
|
||||
|
||||
def test_func(self):
|
||||
return True # self.request.user.has_company_perm('can_edit_preinfo') or self.request.user.user_type == 'CA'
|
||||
Reference in New Issue
Block a user