summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/booking
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pharos-dashboard/booking')
-rw-r--r--tools/pharos-dashboard/booking/tests/test_views.py7
-rw-r--r--tools/pharos-dashboard/booking/views.py15
2 files changed, 15 insertions, 7 deletions
diff --git a/tools/pharos-dashboard/booking/tests/test_views.py b/tools/pharos-dashboard/booking/tests/test_views.py
index 4f5ee8bd..b0c4b498 100644
--- a/tools/pharos-dashboard/booking/tests/test_views.py
+++ b/tools/pharos-dashboard/booking/tests/test_views.py
@@ -56,13 +56,8 @@ class BookingViewTestCase(TestCase):
url = reverse('booking:create', kwargs={'resource_id': 0})
self.assertEqual(self.client.get(url).status_code, 404)
- # anonymous user
- url = reverse('booking:create', kwargs={'resource_id': self.res1.id})
- response = self.client.get(url, follow=True)
- self.assertRedirects(response, reverse('account:login') + '?next=/booking/' + str(
- self.res1.id) + '/')
-
# authenticated user
+ url = reverse('booking:create', kwargs={'resource_id': self.res1.id})
self.client.login(username='user1',password='user1')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
diff --git a/tools/pharos-dashboard/booking/views.py b/tools/pharos-dashboard/booking/views.py
index bc00d3eb..c461aef4 100644
--- a/tools/pharos-dashboard/booking/views.py
+++ b/tools/pharos-dashboard/booking/views.py
@@ -6,17 +6,29 @@ from django.urls import reverse
from django.views import View
from django.views.generic import FormView
+from account.jira_util import get_jira
from booking.forms import BookingForm
from booking.models import Booking
from dashboard.models import Resource
+
class BookingFormView(LoginRequiredMixin, FormView):
template_name = "booking/booking_calendar.html"
form_class = BookingForm
+ def open_jira_issue(self,booking):
+ jira = get_jira(self.request.user)
+ issue_dict = {
+ 'project': 'PHAROS',
+ 'summary': 'Booking: ' + str(self.resource),
+ 'description': str(booking),
+ 'issuetype': {'name': 'Task'},
+ }
+ jira.create_issue(fields=issue_dict)
+
def dispatch(self, request, *args, **kwargs):
self.resource = get_object_or_404(Resource, id=self.kwargs['resource_id'])
- return super(BookingFormView, self).dispatch(request,*args, **kwargs)
+ return super(BookingFormView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
title = 'Booking: ' + self.resource.name
@@ -39,6 +51,7 @@ class BookingFormView(LoginRequiredMixin, FormView):
except PermissionError as err:
messages.add_message(self.request, messages.ERROR, err)
return super(BookingFormView, self).form_invalid(form)
+ self.open_jira_issue(booking)
messages.add_message(self.request, messages.SUCCESS, 'Booking saved')
return super(BookingFormView, self).form_valid(form)