def update_event(scheduling_form, occurrence_id, people_formset=[]): room = get_object_or_404( Room, name=scheduling_form.cleaned_data['location']) start_time = get_start_time(scheduling_form.cleaned_data) people = [] for assignment in people_formset: if assignment.is_valid() and assignment.cleaned_data['worker']: people += [Person( user=assignment.cleaned_data[ 'worker'].workeritem.as_subtype.user_object, public_id=assignment.cleaned_data['worker'].workeritem.pk, role=assignment.cleaned_data['role'])] response = update_occurrence( occurrence_id, start_time, scheduling_form.cleaned_data['max_volunteer'], people=people, locations=[room]) return response
def update_event(scheduling_form, occurrence_id, people_formset=[]): room = get_object_or_404(Room, name=scheduling_form.cleaned_data['location']) start_time = get_start_time(scheduling_form.cleaned_data) people = [] for assignment in people_formset: if assignment.is_valid() and assignment.cleaned_data['worker']: people += [ Person( user=assignment.cleaned_data['worker'].workeritem. as_subtype.user_object, public_id=assignment.cleaned_data['worker'].workeritem.pk, role=assignment.cleaned_data['role']) ] response = update_occurrence(occurrence_id, start_time, scheduling_form.cleaned_data['max_volunteer'], people=people, locations=[room]) return response
def update_event(scheduling_form, occurrence_id, roles=None, people_formset=[]): start_time = get_start_time(scheduling_form.cleaned_data) people = [] for assignment in people_formset: if assignment.is_valid() and assignment.cleaned_data['worker']: people += [Person( user=assignment.cleaned_data[ 'worker'].workeritem.as_subtype.user_object, public_id=assignment.cleaned_data['worker'].workeritem.pk, role=assignment.cleaned_data['role'])] if len(people) == 0: people = None response = update_occurrence( occurrence_id, start_time, scheduling_form.cleaned_data['max_volunteer'], people=people, roles=roles, locations=[scheduling_form.cleaned_data['location']], approval=scheduling_form.cleaned_data['approval']) return response
def do_additional_actions(self, request): response = None context = None if ('create_slot' in request.POST.keys()) or ( 'duplicate_slot' in request.POST.keys()): self.create = True if 'create_slot' in request.POST.keys(): self.event_form = RehearsalSlotForm( request.POST, prefix='new_slot', conference=self.conference) else: self.event_form = RehearsalSlotForm( request.POST, conference=self.conference) if self.event_form.is_valid(): data = self.get_basic_form_settings() self.event.e_conference = self.conference self.event.save() response = create_occurrence( self.event.eventitem_id, self.start_time, self.max_volunteer, locations=[self.room], labels=data['labels'], parent_event_id=self.parent_id) else: context = {'createslotform': self.event_form, 'rehearsal_open': True} elif 'edit_slot' in request.POST.keys(): self.event = get_object_or_404( GenericEvent, event_id=request.POST['opp_event_id']) casting_response = get_acts(int(request.POST['opp_sched_id'])) self.event_form = RehearsalSlotForm( request.POST, instance=self.event, initial={'current_acts': len(casting_response.castings)}) if self.event_form.is_valid(): data = self.get_basic_form_settings() self.event_form.save() response = update_occurrence( data['opp_sched_id'], self.start_time, self.max_volunteer, locations=[self.room]) else: context = { 'error_slot_form': self.event_form, 'error_slot_occurrence_id': int( request.POST['opp_sched_id']), 'rehearsal_open': True} elif 'delete_slot' in request.POST.keys(): opp = get_object_or_404( GenericEvent, event_id=request.POST['opp_event_id']) title = opp.e_title opp.delete() user_message = UserMessage.objects.get_or_create( view=self.__class__.__name__, code="DELETE_REHEARSAL_SUCCESS", defaults={ 'summary': "Rehearsal Slot Deleted", 'description': rehearsal_delete_msg}) messages.success( request, '%s<br>Title: %s' % ( user_message[0].description, title)) return HttpResponseRedirect(self.success_url) return self.check_success_and_return( request, response=response, errorcontext=context, window_controls="rehearsal_open=True")
def post(self, request, *args, **kwargs): context = {} response = None error_url = self.groundwork(request, args, kwargs) if error_url: return error_url if "manage-workers" in request.path: return super(EditVolunteerView, self).post(request, *args, **kwargs) context['association_form'] = EventAssociationForm(request.POST, initial={ 'staff_area': self.area, 'parent_event': self.parent_id }) context['event_form'] = EventBookingForm(request.POST, instance=self.item) context['scheduling_form'] = ScheduleOccurrenceForm( request.POST, conference=self.item.e_conference, open_to_public=event_settings[ self.item.type.lower()]['open_to_public']) if context['event_form'].is_valid( ) and context['scheduling_form'].is_valid( ) and context['association_form'].is_valid(): new_event = context['event_form'].save(commit=False) new_event.duration = timedelta( minutes=context['scheduling_form'].cleaned_data['duration'] * 60) new_event.save() labels = [ self.item.calendar_type, self.item.e_conference.conference_slug ] if context['association_form'].cleaned_data['staff_area']: labels += [ context['association_form'].cleaned_data['staff_area'].slug ] parent_id = -1 if context['association_form'].cleaned_data['parent_event']: parent_id = int( context['association_form'].cleaned_data['parent_event']) response = update_occurrence( self.occurrence.pk, get_start_time(context['scheduling_form'].cleaned_data), context['scheduling_form'].cleaned_data['max_volunteer'], people=None, roles=None, locations=[ context['scheduling_form'].cleaned_data['location'] ], approval=context['scheduling_form'].cleaned_data['approval'], labels=labels, parent_event_id=parent_id) if request.POST.get('edit_event', 0) != "Save and Continue": self.success_url = "%s?%s-day=%d&filter=Filter&new=%s" % ( reverse('manage_event_list', urlconf='gbe.scheduling.urls', args=[self.item.e_conference.conference_slug]), self.item.e_conference.conference_slug, context['scheduling_form'].cleaned_data['day'].pk, str([self.occurrence.pk]), ) else: self.success_url = "%s?%s=True" % (self.success_url, "worker_open") else: context['start_open'] = True return self.make_post_response(request, response=response, errorcontext=context)
def post(self, request, *args, **kwargs): error_url = self.groundwork(request, args, kwargs) if error_url: return error_url self.create = False response = None context = None if ('create' in list(request.POST.keys())) or ('duplicate' in list( request.POST.keys())): self.create = True if 'create' in list(request.POST.keys()): self.event_form = VolunteerOpportunityForm( request.POST, prefix='new_opp', conference=self.conference) else: self.event_form = VolunteerOpportunityForm( request.POST, conference=self.conference) if self.event_form.is_valid(): data = self.get_basic_form_settings() self.event.e_conference = self.conference self.event.save() response = create_occurrence(self.event.eventitem_id, self.start_time, self.max_volunteer, locations=[self.room], labels=data['labels'], parent_event_id=self.parent_id, approval=self.approval) else: context = { 'createform': self.event_form, 'volunteer_open': True } return self.check_success_and_return(request, response=response, errorcontext=context) elif 'edit' in list(request.POST.keys()): self.event = get_object_or_404( GenericEvent, event_id=request.POST['opp_event_id']) self.event_form = VolunteerOpportunityForm(request.POST, instance=self.event) if self.event_form.is_valid(): data = self.get_basic_form_settings() self.event_form.save() response = update_occurrence(data['opp_sched_id'], self.start_time, self.max_volunteer, locations=[self.room], approval=self.approval) else: context = { 'error_opp_form': self.event_form, 'volunteer_open': True } return self.check_success_and_return(request, response=response, errorcontext=context) elif 'delete' in list(request.POST.keys()): opp = get_object_or_404(GenericEvent, event_id=request.POST['opp_event_id']) title = opp.e_title opp.delete() user_message = UserMessage.objects.get_or_create( view=self.__class__.__name__, code="DELETE_SUCCESS", defaults={ 'summary': "Volunteer Opportunity Deleted", 'description': "This volunteer opportunity was deleted." }) messages.success( request, '%s<br>Title: %s' % (user_message[0].description, title)) return HttpResponseRedirect(self.success_url) elif 'allocate' in list(request.POST.keys()): response = get_occurrence(request.POST['opp_sched_id']) return HttpResponseRedirect( reverse('edit_volunteer', urlconf='gbe.scheduling.urls', args=[ self.conference.conference_slug, request.POST['opp_sched_id'] ])) else: actions = self.do_additional_actions(request) if actions: return actions else: user_message = UserMessage.objects.get_or_create( view=self.__class__.__name__, code="UNKNOWN_ACTION", defaults={ 'summary': "Unknown Action", 'description': "This is an unknown action." }) messages.error(request, user_message[0].description) return HttpResponseRedirect(self.success_url)
def post(self, request, *args, **kwargs): error_url = self.groundwork(request, args, kwargs) if error_url: return error_url self.create = False response = None context = None if ('create' in request.POST.keys()) or ( 'duplicate' in request.POST.keys()): self.create = True if 'create' in request.POST.keys(): self.event_form = VolunteerOpportunityForm( request.POST, prefix='new_opp', conference=self.conference) else: self.event_form = VolunteerOpportunityForm( request.POST, conference=self.conference) if self.event_form.is_valid(): data = self.get_basic_form_settings() self.event.e_conference = self.conference self.event.save() response = create_occurrence( self.event.eventitem_id, self.start_time, self.max_volunteer, locations=[self.room], labels=data['labels'], parent_event_id=self.parent_id) else: context = {'createform': self.event_form, 'volunteer_open': True} return self.check_success_and_return(request, response=response, errorcontext=context) elif 'edit' in request.POST.keys(): self.event = get_object_or_404( GenericEvent, event_id=request.POST['opp_event_id']) self.event_form = VolunteerOpportunityForm( request.POST, instance=self.event) if self.event_form.is_valid(): data = self.get_basic_form_settings() self.event_form.save() response = update_occurrence( data['opp_sched_id'], self.start_time, self.max_volunteer, locations=[self.room]) else: context = {'error_opp_form': self.event_form, 'volunteer_open': True} return self.check_success_and_return(request, response=response, errorcontext=context) elif 'delete' in request.POST.keys(): opp = get_object_or_404( GenericEvent, event_id=request.POST['opp_event_id']) title = opp.e_title opp.delete() user_message = UserMessage.objects.get_or_create( view=self.__class__.__name__, code="DELETE_SUCCESS", defaults={ 'summary': "Volunteer Opportunity Deleted", 'description': "This volunteer opportunity was deleted."}) messages.success( request, '%s<br>Title: %s' % ( user_message[0].description, title)) return HttpResponseRedirect(self.success_url) elif 'allocate' in request.POST.keys(): response = get_occurrence(request.POST['opp_sched_id']) return HttpResponseRedirect( reverse('edit_volunteer', urlconf='gbe.scheduling.urls', args=[self.conference.conference_slug, request.POST['opp_sched_id']])) else: actions = self.do_additional_actions(request) if actions: return actions else: user_message = UserMessage.objects.get_or_create( view=self.__class__.__name__, code="UNKNOWN_ACTION", defaults={ 'summary': "Unknown Action", 'description': "This is an unknown action."}) messages.error( request, user_message[0].description) return HttpResponseRedirect(self.success_url)
def post(self, request, *args, **kwargs): intro_message = self.groundwork(request, args, kwargs) if "day_id" in kwargs: day = get_object_or_404(ConferenceDay, pk=kwargs.get("day_id")) else: raise Http404 all_valid = True forms = [] the_form = None for conference in Conference.objects.filter( status__in=('upcoming', 'ongoing')): first_day = ConferenceDay.objects.filter( conference=conference).order_by('day').first() if first_day is not None: form = ConferenceStartChangeForm(request.POST, instance=first_day, prefix=first_day.pk) if first_day == day: form.fields['day'].required = True the_form = form all_valid = all_valid and form.is_valid() forms += [(first_day, form)] if the_form is None: messages.error(request, UserMessage.objects.get_or_create( view=self.__class__.__name__, code="NO_CONF_DAY_FORM", defaults={ 'summary': "Conference Day Form Not Loaded", 'description': missing_day_form_note})[0].description) all_valid = False if not all_valid: return render( request, 'gbe/scheduling/manage_conference.tmpl', {'forms': forms, 'intro': intro_message, 'title': self.title, 'button': self.button, 'header': self.header}) conf_change = the_form.cleaned_data['day'] - day.day # update each conference day so form selection offers right choices for each_day in day.conference.conferenceday_set.all(): each_day.day = each_day.day + conf_change each_day.save() messages.success( request, "Moved Conference %s by %d days, change %d conference days" % ( day.conference.conference_slug, conf_change.days, day.conference.conferenceday_set.count())) # update all scheduled events event_count = 0 response = get_occurrences( labels=[day.conference.conference_slug]) for occurrence in response.occurrences: occ_response = update_occurrence( occurrence.pk, start_time=occurrence.starttime + conf_change) show_general_status(request, occ_response, self.__class__.__name__) if occ_response and occ_response.occurrence: event_count = event_count + 1 messages.success( request, "Moved %d scheduled events by %d days" % ( event_count, conf_change.days)) general_calendar_links = "" class_calendar_links = "" volunteer_calendar_links = "" for each_day in day.conference.conferenceday_set.filter( open_to_public=True).order_by('day'): general_calendar_links = "%s<li>%s - %s?day=%s" % ( general_calendar_links, each_day.day.strftime("%A"), reverse("calendar", urlconf='gbe.scheduling.urls', args=['General']), each_day.day.strftime(URL_DATE)) class_calendar_links = "%s<li>%s - %s?day=%s" % ( class_calendar_links, each_day.day.strftime("%A"), reverse("calendar", urlconf='gbe.scheduling.urls', args=['Conference']), each_day.day.strftime(URL_DATE)) volunteer_calendar_links = "%s<li>%s - %s?day=%s" % ( volunteer_calendar_links, each_day.day.strftime("%A"), reverse("calendar", urlconf='gbe.scheduling.urls', args=['Volunteer']), each_day.day.strftime(URL_DATE)) messages.warning( request, ("REMINDER: Don't forget to change the calendar links: <ul>" + "<li>Special Events</li><ul>%s</ul><li>Conference Events</li>" + "<ul>%s</ul><li>Volunteer Events</li><ul>%s</ul></ul>") % ( general_calendar_links, class_calendar_links, volunteer_calendar_links)) return HttpResponseRedirect( ("%s?%s-calendar_type=0&%s-calendar_type=1&%s-calendar_type=2" + "&filter=Filter") % ( reverse('manage_event_list', urlconf='gbe.scheduling.urls'), day.conference.conference_slug, day.conference.conference_slug, day.conference.conference_slug))