Add backend forms for ScheduleSlots and VolunteerSlots
authorMagnus Hagander <magnus@hagander.net>
Tue, 3 Apr 2018 14:15:08 +0000 (16:15 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 3 Apr 2018 14:15:08 +0000 (16:15 +0200)
postgresqleu/confreg/backendforms.py
postgresqleu/confreg/backendviews.py
postgresqleu/confreg/models.py
postgresqleu/urls.py
template/confreg/admin_dashboard_single.html

index d7983237d062c25b1f2f6c2ae3c08df17e2acd47..4f6f78413913696531b6bcd1a2981278588766aa 100644 (file)
@@ -18,6 +18,7 @@ from postgresqleu.confreg.lookups import RegistrationLookup
 from postgresqleu.confreg.models import Conference, ConferenceRegistration, ConferenceAdditionalOption
 from postgresqleu.confreg.models import RegistrationClass, RegistrationType, RegistrationDay
 from postgresqleu.confreg.models import ConferenceSession, Track, Room
+from postgresqleu.confreg.models import ConferenceSessionScheduleSlot, VolunteerSlot
 
 from postgresqleu.confreg.models import valid_status_transitions, get_status_string
 
@@ -206,3 +207,24 @@ class BackendConferenceSessionForm(BackendForm):
                        ))
 
                return newstatus
+
+class BackendConferenceSessionSlotForm(BackendForm):
+       list_fields = [ 'starttime', 'endtime', ]
+
+       class Meta:
+               model = ConferenceSessionScheduleSlot
+               fields = ['starttime', 'endtime' ]
+
+class BackendVolunteerSlotForm(BackendForm):
+       list_fields = [ 'timerange', 'title', 'min_staff', 'max_staff' ]
+
+       class Meta:
+               model = VolunteerSlot
+               fields = [ 'timerange', 'title', 'min_staff', 'max_staff' ]
+
+       def clean(self):
+               cleaned_data = super(BackendVolunteerSlotForm, self).clean()
+               if cleaned_data.get('min_staff') > cleaned_data.get('max_staff'):
+                       self.add_error('max_staff', 'Max staff must be at least as high as min_staff!')
+
+               return cleaned_data
index fb945c498ea164273ceccdbd700394c04ad3c7a9..3df3107f82c84b4705d9aa5c3fcbd4fa470f240e 100644 (file)
@@ -19,6 +19,7 @@ from backendforms import BackendConferenceForm, BackendRegistrationForm
 from backendforms import BackendRegistrationTypeForm, BackendRegistrationClassForm
 from backendforms import BackendRegistrationDayForm
 from backendforms import BackendTrackForm, BackendRoomForm, BackendConferenceSessionForm
+from backendforms import BackendConferenceSessionSlotForm, BackendVolunteerSlotForm
 
 def get_authenticated_conference(request, urlname):
        if not request.user.is_authenticated:
@@ -208,3 +209,19 @@ def edit_sessions(request, urlname, rest):
                                                           rest,
                                                           allow_new=True,
                                                           allow_delete=True)
+
+def edit_scheduleslots(request, urlname, rest):
+       return backend_list_editor(request,
+                                                          urlname,
+                                                          BackendConferenceSessionSlotForm,
+                                                          rest,
+                                                          allow_new=True,
+                                                          allow_delete=True)
+
+def edit_volunteerslots(request, urlname, rest):
+       return backend_list_editor(request,
+                                                          urlname,
+                                                          BackendVolunteerSlotForm,
+                                                          rest,
+                                                          allow_new=True,
+                                                          allow_delete=True)
index a0a90c66655f45c30f0db833dcda6aa4272fefba..cda6b3fcbf04b629df5ba891b3b8e430728f8c43 100644 (file)
@@ -760,6 +760,9 @@ class VolunteerSlot(models.Model):
                ordering = [ 'timerange', ]
 
        def __unicode__(self):
+               return self._display_timerange()
+
+       def _display_timerange(self):
                return "{0} - {1}".format(self.timerange.lower, self.timerange.upper)
 
        @property
index c08a0af0770c5d6d9e262e8660d8cef7d16ed055..005f71e5669b71a07d2048cbbedc198f5ce9b90d 100644 (file)
@@ -144,6 +144,8 @@ urlpatterns = [
        url(r'^events/admin/(\w+)/tracks/(.*/)?$', postgresqleu.confreg.backendviews.edit_tracks),
        url(r'^events/admin/(\w+)/rooms/(.*/)?$', postgresqleu.confreg.backendviews.edit_rooms),
        url(r'^events/admin/(\w+)/sessions/(.*/)?$', postgresqleu.confreg.backendviews.edit_sessions),
+       url(r'^events/admin/(\w+)/scheduleslots/(.*/)?$', postgresqleu.confreg.backendviews.edit_scheduleslots),
+       url(r'^events/admin/(\w+)/volunteerslots/(.*/)?$', postgresqleu.confreg.backendviews.edit_volunteerslots),
 
        url(r'^events/sponsor/', include('postgresqleu.confsponsor.urls')),
 
index 207cf676de4b2fbe0e5bc60b149c8bc4d158cf8d..93f2401a0516ac89cc84f30990258b7dbada46ca 100644 (file)
@@ -67,6 +67,8 @@
 <div class="row">
   <div class="col-md-3 col-sm-6 col-xs-12 buttonrow"><a class="btn btn-default btn-block" href="/events/admin/{{c.urlname}}/tracks/">Tracks</a></div>
   <div class="col-md-3 col-sm-6 col-xs-12 buttonrow"><a class="btn btn-default btn-block" href="/events/admin/{{c.urlname}}/rooms/">Rooms</a></div>
+  <div class="col-md-3 col-sm-6 col-xs-12 buttonrow"><a class="btn btn-default btn-block" href="/events/admin/{{c.urlname}}/scheduleslots/">Schedule slots</a></div>
+  <div class="col-md-3 col-sm-6 col-xs-12 buttonrow"><a class="btn btn-default btn-block" href="/events/admin/{{c.urlname}}/volunteerslots/">Volunteer slots</a></div>
 </div>
 <div class="row">
   <div class="col-md-3 col-sm-6 col-xs-12 buttonrow"><a class="btn btn-default btn-block" href="/events/admin/{{c.urlname}}/regdays/">Registration days</a></div>