summaryrefslogtreecommitdiffstats
path: root/src/booking
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
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')
-rw-r--r--src/booking/migrations/0004_booking_ext_count.py27
-rw-r--r--src/booking/models.py1
-rw-r--r--src/booking/views.py22
3 files changed, 48 insertions, 2 deletions
diff --git a/src/booking/migrations/0004_booking_ext_count.py b/src/booking/migrations/0004_booking_ext_count.py
new file mode 100644
index 0000000..6bcc3ce
--- /dev/null
+++ b/src/booking/migrations/0004_booking_ext_count.py
@@ -0,0 +1,27 @@
+##############################################################################
+# Copyright (c) 2018 Sawyer Bergeron and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('booking', '0003_auto_20180108_2024'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='booking',
+ name='ext_count',
+ field=models.IntegerField(default=2),
+ ),
+ ]
diff --git a/src/booking/models.py b/src/booking/models.py
index 9156484..8762d46 100644
--- a/src/booking/models.py
+++ b/src/booking/models.py
@@ -55,6 +55,7 @@ class Booking(models.Model):
installer = models.ForeignKey(Installer, models.DO_NOTHING, null=True)
scenario = models.ForeignKey(Scenario, models.DO_NOTHING, null=True)
purpose = models.CharField(max_length=300, blank=False)
+ ext_count = models.IntegerField(default=2)
class Meta:
db_table = 'booking'
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)})