diff --git a/DepoT/urls.py b/DepoT/urls.py index 09540d6..6a78f4e 100644 --- a/DepoT/urls.py +++ b/DepoT/urls.py @@ -24,4 +24,5 @@ urlpatterns = [ path('user/', include('accounts.urls')), path('preinfo/', include('preinfo.urls')), path('container/', include('containers.urls')), + path('booking/', include('booking.urls')), ] diff --git a/booking/forms.py b/booking/forms.py new file mode 100644 index 0000000..4a3b74d --- /dev/null +++ b/booking/forms.py @@ -0,0 +1,19 @@ +from django import forms + +from booking.models import Booking + + +class BookingBaseForm(forms.ModelForm): + """ + Base form for booking-related forms. + This can be extended by other booking forms. + """ + + class Meta: + fields = '__all__' + model = Booking + +class BookingCreateForm(BookingBaseForm): + + class Meta(BookingBaseForm.Meta): + fields = ['number', 'vehicles', 'container_type', 'container_count', 'carrier', 'line', 'container_number'] diff --git a/booking/models.py b/booking/models.py index 1b168d1..a8e4262 100644 --- a/booking/models.py +++ b/booking/models.py @@ -2,7 +2,7 @@ from django.db import models from common.models import ContainerTypeModel, LinesModel, OperationModel # Create your models here. -class BookingModel(models.Model): +class Booking(models.Model): number = models.CharField(max_length=50, unique=True) vehicles = models.CharField(blank=True, null=True) container_type = models.ForeignKey( @@ -11,6 +11,7 @@ class BookingModel(models.Model): related_name='booking_container_types', ) container_count = models.IntegerField() + container_expedited_count = models.IntegerField(default=0) carrier = models.CharField(max_length=100, blank=True, null=True) line = models.ForeignKey( LinesModel, diff --git a/booking/urls.py b/booking/urls.py new file mode 100644 index 0000000..d411529 --- /dev/null +++ b/booking/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from booking.views import CreateBookingView + +urlpatterns = [ + path('client/', CreateBookingView.as_view(), name='client_booking'), +] \ No newline at end of file diff --git a/booking/views.py b/booking/views.py index 2e779ca..396ad54 100644 --- a/booking/views.py +++ b/booking/views.py @@ -1,14 +1,35 @@ from django.shortcuts import render +from django.urls import reverse_lazy from django.views.generic import CreateView +from booking.forms import BookingCreateForm +from booking.models import Booking +from common.utils import filter_queryset_by_user + # Create your views here. class CreateBookingView(CreateView): - template_name = 'create-booking.html' - extra_context = { - 'title': 'Create Booking', - 'description': 'This is the create booking page.', - } - - def get(self, request, *args, **kwargs): - return render(request, self.template_name, self.extra_context) \ No newline at end of file + template_name = 'client-booking-content.html' + model = Booking + form_class = BookingCreateForm + success_url = reverse_lazy('dashboard') + + 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 + return context + + + def form_valid(self, form): + # todo more validation + form.instance.created_by = self.request.user.id + form.instance.updated_by = self.request.user.id + if self.request.user.line: + form.instance.line = self.request.user.line + return super().form_valid(form) \ No newline at end of file diff --git a/containers/models.py b/containers/models.py index ae4b11a..976630d 100644 --- a/containers/models.py +++ b/containers/models.py @@ -43,7 +43,7 @@ class Container(models.Model): null=True ) booking = models.ForeignKey( - 'booking.BookingModel', + 'booking.Booking', on_delete=models.CASCADE, related_name='container_bookings', blank = True, diff --git a/templates/client-base.html b/templates/client-base.html index 8790747..7b379df 100644 --- a/templates/client-base.html +++ b/templates/client-base.html @@ -60,7 +60,7 @@
- {% include 'sidebar.html' %} + {% include 'client-sidebar.html' %}