aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/views.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2018-02-26 17:52:25 -0500
committerSawyer Bergeron <sbergeron@iol.unh.edu>2018-03-26 18:42:42 +0000
commit752f31b9722d15a7857e5ea56966e5f17141d82e (patch)
tree1ec921a2d7249b66864399f2487f65d22ffc7423 /src/booking/views.py
parentb0ef65a9126dc661a9eff59840f1d64f875003f4 (diff)
Limit User Booking Length and Extensions
Jira: PHAROS-363 Bookings can now only be 3 weeks upon creation with a maximum of 2 1 week extensions. Change-Id: I677770de3f62f188d23e60be6d71b42b25bf007e Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/booking/views.py')
-rw-r--r--src/booking/views.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/booking/views.py b/src/booking/views.py
index 7e35af2..a52cfe2 100644
--- a/src/booking/views.py
+++ b/src/booking/views.py
@@ -66,6 +66,11 @@ class BookingFormView(FormView):
'You need to be logged in to book a Pod.')
return super(BookingFormView, self).form_invalid(form)
+ if form.cleaned_data['end'] - form.cleaned_data['start'] > timezone.timedelta(days=21):
+ messages.add_message(self.request, messages.ERROR,
+ 'Bookings can be no more than 3 weeks long.')
+ return super(BookingFormView, self).form_invalid(form)
+
user = self.request.user
booking = Booking(start=form.cleaned_data['start'],
end=form.cleaned_data['end'],
@@ -107,7 +112,7 @@ class BookingEditFormView(FormView):
def get_context_data(self, **kwargs):
title = 'Editing Booking on: ' + self.resource.name
context = super(BookingEditFormView, self).get_context_data(**kwargs)
- context.update({'title': title, 'resource': self.resource})
+ context.update({'title': title, 'resource': self.resource, 'booking': self.original_booking})
return context
def get_form_kwargs(self):
@@ -141,6 +146,19 @@ class BookingEditFormView(FormView):
return super(BookingEditFormView, self).form_invalid(form)
#Do Conflict Checks
+ if self.original_booking.end != form.cleaned_data['end']:
+ if form.cleaned_data['end'] - self.original_booking.end > timezone.timedelta(days=7):
+ messages.add_message(self.request, messages.ERROR,
+ 'Extensions can not be longer than one week.')
+ return super(BookingEditFormView, self).form_invalid(form)
+ elif self.original_booking.ext_count <= 0:
+ messages.add_message(self.request, messages.ERROR,
+ 'Cannot change end date after maximum number of extensions reached.')
+ return super(BookingEditFormView, self).form_invalid(form)
+
+ else:
+ self.original_booking.ext_count -= 1
+
if self.original_booking.start != form.cleaned_data['start']:
if timezone.now() > form.cleaned_data['start']:
messages.add_message(self.request, messages.ERROR,
@@ -205,4 +223,4 @@ class ResourceBookingsJSON(View):
bookings = resource.booking_set.get_queryset().values('id', 'start', 'end', 'purpose',
'jira_issue_status', 'opsys__name',
'installer__name', 'scenario__name')
- return JsonResponse({'bookings': list(bookings)}) \ No newline at end of file
+ return JsonResponse({'bookings': list(bookings)})