示例#1
0
 def clear_bookings(self, request, rehearsals, show=None):
     for item in rehearsals:
         response = remove_booking(item.event.pk, item.booking_id)
         show_general_status(request, response, self.__class__.__name__)
     if show:
         response = remove_booking(show.event.pk, show.booking_id)
         show_general_status(request, response, self.__class__.__name__)
示例#2
0
    def get(self, request, *args, **kwargs):
        this_url = reverse(
                'set_favorite',
                args=[kwargs['occurrence_id'], kwargs['state']],
                urlconf='gbe.scheduling.urls')
        response = check_user_and_redirect(
            request,
            this_url,
            self.__class__.__name__)
        if response['error_url']:
            return HttpResponseRedirect(response['error_url'])
        self.owner = response['owner']
        occurrence_id = int(kwargs['occurrence_id'])
        interested = get_bookings([occurrence_id],
                                  roles=["Interested"])
        bookings = []
        for person in interested.people:
            if person.user == self.owner.user_object:
                bookings += [person.booking_id]

        if kwargs['state'] == 'on' and len(bookings) == 0:
            person = Person(
                user=self.owner.user_object,
                role="Interested")
            response = set_person(occurrence_id, person)
            show_general_status(request,
                                response,
                                self.__class__.__name__)
            if len(response.errors) == 0 and response.booking_id:
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="SET_FAVORITE",
                    defaults={
                        'summary': "User has shown interest",
                        'description': set_favorite_msg})
                messages.success(request, user_message[0].description)
        elif kwargs['state'] == 'off' and len(bookings) > 0:
            success = True
            for booking_id in bookings:
                response = remove_booking(occurrence_id,
                                          booking_id)
                show_general_status(request,
                                    response,
                                    self.__class__.__name__)
            if response.booking_id:
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="REMOVE_FAVORITE",
                    defaults={
                        'summary': "User has shown lack of interest",
                        'description': unset_favorite_msg})
                messages.success(request, user_message[0].description)
        if request.GET.get('next', None):
            redirect_to = request.GET['next']
        else:
            redirect_to = reverse('home', urlconf='gbe.urls')
        return HttpResponseRedirect(redirect_to)
示例#3
0
    def get(self, request, *args, **kwargs):
        this_url = reverse('set_favorite',
                           args=[kwargs['occurrence_id'], kwargs['state']],
                           urlconf='gbe.scheduling.urls')
        response = check_user_and_redirect(request, this_url,
                                           self.__class__.__name__)
        if response['error_url']:
            return HttpResponseRedirect(response['error_url'])
        self.owner = response['owner']
        occurrence_id = int(kwargs['occurrence_id'])
        interested = get_bookings([occurrence_id], roles=["Interested"])
        bookings = []
        for person in interested.people:
            if person.user == self.owner.user_object:
                bookings += [person.booking_id]

        if kwargs['state'] == 'on' and len(bookings) == 0:
            person = Person(user=self.owner.user_object, role="Interested")
            response = set_person(occurrence_id, person)
            show_general_status(request, response, self.__class__.__name__)
            if len(response.errors) == 0 and response.booking_id:
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="SET_FAVORITE",
                    defaults={
                        'summary': "User has shown interest",
                        'description': set_favorite_msg
                    })
                messages.success(request, user_message[0].description)
        elif kwargs['state'] == 'off' and len(bookings) > 0:
            success = True
            for booking_id in bookings:
                response = remove_booking(occurrence_id, booking_id)
                show_general_status(request, response, self.__class__.__name__)
            if response.booking_id:
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="REMOVE_FAVORITE",
                    defaults={
                        'summary': "User has shown lack of interest",
                        'description': unset_favorite_msg
                    })
                messages.success(request, user_message[0].description)
        if request.GET.get('next', None):
            redirect_to = request.GET['next']
        else:
            redirect_to = reverse('home', urlconf='gbe.urls')
        return HttpResponseRedirect(redirect_to)
示例#4
0
    def manage_schedule_problems(self, changed_windows, profile):
        warnings = []
        conflicts = []
        for window in changed_windows:
            conflict_check = get_schedule(
                    profile.user_object,
                    start_time=window.start_time,
                    end_time=window.end_time,
                    labels=[self.bid_object.b_conference.conference_slug])

            # choosing to error silently here, because the function does not
            # have any errors yet, and because this is a public user case
            for conflict in conflict_check.schedule_items:
                if ((conflict.event not in conflicts) and
                        conflict.role == "Volunteer"):
                    conflicts += [conflict.event]
                    warning = {
                        'time': conflict.event.starttime.strftime(
                            DATETIME_FORMAT),
                        'event': str(conflict.event),
                        'interest': conflict.event.eventitem.child(
                            ).volunteer_category_description,
                    }
                    leads = get_all_container_bookings(
                        occurrence_ids=[conflict.event.pk],
                        roles=['Staff Lead', ])
                    for lead in leads.people:
                        warning['lead'] = str(lead.user.profile.badge_name)
                        warning['email'] = lead.user.email
                    for area in StaffArea.objects.filter(
                            conference=self.bid_object.b_conference,
                            slug__in=conflict.event.labels.values_list(
                                'text',
                                flat=True)):
                        warning['lead'] = area.staff_lead.badge_name
                        warning['email'] = area.staff_lead.user_object.email
                    response = remove_booking(
                        occurrence_id=conflict.event.pk,
                        booking_id=conflict.booking_id)
                    warnings += [warning]
        return warnings
示例#5
0
 def post(self, request, *args, **kwargs):
     form = WorkerAllocationForm(request.POST)
     response = None
     email_status = None
     if not form.is_valid():
         context = None
         if request.POST['alloc_id'] == '-1':
             form.data['alloc_id'] = -1
             context = {'new_worker_alloc_form': form}
         else:
             is_present = test_booking(
                 int(request.POST['alloc_id']), self.occurrence.pk)
             if not is_present:
                 response = PersonResponse(errors=[Error(
                     code="BOOKING_NOT_FOUND",
                     details="Booking id %s for occurrence %d not found" % (
                         request.POST['alloc_id'], self.occurrence.pk)), ])
             context = {'worker_alloc_forms': form}
         return self.make_post_response(request,
                                        response=response,
                                        errorcontext=context)
     else:
         data = form.cleaned_data
         if 'delete' in request.POST.keys():
             if ('alloc_id' not in request.POST) or (len(
                     request.POST['alloc_id']) == 0):
                 return self.make_post_response(
                     request,
                     PersonResponse(errors=[Error(
                         code="NO_BOOKING",
                         details="No booking id for occurrence id %d." % (
                             self.occurrence.pk))]))
             response = remove_booking(
                 self.occurrence.pk,
                 booking_id=int(request.POST['alloc_id']))
             if response.booking_id:
                 email_status = send_schedule_update_mail(
                     "Volunteer", data['worker'].workeritem.as_subtype)
         elif data.get('worker', None):
             if data['role'] == "Volunteer":
                 data['worker'].workeritem.as_subtype.check_vol_bid(
                     self.item.e_conference)
             person = Person(
                 user=data['worker'].workeritem.as_subtype.user_object,
                 public_id=data['worker'].workeritem.as_subtype.pk,
                 role=data['role'],
                 label=data['label'],
                 worker=None)
             if int(data['alloc_id']) > -1:
                 person.booking_id = int(data['alloc_id'])
             response = set_person(
                 self.occurrence.pk,
                 person
             )
             email_status = send_schedule_update_mail("Volunteer",
                                                      data['worker'])
         if email_status:
             user_message = UserMessage.objects.get_or_create(
                 view=self.__class__.__name__,
                 code="EMAIL_FAILURE",
                 defaults={
                     'summary': "Email Failed",
                     'description': volunteer_allocate_email_fail_msg})
             messages.error(
                 request,
                 user_message[0].description)
         self.success_url = reverse('edit_event',
                                    urlconf='gbe.scheduling.urls',
                                    args=[self.conference.conference_slug,
                                          self.occurrence.pk])
     return self.make_post_response(request,
                                    response=response)
示例#6
0
    def book_rehearsals(self, request):
        error = False
        bookings = []
        forms = self.set_rehearsal_forms(request)
        # using the form guarantees that we've checked that the user is
        # only booking rehearsals that are open, for shows they are in.
        for rehearsal_form in forms:
            if not rehearsal_form.is_valid():
                error = True
        if error:
            return error, bookings, forms, request

        for rehearsal_form in forms:
            if int(rehearsal_form.cleaned_data['rehearsal']) >= 0:
                person = Person(
                    public_id=self.act.performer.pk,
                    role="performer",
                    commitment=Commitment(decorator_class=self.act))
                if rehearsal_form.cleaned_data['booking_id']:
                    person.booking_id = int(
                        rehearsal_form.cleaned_data['booking_id'])
                response = set_person(occurrence_id=int(
                    rehearsal_form.cleaned_data['rehearsal']),
                                      person=person)
                # errors are internal, and not OK to show regular user
                if response.errors:
                    error = True
                else:
                    show_general_status(request, response,
                                        self.__class__.__name__)
                self.act.tech.confirm_no_rehearsal = False
                if response.occurrence:
                    bookings += [response.occurrence]
                    self.rehearsals[int(rehearsal_form.prefix)] = ScheduleItem(
                        event=response.occurrence,
                        booking_id=response.booking_id)
            else:
                if rehearsal_form.cleaned_data['booking_id']:
                    response = remove_booking(
                        occurrence_id=self.rehearsals[int(
                            rehearsal_form.prefix)].event.pk,
                        booking_id=int(
                            rehearsal_form.cleaned_data['booking_id']))
                    # errors are internal, and not OK to show regular user
                    if response.errors:
                        error = True
                    else:
                        del self.rehearsals[int(rehearsal_form.prefix)]
                        success = UserMessage.objects.get_or_create(
                            view=self.__class__.__name__,
                            code="REHEARSAL_REMOVED",
                            defaults={
                                'summary': "User Canceled Rehearsal",
                                'description': rehearsal_remove_confirmation
                            })
                        messages.success(request, success[0].description)
                self.act.tech.confirm_no_rehearsal = True
                self.act.tech.save()
        # if there has been no failure, we've changed the state of rehearsal
        # bookings, and the forms should be changed to reflect the new
        # persistent state - BUG found on 7/9/21 with GBE-238
        if not error:
            forms = self.set_rehearsal_forms()
        return error, bookings, forms, request
    def get(self, request, *args, **kwargs):
        if request.GET.get('next', None):
            redirect_to = request.GET['next']
        else:
            redirect_to = reverse('home', urlconf='gbe.urls')
        this_url = reverse('set_volunteer',
                           args=[kwargs['occurrence_id'], kwargs['state']],
                           urlconf='gbe.scheduling.urls')
        response = check_user_and_redirect(request, this_url,
                                           self.__class__.__name__)
        if response['error_url']:
            return HttpResponseRedirect(response['error_url'])
        self.owner = response['owner']
        occurrence_id = int(kwargs['occurrence_id'])
        occ_response = get_occurrence(occurrence_id)
        show_general_status(request, occ_response, self.__class__.__name__)
        if occ_response.errors:
            return HttpResponseRedirect(redirect_to)

        volunteers = get_bookings([occurrence_id],
                                  roles=["Volunteer", "Pending Volunteer"])
        bookings = []
        for person in volunteers.people:
            if person.user == self.owner.user_object:
                bookings += [person]
        schedule_response = None
        if kwargs['state'] == 'on' and len(bookings) == 0:
            # if this person hasn't volunteered yet, and wants to
            role = "Volunteer"
            default_summary = "User has volunteered"
            default_message = set_volunteer_msg
            if occ_response.occurrence.approval_needed:
                role = "Pending Volunteer"
                default_summary = "User is pending"
                default_message = set_pending_msg
            person = Person(user=self.owner.user_object, role=role)
            schedule_response = set_person(occurrence_id, person)
            show_general_status(request, schedule_response,
                                self.__class__.__name__, False)
            if len(schedule_response.errors) == 0 and (
                    schedule_response.booking_id):
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="SET_%s" % role.replace(" ", "_").upper(),
                    defaults={
                        'summary': default_summary,
                        'description': default_message
                    })
                messages.success(request, user_message[0].description)

        elif kwargs['state'] == 'off' and len(bookings) > 0:
            # if this person has volunteered, and is withdrawing
            success = True
            for booking in bookings:
                role = booking.role
                default_summary = "User withdrew"
                default_message = unset_volunteer_msg
                if role == "Pending Volunteer":
                    default_summary = "Pending user withdrew"
                    default_message = unset_pending_msg
                schedule_response = remove_booking(occurrence_id,
                                                   booking.booking_id)
                show_general_status(request, schedule_response,
                                    self.__class__.__name__)
                if schedule_response.booking_id:
                    user_message = UserMessage.objects.get_or_create(
                        view=self.__class__.__name__,
                        code="REMOVE_%s" % role.replace(" ", "_").upper(),
                        defaults={
                            'summary': default_summary,
                            'description': default_message
                        })
                    messages.success(request, user_message[0].description)
        if schedule_response and schedule_response.booking_id:
            email_status = send_schedule_update_mail("Volunteer", self.owner)
            staff_status = send_volunteer_update_to_staff(
                self.owner, self.owner, occ_response.occurrence,
                kwargs['state'], schedule_response)
            if (email_status or staff_status) and validate_perms(
                    request, 'any', require=False):
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="EMAIL_FAILURE",
                    defaults={
                        'summary': "Email Failed",
                        'description': volunteer_allocate_email_fail_msg
                    })
                messages.error(request,
                               user_message[0].description + "status code: ")
        return HttpResponseRedirect(redirect_to)