summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/dashboard/views
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pharos-dashboard/dashboard/views')
-rw-r--r--tools/pharos-dashboard/dashboard/views/booking.py69
-rw-r--r--tools/pharos-dashboard/dashboard/views/registration.py16
-rw-r--r--tools/pharos-dashboard/dashboard/views/table_views.py62
3 files changed, 0 insertions, 147 deletions
diff --git a/tools/pharos-dashboard/dashboard/views/booking.py b/tools/pharos-dashboard/dashboard/views/booking.py
deleted file mode 100644
index 1499edb7..00000000
--- a/tools/pharos-dashboard/dashboard/views/booking.py
+++ /dev/null
@@ -1,69 +0,0 @@
-from dashboard.forms.booking_form import BookingForm
-from dashboard.models import Resource, Booking
-from dashboard.views.registration import BookingUserTestMixin
-from django.contrib import messages
-from django.contrib.auth.decorators import login_required
-from django.http import Http404, JsonResponse
-from django.shortcuts import get_object_or_404
-from django.utils.decorators import method_decorator
-from django.views.generic import FormView, View
-
-
-@method_decorator(login_required, name='dispatch')
-class BookingCalendarView(BookingUserTestMixin, FormView):
- template_name = "dashboard/booking_calendar.html"
- form_class = BookingForm
-
- # set instance variables
- def dispatch(self, request, *args, **kwargs):
- self.foo = request.GET.get('foo', False)
- self.resource = get_object_or_404(Resource, resource_id=self.kwargs['resource_id'])
- return super(BookingCalendarView, self).dispatch(request, *args, **kwargs)
-
- def form_valid(self, form):
- self.success_url = self.request.path
- booking = None
- # change existing booking
- if form.cleaned_data['booking_id'] is not None:
- booking = get_object_or_404(Booking, booking_id=form.cleaned_data['booking_id'])
- # create new booking
- else:
- booking = Booking()
- booking.resource = self.resource
- booking.user = self.request.user
- booking.start_date_time = form.cleaned_data['start_date_time']
- booking.end_date_time = form.cleaned_data['end_date_time']
- booking.purpose = form.cleaned_data['purpose']
- try:
- booking.save()
- except ValueError:
- messages.add_message(self.request, messages.ERROR,
- 'This booking overlaps with another booking')
- return super(BookingCalendarView, self).form_invalid(form)
- messages.add_message(self.request, messages.SUCCESS,
- 'Booking saved')
- return super(BookingCalendarView, self).form_valid(form)
-
- def get_context_data(self, **kwargs):
- title = 'Booking: ' + self.resource.name
- context = super(BookingCalendarView, self).get_context_data(**kwargs)
- context.update({'title': title, 'resource': self.resource})
- return context
-
-
-@method_decorator(login_required, name='dispatch')
-class ResourceBookingsView(BookingUserTestMixin, View):
- def get(self, request, *args, **kwargs):
- resource = Resource.objects.get(resource_id=self.kwargs['resource_id'])
- bookings = resource.booking_set.get_queryset().values(
- 'booking_id', 'user__username', 'user__email',
- 'start_date_time', 'end_date_time', 'purpose')
- return JsonResponse({'bookings': list(bookings)})
-
-
-@method_decorator(login_required, name='dispatch')
-class DeleteBookingView(BookingUserTestMixin, View):
- def post(self, request, *args, **kwargs):
- booking = get_object_or_404(Booking, booking_id=self.kwargs['booking_id'])
- booking.delete()
- return JsonResponse({True: self.kwargs['booking_id']})
diff --git a/tools/pharos-dashboard/dashboard/views/registration.py b/tools/pharos-dashboard/dashboard/views/registration.py
deleted file mode 100644
index 516fb298..00000000
--- a/tools/pharos-dashboard/dashboard/views/registration.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from django.contrib.auth.mixins import UserPassesTestMixin
-
-
-class BookingUserTestMixin(UserPassesTestMixin):
- # Test if a user has permission to book this Pod
- def test_func(self):
- user = self.request.user
- # Check if User is troubleshooter / admin
- if user.has_perm(('dashboard.add_booking')):
- return True
- # Check if User owns this resource
- user_resources = user.userresource_set.get_queryset()
- for user_resource in user_resources:
- if user_resource.resource_id == self.resource.resource_id:
- return True
- return False
diff --git a/tools/pharos-dashboard/dashboard/views/table_views.py b/tools/pharos-dashboard/dashboard/views/table_views.py
deleted file mode 100644
index 4404234e..00000000
--- a/tools/pharos-dashboard/dashboard/views/table_views.py
+++ /dev/null
@@ -1,62 +0,0 @@
-import dashboard.jenkins.jenkins_util as jenkins_util
-
-import dashboard.jenkins.jenkins_adapter as jenkins
-from dashboard.models import Resource, Booking
-from django.utils import timezone
-from django.views.generic import TemplateView
-
-
-class JenkinsSlavesView(TemplateView):
- template_name = "tables/jenkins_slaves.html"
-
- def get_context_data(self, **kwargs):
- slaves = jenkins.get_all_slaves()
- for slave in slaves:
- jenkins_util.parse_slave_data(slave, slave)
-
- context = super(JenkinsSlavesView, self).get_context_data(**kwargs)
- context.update({'title': "Jenkins Slaves", 'slaves': slaves})
- return context
-
-
-class CIPodsView(TemplateView):
- template_name = "tables/ci_pods.html"
-
- def get_context_data(self, **kwargs):
- resources = Resource.objects.filter().values() # get resources as a set of dicts
- ci_pods = []
- for resource in resources:
- if not jenkins.is_ci_slave(resource['slavename']):
- continue
- ci_slave = jenkins.get_slave(resource['slavename'])
- jenkins_util.parse_slave_data(resource, ci_slave)
- ci_pods.append(resource)
-
- context = super(CIPodsView, self).get_context_data(**kwargs)
- context.update({'title': "CI Pods", 'ci_pods': ci_pods})
- return context
-
-
-class DevelopmentPodsView(TemplateView):
- template_name = "tables/dev_pods.html"
-
- def get_context_data(self, **kwargs):
- resources = Resource.objects.filter().values() # get resources as a set of dicts
- dev_pods = []
-
- current_bookings = Booking.objects.filter(start_date_time__lte=timezone.now())
- current_bookings = current_bookings.filter(end_date_time__gt=timezone.now())
-
- for resource in resources:
- if not jenkins.is_dev_pod(resource['slavename']):
- continue
- dev_pod = jenkins.get_slave(resource['slavename'])
- jenkins_util.parse_slave_data(resource, dev_pod)
- for booking in current_bookings:
- if booking.resource.slavename == resource['slavename']:
- resource['current_booking'] = booking
- dev_pods.append(resource)
-
- context = super(DevelopmentPodsView, self).get_context_data(**kwargs)
- context.update({'title': "Development Pods", 'dev_pods': dev_pods})
- return context