diff options
-rw-r--r-- | src/api/migrations/0002_remove_job_delta.py | 17 | ||||
-rw-r--r-- | src/booking/views.py | 127 | ||||
-rw-r--r-- | src/resource_inventory/admin.py | 2 | ||||
-rw-r--r-- | src/resource_inventory/migrations/0004_auto_20181017_1532.py | 28 | ||||
-rw-r--r-- | src/workflow/booking_workflow.py | 1 |
5 files changed, 46 insertions, 129 deletions
diff --git a/src/api/migrations/0002_remove_job_delta.py b/src/api/migrations/0002_remove_job_delta.py new file mode 100644 index 0000000..157a40f --- /dev/null +++ b/src/api/migrations/0002_remove_job_delta.py @@ -0,0 +1,17 @@ +# Generated by Django 2.1 on 2018-10-17 15:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='job', + name='delta', + ), + ] diff --git a/src/booking/views.py b/src/booking/views.py index c139b4c..9b9860f 100644 --- a/src/booking/views.py +++ b/src/booking/views.py @@ -19,7 +19,6 @@ from django.views.generic import TemplateView from django.shortcuts import redirect, render import json -from booking.forms import BookingForm, BookingEditForm from resource_inventory.models import ResourceBundle from resource_inventory.resource_manager import ResourceManager from booking.models import Booking, Installer, Opsys @@ -42,132 +41,6 @@ def drop_filter(context): context.update({'installer_filter': json.dumps(installer_filter), 'scenario_filter': json.dumps(scenario_filter)}) -class BookingFormView(FormView): - template_name = "booking/booking_calendar.html" - form_class = BookingForm - - def dispatch(self, request, *args, **kwargs): - self.resource = get_object_or_404(ResourceBundle, id=self.kwargs['resource_id']) - return super(BookingFormView, self).dispatch(request, *args, **kwargs) - - def get_context_data(self, **kwargs): - title = 'Booking: ' + str(self.resource.id) - context = super(BookingFormView, self).get_context_data(**kwargs) - context.update({'title': title, 'resource': self.resource}) - - drop_filter(context) - - return context - - def get_success_url(self): - return reverse('booking:create', kwargs=self.kwargs) - - def form_valid(self, form): - if not self.request.user.is_authenticated: - messages.add_message(self.request, messages.ERROR, - 'You need to be logged in to book a Pod.') - return super(BookingFormView, self).form_invalid(form) - - if form.cleaned_data['end'] - form.cleaned_data['start'] > timezone.timedelta(days=21): - messages.add_message(self.request, messages.ERROR, - 'Bookings can be no more than 3 weeks long.') - return super(BookingFormView, self).form_invalid(form) - - user = self.request.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, - owner=user - ) - try: - booking.save() - except ValueError as err: - messages.add_message(self.request, messages.ERROR, err) - return super(BookingFormView, self).form_invalid(form) - messages.add_message(self.request, messages.SUCCESS, 'Booking saved') - return super(BookingFormView, self).form_valid(form) - - -class BookingEditFormView(FormView): - template_name = "booking/booking_calendar.html" - form_class = BookingEditForm - - def is_valid(self): - return True - - def dispatch(self, request, *args, **kwargs): - self.resource = get_object_or_404(ResourceBundle, id=self.kwargs['resource_id']) - self.original_booking = get_object_or_404(Booking, id=self.kwargs['booking_id']) - return super(BookingEditFormView, self).dispatch(request, *args, **kwargs) - - def get_context_data(self, **kwargs): - title = 'Editing Booking on: ' + self.resource.name - context = super(BookingEditFormView, self).get_context_data(**kwargs) - context.update({'title': title, 'resource': self.resource, 'booking': self.original_booking}) - - drop_filter(context) - - return context - - def get_form_kwargs(self): - kwargs = super(BookingEditFormView, self).get_form_kwargs() - kwargs['purpose'] = self.original_booking.purpose - kwargs['start'] = self.original_booking.start - kwargs['end'] = self.original_booking.end - return kwargs - - def get_success_url(self): - return reverse('booking:create', args=(self.resource.id,)) - - def form_valid(self, form): - - if not self.request.user.is_authenticated: - messages.add_message(self.request, messages.ERROR, - 'You need to be logged in to book a Pod.') - return super(BookingEditFormView, self).form_invalid(form) - - if not self.request.user == self.original_booking.user: - messages.add_message(self.request, messages.ERROR, - 'You are not the owner of this booking.') - return super(BookingEditFormView, self).form_invalid(form) - - # Do Conflict Checks - if self.original_booking.end != form.cleaned_data['end']: - if form.cleaned_data['end'] - self.original_booking.end > timezone.timedelta(days=7): - messages.add_message(self.request, messages.ERROR, - 'Extensions can not be longer than one week.') - return super(BookingEditFormView, self).form_invalid(form) - elif self.original_booking.ext_count <= 0: - messages.add_message(self.request, messages.ERROR, - 'Cannot change end date after maximum number of extensions reached.') - return super(BookingEditFormView, self).form_invalid(form) - - else: - self.original_booking.ext_count -= 1 - - if self.original_booking.start != form.cleaned_data['start']: - if timezone.now() > form.cleaned_data['start']: - messages.add_message(self.request, messages.ERROR, - 'Cannot change start date after it has occurred.') - return super(BookingEditFormView, self).form_invalid(form) - self.original_booking.start = form.cleaned_data['start'] - self.original_booking.end = form.cleaned_data['end'] - self.original_booking.purpose = form.cleaned_data['purpose'] - self.original_booking.installer = form.cleaned_data['installer'] - self.original_booking.scenario = form.cleaned_data['scenario'] - self.original_booking.reset = form.cleaned_data['reset'] - try: - self.original_booking.save() - except ValueError as err: - messages.add_message(self.request, messages.ERROR, err) - return super(BookingEditFormView, self).form_invalid(form) - - return super(BookingEditFormView, self).form_valid(form) - - class BookingView(TemplateView): template_name = "booking/booking_detail.html" diff --git a/src/resource_inventory/admin.py b/src/resource_inventory/admin.py index 222877a..37b0c45 100644 --- a/src/resource_inventory/admin.py +++ b/src/resource_inventory/admin.py @@ -16,7 +16,7 @@ profiles = [HostProfile, InterfaceProfile, DiskProfile, CpuProfile, RamProfile] admin.site.register(profiles) -generics = [GenericResourceBundle, GenericResource, GenericHost, GenericPod, GenericInterface] +generics = [GenericResourceBundle, GenericResource, GenericHost, GenericInterface] admin.site.register(generics) diff --git a/src/resource_inventory/migrations/0004_auto_20181017_1532.py b/src/resource_inventory/migrations/0004_auto_20181017_1532.py new file mode 100644 index 0000000..3a7475c --- /dev/null +++ b/src/resource_inventory/migrations/0004_auto_20181017_1532.py @@ -0,0 +1,28 @@ +# Generated by Django 2.1 on 2018-10-17 15:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('resource_inventory', '0003_vlan_public'), + ] + + operations = [ + migrations.RemoveField( + model_name='genericpod', + name='genericresource_ptr', + ), + migrations.RemoveField( + model_name='genericpod', + name='hosts', + ), + migrations.RemoveField( + model_name='genericpod', + name='networks', + ), + migrations.DeleteModel( + name='GenericPod', + ), + ] diff --git a/src/workflow/booking_workflow.py b/src/workflow/booking_workflow.py index 52fe36b..213b9e6 100644 --- a/src/workflow/booking_workflow.py +++ b/src/workflow/booking_workflow.py @@ -74,7 +74,6 @@ class Resource_Select(WorkflowStep): context = self.get_context() if form.is_valid(): data = form.cleaned_data['generic_resource_bundle'] - irint(str(data['user'])) data = data[2:-2] if not data: self.metastep.set_invalid("Please select a valid bundle") |