aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/templates/booking/booking_calendar.html15
-rw-r--r--src/templates/booking/booking_detail.html6
5 files changed, 67 insertions, 4 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)})
diff --git a/src/templates/booking/booking_calendar.html b/src/templates/booking/booking_calendar.html
index 81efbe5..b60db3c 100644
--- a/src/templates/booking/booking_calendar.html
+++ b/src/templates/booking/booking_calendar.html
@@ -64,13 +64,26 @@
{% bootstrap_form_errors form type='non_fields' %}
<form method="post" action="" class="form" id="bookingeditform">
{% csrf_token %}
-
+ <div id='hide_if_noext'>
<div class='input-group' id='starttimeeditpicker'>
{% bootstrap_field form.start addon_after='<span class="glyphicon glyphicon-calendar"></span>' %}
</div>
<div class='input-group' id='endtimeeditpicker'>
{% bootstrap_field form.end addon_after='<span class="glyphicon glyphicon-calendar"></span>' %}
</div>
+ </div>
+ <script type="text/javascript">
+ if( {{ booking.ext_count }} <= 0 ){
+ var hidediv = document.getElementById('hide_if_noext');
+ hidediv.style.display = 'none';
+ var par = document.createElement("div");
+ var text = document.createTextNode("No Extensions Remaining");
+ par.appendChild(text);
+ par.style.fontWeight = 'bold';
+ par.style.paddingBottom = '15pt';
+ hidediv.parentNode.insertBefore(par,hidediv.nextSibling);
+ }
+ </script>
{% bootstrap_field form.purpose %}
{% bootstrap_field form.installer %}
{% bootstrap_field form.scenario %}
diff --git a/src/templates/booking/booking_detail.html b/src/templates/booking/booking_detail.html
index c88cd84..4628a62 100644
--- a/src/templates/booking/booking_detail.html
+++ b/src/templates/booking/booking_detail.html
@@ -44,6 +44,10 @@
<p>
<b>Scenario: </b> {{ booking.scenario }}
</p>
+<p>
+ <b>Extensions Remaining: </b> {{ booking.ext_count }}
+</p>
+
{% if user.is_authenticated %}
{% if user.get_username == booking.user.username %}
<p>
@@ -67,4 +71,4 @@
</div>
</p>
{% endif %}
-{% endif %} \ No newline at end of file
+{% endif %}