diff options
Diffstat (limited to 'tools/pharos-dashboard/booking/views.py')
-rw-r--r-- | tools/pharos-dashboard/booking/views.py | 15 |
1 files changed, 14 insertions, 1 deletions
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) |