def bid_state_change(self, request):
        # Clear all commitments
        remove_response = remove_person(
            user=self.bidder.user_object,
            labels=[self.object.b_conference.conference_slug],
            roles=['Volunteer'])
        show_general_status(request, remove_response, self.__class__.__name__)

        # if the volunteer has been accepted, set the events.
        if request.POST['accepted'] == '3':
            person = Person(
                    user=self.bidder.user_object,
                    public_id=self.bidder.pk,
                    role='Volunteer')
            for assigned_event in request.POST.getlist('events'):
                set_response = set_person(
                    assigned_event,
                    person)
                show_general_status(request,
                                    set_response,
                                    self.__class__.__name__)

            email_status = send_schedule_update_mail('Volunteer', self.bidder)
            self.check_email_status(request, email_status)

        return super(VolunteerChangeStateView, self).bid_state_change(
            request)
Esempio n. 2
0
 def set_status(self, request, kwargs):
     check = False
     state = volunteer_action_map[kwargs['action']]['state']
     if kwargs['action'] == "approve":
         check = True
     profile = get_object_or_404(Profile, pk=kwargs['public_id'])
     person = Person(user=profile.user_object,
                     public_id=profile.pk,
                     role=volunteer_action_map[kwargs['action']]['role'],
                     booking_id=kwargs['booking_id'],
                     worker=None)
     response = set_person(person=person)
     show_general_status(request, response, self.__class__.__name__)
     if not response.errors:
         self.changed_id = response.booking_id
         user_message = UserMessage.objects.get_or_create(
             view=self.__class__.__name__,
             code="SET_%s" % person.role,
             defaults={
                 'summary': set_volunteer_role_summary % person.role,
                 'description': set_volunteer_role_msg % person.role
             })
         full_msg = '%s Person: %s<br/>Event: %s, Start Time: %s' % (
             user_message[0].description, str(profile),
             str(response.occurrence),
             response.occurrence.starttime.strftime(GBE_DATETIME_FORMAT))
         messages.success(request, full_msg)
         self.send_notifications(request, response, state, person)
Esempio n. 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)
Esempio n. 4
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)
Esempio n. 5
0
    def post(self, request, *args, **kwargs):
        error_url = self.groundwork(request, args, kwargs)
        if error_url:
            return error_url
        data = self.get_context_data(request)
        if not data['all_valid']:
            messages.error(
                request,
                UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="ACT_SCHED_ERROR",
                    defaults={
                        'summary': "Act Order Forms not valid",
                        'description': act_order_form_invalid
                    })[0].description)
            data['open_panel'] = 'act'
        else:
            for act in data['acts']:
                person = Person(public_id=act['act'].performer.pk,
                                booking_id=act['form'].prefix,
                                role="Performer",
                                commitment=Commitment(
                                    decorator_class=act['act'],
                                    order=act['form'].cleaned_data['order']))
                response = set_person(person=person,
                                      occurrence_id=self.occurrence.pk)
                # we don't care about overbook warnings on this case
                response.warnings = []
                show_general_status(request, response, self.__class__.__name__)
            # I can't think of a reason the set_person could fail that isn't
            # already ruled out by how the request is constructed.
            messages.success(
                request,
                UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="ACT_SCHED_SUCCESS",
                    defaults={
                        'summary': "Order of Acts was updated",
                        'description': act_order_submit_success
                    })[0].description)

        return render(request, self.template, data)
Esempio n. 6
0
    def bid_state_change(self, request):
        # Clear all commitments
        remove_response = remove_person(
            user=self.bidder.user_object,
            labels=[self.object.b_conference.conference_slug],
            roles=['Volunteer'])
        show_general_status(request, remove_response, self.__class__.__name__)

        # if the volunteer has been accepted, set the events.
        if request.POST['accepted'] == '3':
            person = Person(user=self.bidder.user_object,
                            public_id=self.bidder.pk,
                            role='Volunteer')
            for assigned_event in request.POST.getlist('events'):
                set_response = set_person(assigned_event, person)
                show_general_status(request, set_response,
                                    self.__class__.__name__)

            email_status = send_schedule_update_mail('Volunteer', self.bidder)
            self.check_email_status(request, email_status)

        return super(VolunteerChangeStateView, self).bid_state_change(request)
Esempio n. 7
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)
Esempio n. 8
0
 def test_no_arguments(self):
     response = set_person()
     self.assertEqual(response.errors[0].code, "OCCURRENCE_NOT_FOUND")
     self.assertEqual(response.errors[0].details,
                      "Neither booking id nor occurrence id provided")
Esempio n. 9
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)
Esempio n. 11
0
    def bid_state_change(self, request):
        show = None
        rehearsals = []

        # Determine if the current show should be changed
        if self.object.accepted in self.show_booked_states:
            response = get_schedule(commitment=self.object,
                                    roles=["Performer", "Waitlisted"])
            show_general_status(request, response, self.__class__.__name__)
            show, rehearsals = self.parse_act_schedule(response.schedule_items)

        # if the act has been accepted, set the show.
        if self.act_accepted(request):
            # Cast the act into the show by adding it to the schedule
            # resource time
            if ('casting' not in request.POST) or (
                    request.POST['casting'] != ''
                    and ActCastingOption.objects.filter(
                        casting=request.POST['casting']).count() == 0):
                user_message = UserMessage.objects.get_or_create(
                    view=self.__class__.__name__,
                    code="INVALID_CASTING",
                    defaults={
                        'summary': "Casting Role Incorrect",
                        'description': no_casting_msg
                    })
                messages.error(request, user_message[0].description)

                return HttpResponseRedirect(
                    reverse("act_review",
                            urlconf='gbe.urls',
                            args=[self.object.pk]))
            casting = request.POST['casting']
            role = "Performer"
            if request.POST['accepted'] == '2':
                casting = "Waitlisted"
                role = "Waitlisted"

            same_show = False
            same_role = False
            if show and show.event.eventitem == self.new_show.eventitem:
                same_show = True
                if casting == show.commitment.role:
                    user_message = UserMessage.objects.get_or_create(
                        view=self.__class__.__name__,
                        code="ACT_NO_CHANGE",
                        defaults={
                            'summary': "Act State Not Changed",
                            'description': act_status_no_change_msg
                        })
                    messages.success(
                        request, "%s<br>Performer/Act: %s - %s" %
                        (user_message[0].description,
                         self.object.performer.name, self.object.b_title))
                    return super(ActChangeStateView,
                                 self).bid_state_change(request)

            person = Person(public_id=self.object.performer.pk,
                            role=role,
                            commitment=Commitment(role=casting,
                                                  decorator_class=self.object))
            profiles = self.object.get_performer_profiles()
            if len(profiles) > 1:
                person.users = [profile.user_object for profile in profiles]
            else:
                person.user = profiles[0].user_object
            if same_show and not same_role:
                person.booking_id = show.booking_id
                set_response = set_person(person=person)
                self.show_set_act_status(request, set_response)
                if request.POST['accepted'] != '3':
                    self.clear_bookings(request, rehearsals)
            elif not same_show:
                self.clear_bookings(request, rehearsals, show)
                set_response = set_person(occurrence_id=self.new_show.pk,
                                          person=person)
                self.show_set_act_status(request, set_response)

            user_message = UserMessage.objects.get_or_create(
                view=self.__class__.__name__,
                code="ACT_ACCEPTED",
                defaults={
                    'summary': "Act State Changed (Accept/Waitlist)",
                    'description': act_status_change_msg
                })
            messages.success(
                request,
                "%s<br>Performer/Act: %s - %s<br>State: %s<br>Show: %s" %
                (user_message[0].description, self.object.performer.name,
                 self.object.b_title, acceptance_states[int(
                     request.POST['accepted'])][1],
                 self.new_show.eventitem.child().e_title))
        else:
            self.clear_bookings(request, rehearsals, show)
            user_message = UserMessage.objects.get_or_create(
                view=self.__class__.__name__,
                code="ACT_NOT_ACCEPTED",
                defaults={
                    'summary': "Act State Changed (Not Accepted)",
                    'description': act_status_change_msg
                })
            messages.success(
                request, "%s<br>Performer/Act: %s - %s<br>State: %s" %
                (user_message[0].description, self.object.performer.name,
                 self.object.b_title, acceptance_states[int(
                     request.POST['accepted'])][1]))

        return super(ActChangeStateView, self).bid_state_change(request)