def save(self, vr=None): if vr: ts = vr.timeslot ts.start = self.cleaned_data['start_time'] ts.end = self.cleaned_data['end_time'] ts.short_description = ts.description = self.cleaned_data[ 'description'] ts.save() vr.num_volunteers = self.cleaned_data['num_volunteers'] vr.program = self.program vr.save() else: ts = Event() ts.program = self.program ts.start = self.cleaned_data['start_time'] ts.end = self.cleaned_data['end_time'] ts.short_description = ts.description = self.cleaned_data[ 'description'] ts.event_type = EventType.get_from_desc('Volunteer') ts.save() vr = VolunteerRequest() vr.program = self.program vr.timeslot = ts vr.num_volunteers = self.cleaned_data['num_volunteers'] vr.save()
def save(self, vr=None): if vr: ts = vr.timeslot ts.start = self.cleaned_data['start_time'] ts.end = self.cleaned_data['end_time'] ts.short_description = ts.description = self.cleaned_data[ 'description'] ts.save() vr.num_volunteers = self.cleaned_data['num_volunteers'] vr.program = self.program vr.save() else: ts = Event() ts.anchor = self.program.anchor ts.start = self.cleaned_data['start_time'] ts.end = self.cleaned_data['end_time'] ts.short_description = ts.description = self.cleaned_data[ 'description'] ts.event_type, created = EventType.objects.get_or_create( description='Volunteer') ts.save() vr = VolunteerRequest() vr.program = self.program vr.timeslot = ts vr.num_volunteers = self.cleaned_data['num_volunteers'] vr.save()
def resources_timeslot_import(self, request, tl, one, two, module, extra, prog): context = {} response = None controller = ResourceController(prog) import_mode = 'preview' if 'import_confirm' in request.POST and request.POST[ 'import_confirm'] == 'yes': import_mode = 'save' import_form = TimeslotImportForm(request.POST) if not import_form.is_valid(): context['import_timeslot_form'] = import_form else: past_program = import_form.cleaned_data['program'] start_date = import_form.cleaned_data['start_date'] if past_program == prog: raise ESPError( "You're trying to import timeslots from a program" " to itself! Try a different program instead.", log=False) # Figure out timeslot dates new_timeslots = [] prev_timeslots = past_program.getTimeSlots().order_by('start') time_delta = start_date - prev_timeslots[0].start.date() for orig_timeslot in prev_timeslots: new_timeslot = Event( program=self.program, event_type=orig_timeslot.event_type, short_description=orig_timeslot.short_description, description=orig_timeslot.description, priority=orig_timeslot.priority, start=orig_timeslot.start + time_delta, end=orig_timeslot.end + time_delta, ) # Save the new timeslot only if it doesn't duplicate an existing one if import_mode == 'save' and not Event.objects.filter( program=new_timeslot.program, start=new_timeslot.start, end=new_timeslot.end).exists(): new_timeslot.save() new_timeslots.append(new_timeslot) # Render a preview page showing the resources for the previous program if desired context['past_program'] = past_program context['start_date'] = start_date.strftime('%m/%d/%Y') context['new_timeslots'] = new_timeslots if import_mode == 'preview': context['prog'] = self.program response = render_to_response( self.baseDir() + 'timeslot_import.html', request, context) else: extra = 'timeslot' return (response, context)
def resources_timeslot_import(self, request, tl, one, two, module, extra, prog): context = {} response = None controller = ResourceController(prog) import_mode = 'preview' if 'import_confirm' in request.POST and request.POST['import_confirm'] == 'yes': import_mode = 'save' import_form = TimeslotImportForm(request.POST) if not import_form.is_valid(): context['import_timeslot_form'] = import_form else: past_program = import_form.cleaned_data['program'] start_date = import_form.cleaned_data['start_date'] # Figure out timeslot dates new_timeslots = [] prev_timeslots = past_program.getTimeSlots().order_by('start') time_delta = start_date - prev_timeslots[0].start.date() for orig_timeslot in prev_timeslots: new_timeslot = Event( program = self.program, event_type = orig_timeslot.event_type, short_description = orig_timeslot.short_description, description = orig_timeslot.description, priority = orig_timeslot.priority, start = orig_timeslot.start + time_delta, end = orig_timeslot.end + time_delta, ) # Save the new timeslot only if it doesn't duplicate an existing one if import_mode == 'save' and not Event.objects.filter(program=new_timeslot.program, start=new_timeslot.start, end=new_timeslot.end).exists(): new_timeslot.save() new_timeslots.append(new_timeslot) # Render a preview page showing the resources for the previous program if desired context['past_program'] = past_program context['start_date'] = start_date.strftime('%m/%d/%Y') context['new_timeslots'] = new_timeslots if import_mode == 'preview': context['prog'] = self.program response = render_to_response(self.baseDir()+'timeslot_import.html', request, context) else: extra = 'timeslot' return (response, context)
def save(self, vr=None): if vr: ts = vr.timeslot ts.start = self.cleaned_data['start_time'] ts.end = self.cleaned_data['end_time'] ts.short_description = ts.description = self.cleaned_data['description'] ts.save() vr.num_volunteers = self.cleaned_data['num_volunteers'] vr.program = self.program vr.save() else: ts = Event() ts.program = self.program ts.start = self.cleaned_data['start_time'] ts.end = self.cleaned_data['end_time'] ts.short_description = ts.description = self.cleaned_data['description'] ts.event_type = EventType.get_from_desc('Volunteer') ts.save() vr = VolunteerRequest() vr.program = self.program vr.timeslot = ts vr.num_volunteers = self.cleaned_data['num_volunteers'] vr.save()