Ejemplo n.º 1
0
def setup_event_management_form(conference, item, occurrence, context):
    duration = float(item.duration.total_minutes()) / 60
    initial_form_info = {
        'duration':
        duration,
        'max_volunteer':
        occurrence.max_volunteer,
        'day':
        get_conference_day(conference=conference,
                           date=occurrence.starttime.date()),
        'time':
        occurrence.starttime.strftime("%H:%M:%S"),
        'location':
        occurrence.location,
        'occurrence_id':
        occurrence.pk,
    }
    context['event_id'] = occurrence.pk
    context['eventitem_id'] = item.eventitem_id

    # if there was an error in the edit form
    if 'event_form' not in context:
        context['event_form'] = EventBookingForm(instance=item)
    if 'scheduling_form' not in context:
        context['scheduling_form'] = ScheduleOccurrenceForm(
            conference=conference,
            open_to_public=True,
            initial=initial_form_info)
    return (context, initial_form_info)
 def get(self, request, *args, **kwargs):
     context = self.groundwork(request, args, kwargs)
     if self.event_type == "show":
         context['second_form'] = ShowBookingForm(
             initial={'e_conference': self.conference})
     else:
         context['second_form'] = GenericBookingForm(
             initial={
                 'e_conference': self.conference,
                 'type': self.event_type.title()
             })
     context['scheduling_form'] = ScheduleOccurrenceForm(
         conference=self.conference,
         open_to_public=True,
         initial={
             'duration': 1,
             'max_volunteer':
             event_settings[self.event_type]['max_volunteer']
         })
     context['worker_formset'] = self.make_formset(
         event_settings[self.event_type]['roles'])
     if validate_perms(request, ('Ticketing - Admin', ), require=False):
         context['tickets'] = LinkBPTEventForm(
             initial={
                 'conference': self.conference,
             })
     return render(request, self.template, context)
Ejemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     more_view = "edit_event"
     context = self.groundwork(request, args, kwargs)
     if self.event_type == "show":
         context['second_form'] = ShowBookingForm(request.POST)
         more_view = "edit_show"
     else:
         context['second_form'] = GenericBookingForm(request.POST)
     context['scheduling_form'] = ScheduleOccurrenceForm(
         request.POST,
         conference=self.conference)
     context['worker_formset'] = self.make_formset(
         event_settings[self.event_type]['roles'],
         post=request.POST)
     if validate_perms(request, ('Ticketing - Admin',), require=False):
         context['tickets'] = LinkBPTEventForm(request.POST, initial={
             'conference': self.conference, })
     if context['second_form'].is_valid(
             ) and context['scheduling_form'].is_valid(
             ) and self.is_formset_valid(context['worker_formset']) and (
             not context['tickets'] or context['tickets'].is_valid()):
         new_event = context['second_form'].save(commit=False)
         new_event.duration = Duration(
             minutes=context['scheduling_form'].cleaned_data[
                 'duration']*60)
         new_event.save()
         response = self.book_event(context['scheduling_form'],
                                    context['worker_formset'],
                                    new_event)
         if context['tickets']:
             self.setup_ticket_links(request, new_event, context['tickets'])
         success = self.finish_booking(
             request,
             response,
             context['scheduling_form'].cleaned_data['day'].pk)
         if success:
             if request.POST.get(
                     'set_event') == 'More...':
                 return HttpResponseRedirect(
                     "%s?volunteer_open=True&rehearsal_open=True" %
                     reverse(more_view,
                             urlconf='gbe.scheduling.urls',
                             args=[self.conference.conference_slug,
                                   response.occurrence.pk]))
             else:
                 return success
     return render(request, self.template, context)
Ejemplo n.º 4
0
def process_post_response(request,
                          slug,
                          item,
                          start_success_url,
                          next_step,
                          occurrence_id,
                          roles=None,
                          additional_validity=True,
                          people_forms=[]):
    success_url = start_success_url
    context = {}
    response = None
    context['event_form'] = EventBookingForm(request.POST,
                                             instance=item)
    context['scheduling_form'] = ScheduleOccurrenceForm(
        request.POST,
        conference=item.e_conference,
        open_to_public=event_settings[item.type.lower()]['open_to_public'])

    if context['event_form'].is_valid(
            ) and context['scheduling_form'].is_valid(
            ) and additional_validity:
        new_event = context['event_form'].save(commit=False)
        new_event.duration = timedelta(
            minutes=context['scheduling_form'].cleaned_data[
                'duration']*60)
        new_event.save()
        response = update_event(context['scheduling_form'],
                                occurrence_id,
                                roles,
                                people_forms)
        if request.POST.get('edit_event', 0) != "Save and Continue":
            success_url = "%s?%s-day=%d&filter=Filter&new=%s" % (
                reverse('manage_event_list',
                        urlconf='gbe.scheduling.urls',
                        args=[slug]),
                slug,
                context['scheduling_form'].cleaned_data['day'].pk,
                str([occurrence_id]),)
        else:
            success_url = "%s?%s=True" % (success_url, next_step)
    else:
        context['start_open'] = True
    return context, success_url, response
Ejemplo n.º 5
0
 def setup_third_form(self, working_class=None):
     context = {}
     if working_class is not None:
         context['third_title'] = "Book Class:  %s" % (
             working_class.e_title)
         context['third_form'] = ClassBookingForm(instance=working_class)
         duration = working_class.duration.total_seconds() / timedelta(
             hours=1).total_seconds()
         context['scheduling_info'] = get_scheduling_info(working_class)
     else:
         context['third_form'] = ClassBookingForm()
         duration = 1
     context['scheduling_form'] = ScheduleOccurrenceForm(
         conference=self.conference,
         open_to_public=True,
         initial={
             'duration': duration,
         })
     context['scheduling_form'].fields[
         'max_volunteer'].widget = HiddenInput()
     context['worker_formset'] = self.make_formset(working_class)
     return context
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     working_class = None
     context = self.groundwork(request, args, kwargs)
     context['second_form'] = PickVolunteerTopicForm(
         request.POST, initial={'conference': self.conference})
     context['third_title'] = "Make New Volunteer Opportunity"
     if 'pick_topic' in request.POST.keys(
     ) and context['second_form'].is_valid():
         if context['second_form'].cleaned_data[
                 'volunteer_topic'] and 'staff_' in context[
                     'second_form'].cleaned_data['volunteer_topic']:
             staff_area_id = context['second_form'].cleaned_data[
                 'volunteer_topic'].split("staff_")[1]
             return HttpResponseRedirect(
                 "%s?volunteer_open=True" %
                 reverse('edit_staff',
                         urlconf='gbe.scheduling.urls',
                         args=[staff_area_id]))
         elif context['second_form'].cleaned_data['volunteer_topic']:
             occurrence_id = context['second_form'].cleaned_data[
                 'volunteer_topic']
             return HttpResponseRedirect("%s?volunteer_open=True" % reverse(
                 'edit_event',
                 urlconf='gbe.scheduling.urls',
                 args=[self.conference.conference_slug, occurrence_id]))
         else:
             context['third_title'] = "Make New Volunteer Opportunity"
             context['third_form'] = GenericBookingForm(
                 initial={
                     'e_conference': self.conference,
                     'type': "Volunteer"
                 })
             context['scheduling_form'] = ScheduleOccurrenceForm(
                 conference=self.conference,
                 initial={
                     'duration': 1,
                     'max_volunteer': 1
                 })
             context['worker_formset'] = self.make_formset(self.roles)
     elif 'set_opp' in request.POST.keys():
         context['third_title'] = "Make New Volunteer Opportunity"
         context['third_form'] = GenericBookingForm(request.POST)
         context['second_form'] = PickVolunteerTopicForm(
             initial={'conference': self.conference})
         context['scheduling_form'] = ScheduleOccurrenceForm(
             request.POST, conference=self.conference)
         context['worker_formset'] = self.make_formset(self.roles,
                                                       post=request.POST)
         if context['third_form'].is_valid() and context[
                 'scheduling_form'].is_valid() and self.is_formset_valid(
                     context['worker_formset']):
             volunteer_event = context['third_form'].save(commit=False)
             volunteer_event.duration = Duration(
                 minutes=context['scheduling_form'].cleaned_data['duration']
                 * 60)
             volunteer_event.save()
             response = self.book_event(context['scheduling_form'],
                                        context['worker_formset'],
                                        volunteer_event)
             success = self.finish_booking(
                 request, response,
                 context['scheduling_form'].cleaned_data['day'].pk)
             if success:
                 return success
     return render(request, self.template, context)
Ejemplo n.º 8
0
    def post(self, request, *args, **kwargs):
        working_class = None
        context = self.groundwork(request, args, kwargs)
        context['second_form'] = PickClassForm(
            request.POST, initial={'conference': self.conference})
        context['third_title'] = "Make New Class"
        if 'pick_class' in request.POST.keys(
        ) and context['second_form'].is_valid():
            if context['second_form'].cleaned_data['accepted_class']:
                working_class = context['second_form'].cleaned_data[
                    'accepted_class']
                context['third_title'] = "Book Class:  %s" % (
                    working_class.e_title)
                context['third_form'] = ClassBookingForm(
                    instance=working_class)
                duration = working_class.duration.hours() + float(
                    working_class.duration.minutes()) / 60
                context['scheduling_info'] = get_scheduling_info(working_class)
            else:
                context['third_form'] = ClassBookingForm()
                duration = 1
            context['scheduling_form'] = ScheduleOccurrenceForm(
                conference=self.conference,
                open_to_public=True,
                initial={
                    'duration': duration,
                })
            context['scheduling_form'].fields[
                'max_volunteer'].widget = HiddenInput()
            context['worker_formset'] = self.make_formset(working_class)

        elif 'set_class' in request.POST.keys(
        ) and 'eventitem_id' in request.POST.keys():
            if request.POST['eventitem_id']:
                working_class = get_object_or_404(
                    Class, eventitem_id=request.POST['eventitem_id'])
                context['third_title'] = "Book Class:  %s" % (
                    working_class.e_title)
                context['third_form'] = ClassBookingForm(
                    request.POST, instance=working_class)
                context['scheduling_info'] = get_scheduling_info(working_class)
            else:
                context['third_form'] = ClassBookingForm(request.POST)
            context['second_form'] = PickClassForm(
                initial={
                    'conference': self.conference,
                    'accepted_class': working_class
                })
            context['scheduling_form'] = ScheduleOccurrenceForm(
                request.POST, conference=self.conference)
            context['scheduling_form'].fields[
                'max_volunteer'].widget = HiddenInput()
            context['worker_formset'] = self.make_formset(working_class,
                                                          post=request.POST)
            if context['third_form'].is_valid() and context[
                    'scheduling_form'].is_valid() and self.is_formset_valid(
                        context['worker_formset']):
                working_class = context['third_form'].save(commit=False)
                working_class.duration = Duration(
                    minutes=context['scheduling_form'].cleaned_data['duration']
                    * 60)
                if not hasattr(working_class, 'teacher'):
                    teacher = None
                    for form in context['worker_formset']:
                        if form.cleaned_data['worker']:
                            teacher = form.cleaned_data['worker']
                            break
                    if teacher:
                        working_class.teacher = teacher
                    else:
                        user_message = UserMessage.objects.get_or_create(
                            view=self.__class__.__name__,
                            code="NEED_LEADER",
                            defaults={
                                'summary':
                                "Need Leader for Class",
                                'description':
                                "You must select at least " +
                                "one person to run this class."
                            })
                        messages.error(request, user_message[0].description)
                        return render(request, self.template, context)
                    working_class.e_conference = self.conference
                    working_class.b_conference = self.conference

                working_class.save()
                response = self.book_event(context['scheduling_form'],
                                           context['worker_formset'],
                                           working_class)
                success = self.finish_booking(
                    request, response,
                    context['scheduling_form'].cleaned_data['day'].pk)
                if success:
                    return success
        return render(request, self.template, context)