summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/src/booking
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-10-05 14:10:56 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-10-05 14:20:13 +0200
commit7c3d7e75f50c3e39eb1c752391c6336431543288 (patch)
treeda5a8f0fe69bc33e5a0de646d407e7dd013a227f /tools/pharos-dashboard/src/booking
parent94f19e02d37b1d7af807854cae910c83d34ce0cd (diff)
Add Installer and Scenario fields to bookings
JIRA: PHAROS-272 Change-Id: I28f44bfadb1dbe3cb0caca0a8038fba988cf26f9 Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/src/booking')
-rw-r--r--tools/pharos-dashboard/src/booking/admin.py6
-rw-r--r--tools/pharos-dashboard/src/booking/forms.py8
-rw-r--r--tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py40
-rw-r--r--tools/pharos-dashboard/src/booking/models.py31
-rw-r--r--tools/pharos-dashboard/src/booking/urls.py2
-rw-r--r--tools/pharos-dashboard/src/booking/views.py32
6 files changed, 88 insertions, 31 deletions
diff --git a/tools/pharos-dashboard/src/booking/admin.py b/tools/pharos-dashboard/src/booking/admin.py
index 7a7f251a..d883be1c 100644
--- a/tools/pharos-dashboard/src/booking/admin.py
+++ b/tools/pharos-dashboard/src/booking/admin.py
@@ -10,6 +10,8 @@
from django.contrib import admin
-from booking.models import Booking
+from booking.models import *
-admin.site.register(Booking) \ No newline at end of file
+admin.site.register(Booking)
+admin.site.register(Installer)
+admin.site.register(Scenario) \ No newline at end of file
diff --git a/tools/pharos-dashboard/src/booking/forms.py b/tools/pharos-dashboard/src/booking/forms.py
index 02ac887a..2dbfacb0 100644
--- a/tools/pharos-dashboard/src/booking/forms.py
+++ b/tools/pharos-dashboard/src/booking/forms.py
@@ -10,10 +10,14 @@
import django.forms as forms
+from booking.models import Installer, Scenario
+
class BookingForm(forms.Form):
- fields = ['start', 'end', 'purpose']
+ fields = ['start', 'end', 'purpose', 'installer', 'scenario']
start = forms.DateTimeField()
end = forms.DateTimeField()
- purpose = forms.CharField(max_length=300) \ No newline at end of file
+ purpose = forms.CharField(max_length=300)
+ installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False)
+ scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False) \ No newline at end of file
diff --git a/tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py b/tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py
new file mode 100644
index 00000000..05684f0b
--- /dev/null
+++ b/tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10 on 2016-10-05 12:02
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('booking', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Installer',
+ fields=[
+ ('id', models.AutoField(primary_key=True, serialize=False)),
+ ('name', models.CharField(max_length=30)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='Scenario',
+ fields=[
+ ('id', models.AutoField(primary_key=True, serialize=False)),
+ ('name', models.CharField(max_length=300)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='booking',
+ name='installer',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.Installer'),
+ ),
+ migrations.AddField(
+ model_name='booking',
+ name='scenario',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.Scenario'),
+ ),
+ ]
diff --git a/tools/pharos-dashboard/src/booking/models.py b/tools/pharos-dashboard/src/booking/models.py
index 200dc830..88ab5589 100644
--- a/tools/pharos-dashboard/src/booking/models.py
+++ b/tools/pharos-dashboard/src/booking/models.py
@@ -16,6 +16,20 @@ from jira import JIRAError
from dashboard.models import Resource
from django.conf import settings
+class Installer(models.Model):
+ id = models.AutoField(primary_key=True)
+ name = models.CharField(max_length=30)
+
+ def __str__(self):
+ return self.name
+
+class Scenario(models.Model):
+ id = models.AutoField(primary_key=True)
+ name = models.CharField(max_length=300)
+
+ def __str__(self):
+ return self.name
+
class Booking(models.Model):
id = models.AutoField(primary_key=True)
@@ -26,6 +40,8 @@ class Booking(models.Model):
jira_issue_id = models.IntegerField(null=True)
jira_issue_status = models.CharField(max_length=50)
+ 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)
class Meta:
@@ -40,27 +56,12 @@ class Booking(models.Model):
except JIRAError:
return None
- def authorization_test(self):
- """
- Return True if self.user is authorized to make this booking.
- """
- user = self.user
- # Check if User is troubleshooter / admin
- if user.has_perm('booking.add_booking'):
- return True
- # Check if User owns this resource
- if user == self.resource.owner:
- return True
- return False
-
def save(self, *args, **kwargs):
"""
Save the booking if self.user is authorized and there is no overlapping booking.
Raise PermissionError if the user is not authorized
Raise ValueError if there is an overlapping booking
"""
- if not self.authorization_test():
- raise PermissionError('Insufficient permissions to save this booking.')
if self.start >= self.end:
raise ValueError('Start date is after end date')
# conflicts end after booking starts, and start before booking ends
diff --git a/tools/pharos-dashboard/src/booking/urls.py b/tools/pharos-dashboard/src/booking/urls.py
index 53206233..9e013164 100644
--- a/tools/pharos-dashboard/src/booking/urls.py
+++ b/tools/pharos-dashboard/src/booking/urls.py
@@ -34,4 +34,6 @@ urlpatterns = [
url(r'^detail/$', BookingView.as_view(), name='detail_prefix'),
url(r'^detail/(?P<booking_id>[0-9]+)/$', BookingView.as_view(), name='detail'),
+
+ url(r'^list/$', BookingListView.as_view(), name='list')
]
diff --git a/tools/pharos-dashboard/src/booking/views.py b/tools/pharos-dashboard/src/booking/views.py
index 2fe167af..413573da 100644
--- a/tools/pharos-dashboard/src/booking/views.py
+++ b/tools/pharos-dashboard/src/booking/views.py
@@ -15,7 +15,6 @@ from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
-from django.shortcuts import redirect
from django.urls import reverse
from django.utils import timezone
from django.views import View
@@ -65,13 +64,12 @@ class BookingFormView(LoginRequiredMixin, FormView):
def form_valid(self, form):
user = self.request.user
- if not user.userprofile.ssh_public_key or not user.userprofile.pgp_public_key:
- messages.add_message(self.request, messages.INFO,
- 'Please upload your private keys before booking')
- return redirect('account:settings')
- booking = Booking(start=form.cleaned_data['start'], end=form.cleaned_data['end'],
- purpose=form.cleaned_data['purpose'], resource=self.resource,
- user=user)
+ booking = Booking(start=form.cleaned_data['start'],
+ end=form.cleaned_data['end'],
+ purpose=form.cleaned_data['purpose'],
+ installer=form.cleaned_data['installer'],
+ scenario=form.cleaned_data['scenario'],
+ resource=self.resource, user=user)
try:
booking.save()
except ValueError as err:
@@ -98,10 +96,19 @@ class BookingView(TemplateView):
def get_context_data(self, **kwargs):
booking = get_object_or_404(Booking, id=self.kwargs['booking_id'])
- jira_issue = booking.get_jira_issue()
title = 'Booking Details'
context = super(BookingView, self).get_context_data(**kwargs)
- context.update({'title': title, 'booking': booking, 'jira_issue': jira_issue})
+ context.update({'title': title, 'booking': booking})
+ return context
+
+class BookingListView(TemplateView):
+ template_name = "booking/booking_list.html"
+
+ def get_context_data(self, **kwargs):
+ bookings = Booking.objects.filter(end__gte=timezone.now())
+ title = 'Search Booking'
+ context = super(BookingListView, self).get_context_data(**kwargs)
+ context.update({'title': title, 'bookings': bookings})
return context
@@ -109,5 +116,6 @@ class ResourceBookingsJSON(View):
def get(self, request, *args, **kwargs):
resource = get_object_or_404(Resource, id=self.kwargs['resource_id'])
bookings = resource.booking_set.get_queryset().values('id', 'start', 'end', 'purpose',
- 'jira_issue_status')
- return JsonResponse({'bookings': list(bookings)}) \ No newline at end of file
+ 'jira_issue_status',
+ 'installer__name', 'scenario__name')
+ return JsonResponse({'bookings': list(bookings)})