summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/booking
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-08-25 12:05:19 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-08-25 12:05:19 +0200
commit4ef923cbe9d4d4f3348657389661ffa99e89f919 (patch)
treeadd3d8cb4adedb250326ba3e2e6f4926dd5073bc /tools/pharos-dashboard/booking
parentc1de4c940288ef0ec1a5132b30aff74efb0afbcd (diff)
Add a Booking detail view
JIRA: RELENG-12 This adds a pop-up to the booking calendar, containing information about a selected booking. Change-Id: Ie780006963cb927d073103edbaefbdab3de403fb Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/booking')
-rw-r--r--tools/pharos-dashboard/booking/models.py10
-rw-r--r--tools/pharos-dashboard/booking/urls.py2
-rw-r--r--tools/pharos-dashboard/booking/views.py18
3 files changed, 26 insertions, 4 deletions
diff --git a/tools/pharos-dashboard/booking/models.py b/tools/pharos-dashboard/booking/models.py
index 8011fa41..4be8ccab 100644
--- a/tools/pharos-dashboard/booking/models.py
+++ b/tools/pharos-dashboard/booking/models.py
@@ -1,7 +1,9 @@
from django.contrib.auth.models import User
from django.db import models
+from jira import JIRA
from dashboard.models import Resource
+from pharos_dashboard import settings
class Booking(models.Model):
@@ -17,6 +19,11 @@ class Booking(models.Model):
class Meta:
db_table = 'booking'
+ def get_jira_issue(self):
+ jira = JIRA(server=settings.JIRA_URL, basic_auth=(settings.JIRA_USER_NAME, settings.JIRA_USER_PASSWORD))
+ issue = jira.issue(self.jira_issue_id)
+ return issue
+
def authorization_test(self):
"""
Return True if self.user is authorized to make this booking.
@@ -41,13 +48,12 @@ class Booking(models.Model):
if self.start >= self.end:
raise ValueError('Start date is after end date')
# conflicts end after booking starts, and start before booking ends
- conflicting_dates = Booking.objects.filter(resource=self.resource)
+ conflicting_dates = Booking.objects.filter(resource=self.resource).exclude(id=self.id)
conflicting_dates = conflicting_dates.filter(end__gt=self.start)
conflicting_dates = conflicting_dates.filter(start__lt=self.end)
if conflicting_dates.count() > 0:
raise ValueError('This booking overlaps with another booking')
return super(Booking, self).save(*args, **kwargs)
-
def __str__(self):
return str(self.resource) + ' from ' + str(self.start) + ' until ' + str(self.end)
diff --git a/tools/pharos-dashboard/booking/urls.py b/tools/pharos-dashboard/booking/urls.py
index 37f0c6b0..f6429daa 100644
--- a/tools/pharos-dashboard/booking/urls.py
+++ b/tools/pharos-dashboard/booking/urls.py
@@ -21,4 +21,6 @@ urlpatterns = [
url(r'^(?P<resource_id>[0-9]+)/$', BookingFormView.as_view(), name='create'),
url(r'^(?P<resource_id>[0-9]+)/bookings_json/$', ResourceBookingsJSON.as_view(),
name='bookings_json'),
+ url(r'^detail/$', BookingView.as_view(), name='detail_prefix'),
+ url(r'^detail/(?P<booking_id>[0-9]+)/$', BookingView.as_view(), name='detail'),
]
diff --git a/tools/pharos-dashboard/booking/views.py b/tools/pharos-dashboard/booking/views.py
index c2f437f3..fde8d816 100644
--- a/tools/pharos-dashboard/booking/views.py
+++ b/tools/pharos-dashboard/booking/views.py
@@ -1,11 +1,12 @@
from django.contrib import messages
-from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
+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.views import View
from django.views.generic import FormView
-from django.shortcuts import redirect
+from django.views.generic import TemplateView
from jira import JIRAError
from account.jira_util import get_jira
@@ -28,6 +29,7 @@ def create_jira_ticket(user, booking):
jira.add_attachment(issue, user.userprofile.pgp_public_key)
jira.add_attachment(issue, user.userprofile.ssh_public_key)
booking.jira_issue_id = issue.id
+ booking.save()
class BookingFormView(LoginRequiredMixin, FormView):
@@ -76,6 +78,18 @@ class BookingFormView(LoginRequiredMixin, FormView):
return super(BookingFormView, self).form_valid(form)
+class BookingView(TemplateView):
+ template_name = "booking/booking_detail.html"
+
+ 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})
+ return context
+
+
class ResourceBookingsJSON(View):
def get(self, request, *args, **kwargs):
resource = get_object_or_404(Resource, id=self.kwargs['resource_id'])