Exemplo n.º 1
0
def admin_set_volunteer_attendance(registration_id, attendance_state):
    success, error = ('',)*2
    if registration_id and attendance_state:
        try:
            volunteer_registration = Volunteer_Date_Registration.objects.get(id=registration_id)
            volunteer_date = volunteer_registration.volunteer_date
            volunteer_user = volunteer_registration.volunteer

            # set appropriate attendance state
            if attendance_state == 'yes':
                volunteer_registration.attended = True
            else:
                volunteer_registration.attended = False
            volunteer_registration.marked = True

            volunteer_registration.save()

            # localize the volunteer date times for emailing
            localized_start = localize(volunteer_date.event_begin)
            localized_end = localize(volunteer_date.event_end)

            # send notification email
            if volunteer_registration.attended:
                send_date_attended_email(volunteer_user, localized_start, localized_end)
            else:
                send_date_absent_email(volunteer_user, localized_start, localized_end)

            success = 'Successfully saved attendance state for {0} {1}'.format(volunteer_user.first_name,
                                                                               volunteer_user.last_name)
        except:
            error = 'Registration does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        try:
            hours_from_now = options.get('hours_from_now')
            volunteer_dates = Volunteer_Date.objects
            num_emails_sent = 0

            for volunteer_date in volunteer_dates:
                # check if volunteer_date is in the future and within hours_from_now
                if 0 < get_diff_from_now(volunteer_date.event_begin) < hours_from_now:
                    # localize the volunteer date times for emailing
                    localized_start = localize(volunteer_date.event_begin)
                    localized_end = localize(volunteer_date.event_end)

                    # send volunteers reminder emails
                    for volunteer in volunteer_date.volunteers:
                        send_volunteer_reminder_email(volunteer,
                                                      localized_start,
                                                      localized_end)
                        num_emails_sent+=1

            self.stdout.write('Successfully emailed %d volunteers with '
                              'registrations %d hours from now' %
                              (num_emails_sent, hours_from_now))
        except Exception as e:
            raise CommandError('Error sending emails: %s' % e)
Exemplo n.º 3
0
def admin_delete_volunteering_date(date_id):
    success, error = ('',)*2
    if date_id:
        volunteer_date = Volunteer_Date.objects.get(id=date_id)

        # localize the volunteer date times for emailing
        localized_start = localize(volunteer_date.event_begin)
        localized_end = localize(volunteer_date.event_end)

        # send emails to all registered volunteers
        for registration in volunteer_date.registrations.filter(cancelled=False):
            send_admin_date_deleted_email(registration.volunteer,
                                          localized_start,
                                          localized_end)

        # finally, delete volunteer_date object
        volunteer_date.delete()

        success = 'Successfully deleted volunteering date on ' \
                  '{0} from {1} to {2}'.format(localized_start.strftime('%A, %B %-d, %Y'),
                                               localized_start.strftime('%-I:%M %p'),
                                               localized_end.strftime('%-I:%M %p'))
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 4
0
def volunteer_date_cancellation(volunteer_id, date_id):
    success, error = ('',)*2
    if volunteer_id and date_id:
        volunteer_user = WIS_User.objects.get(id=volunteer_id)
        volunteer_date = Volunteer_Date.objects.get(id=date_id)
        volunteer_registration = Volunteer_Date_Registration.objects.get(volunteer_date=volunteer_date,
                                                                         volunteer=volunteer_user)

        if volunteer_date.is_past:
            error = 'You cannot cancel registration for a date that has already passed'
        elif volunteer_date.is_two_days_or_less_prior:
            error = 'You cannot cancel registration for a date less than 48 hours in advance'
        elif volunteer_registration.cancelled:
            error = 'You have already cancelled this registration'
        else:
            # set registration to cancelled
            volunteer_registration.cancelled = True
            volunteer_registration.cancel_time = datetime.datetime.utcnow()
            volunteer_registration.save()

            # localize the volunteer date times for displaying
            localized_start = localize(volunteer_date.event_begin)
            localized_end = localize(volunteer_date.event_end)

            # send confirmation email
            send_date_cancelled_email(volunteer_user, localized_start, localized_end)

            success = 'You have successfully cancelled your volunteering registration on ' \
                      '{0} from {1} to {2}'.format(localized_start.strftime('%A, %B %-d, %Y'),
                                                   localized_start.strftime('%-I:%M %p'),
                                                   localized_end.strftime('%-I:%M %p'))
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 5
0
def admin_remove_volunteer_from_date(registration_id):
    success, error = ('',)*2
    if registration_id:
        try:
            volunteer_registration = Volunteer_Date_Registration.objects.get(id=registration_id)
            volunteer_date = volunteer_registration.volunteer_date
            volunteer_user = volunteer_registration.volunteer

            # delete the registration object
            volunteer_registration.delete()

            # localize the volunteer date times for emailing
            localized_start = localize(volunteer_date.event_begin)
            localized_end = localize(volunteer_date.event_end)

            # send notification email
            send_admin_date_cancelled_email(volunteer_user, localized_start, localized_end)

            success = 'Successfully removed {0} {1} from volunteering date'.format(volunteer_user.first_name,
                                                                                   volunteer_user.last_name)
        except:
            error = 'Registration does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 6
0
def admin_delete_volunteering_date(date_id):
    success, error = ('',)*2
    if date_id:
        try:
            volunteer_date = Volunteer_Date.objects.get(id=date_id)

            # localize the volunteer date times for emailing
            localized_start = localize(volunteer_date.event_begin)
            localized_end = localize(volunteer_date.event_end)

            # remove registrations from volunteer objects
            for volunteer in volunteer_date.volunteers:
                for registration in volunteer.registrations:
                    if registration.volunteer_date.id == volunteer_date.id:
                        volunteer.registrations.remove(registration)
                        registration.delete()
                        # send notification email
                        send_admin_date_deleted_email(volunteer,
                                                      localized_start,
                                                      localized_end)
                volunteer.save()

            # finally, delete volunteer_date object
            volunteer_date.delete()

            success = 'Successfully deleted volunteering date on ' \
                      '{0} from {1} to {2}'.format(localized_start.strftime('%A, %B %-d, %Y'),
                                                   localized_start.strftime('%-I:%M %p'),
                                                   localized_end.strftime('%-I:%M %p'))
        except DoesNotExist:
            error = 'Volunteering date does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 7
0
def admin_remove_volunteer_from_date(registration_id):
    success, error = ('',)*2
    if registration_id:
        try:
            volunteer_registration = Volunteer_Date_Registration.objects.get(id=registration_id)
            volunteer_date = volunteer_registration.volunteer_date
            volunteer_user = volunteer_registration.volunteer

            # update the registration object
            volunteer_registration.cancelled = True
            volunteer_registration.cancel_time = datetime.datetime.utcnow()
            volunteer_registration.save()

            # remove registration from the volunteer's list
            volunteer_user.registrations.remove(volunteer_registration)
            volunteer_user.save()

            # remove volunteer from list of volunteers for the date
            volunteer_date.volunteers.remove(volunteer_user)
            volunteer_date.save()

            # localize the volunteer date times for emailing
            localized_start = localize(volunteer_date.event_begin)
            localized_end = localize(volunteer_date.event_end)

            # send notification email
            send_admin_date_cancelled_email(volunteer_user, localized_start, localized_end)

            success = 'Successfully removed {0} {1} from volunteering date'.format(volunteer_user.first_name,
                                                                                   volunteer_user.last_name)
        except DoesNotExist:
            error = 'Registration does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 8
0
    def handle(self, *args, **options):
        try:
            day_of_week = datetime.datetime.today().isoweekday()
            if day_of_week in EMAIL_REMINDER_DAYS:
                hours_from_now = options.get('hours_from_now')
                volunteer_dates = Volunteer_Date.objects.all()
                num_emails_sent = 0

                for volunteer_date in volunteer_dates:
                    # check if volunteer_date is in the future and within hours_from_now
                    if 0 < get_diff_from_now(volunteer_date.event_begin) < hours_from_now:
                        # localize the volunteer date times for emailing
                        localized_start = localize(volunteer_date.event_begin)
                        localized_end = localize(volunteer_date.event_end)

                        # calculate cutoff time for cancelling
                        cutoff_time = localized_start - datetime.timedelta(days=CANCELLATION_CUTOFF_DAYS)

                        # send volunteers reminder emails
                        for registration in volunteer_date.registrations.all():
                            if not registration.cancelled:                    
                                send_volunteer_reminder_email(registration.volunteer,
                                                            localized_start,
                                                            localized_end,
                                                            cutoff_time)
                                num_emails_sent+=1

                self.stdout.write('Successfully emailed %d volunteers with '
                                  'registrations %d hours from now' %
                                  (num_emails_sent, hours_from_now))
            else:
                self.stdout.write('Skipping email sends, current day %s is not in EMAIL_REMINDER_DAYS' % day_of_week)
        except Exception as e:
            raise CommandError('Error sending emails: %s' % e)
Exemplo n.º 9
0
def volunteer_date_register(volunteer_id, date_id):
    success, error = ('',)*2
    if volunteer_id and date_id:
        try:
            volunteer_user = WIS_User.objects.get(id=volunteer_id)
            volunteer_date = Volunteer_Date.objects.get(id=date_id)

            if volunteer_date.slots_available < 1:
                error = 'There are no slots available for that date'
            elif volunteer_date.is_past:
                error = 'You cannot signup for a date that has already passed'
            elif volunteer_date.is_two_days_or_less_prior:
                error = 'You cannot signup for a date less than 48 hours in advance'
            elif volunteer_user in volunteer_date.volunteers:
                error = 'You have already registered for this date'
            else:
                # create registration object
                registration = Volunteer_Date_Registration(volunteer_date=volunteer_date,
                                                           volunteer=volunteer_user)
                registration.save()

                # add registration to the volunteer's list
                volunteer_user.registrations.append(registration)
                volunteer_user.save()

                # add volunteer to list of volunteers for the date
                volunteer_date.volunteers.append(volunteer_user)
                volunteer_date.save()

                # localize the volunteer date times for displaying
                localized_start = localize(volunteer_date.event_begin)
                localized_end = localize(volunteer_date.event_end)

                # send confirmation email
                send_date_registered_email(volunteer_user, localized_start, localized_end)

                success = 'You have successfully signed up for volunteering on ' \
                          '{0} from {1} to {2}'.format(localized_start.strftime('%A, %B %-d, %Y'),
                                                       localized_start.strftime('%-I:%M %p'),
                                                       localized_end.strftime('%-I:%M %p'))
        except DoesNotExist:
            error = 'Selected date does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 10
0
def volunteer_date_cancellation(volunteer_id, date_id):
    success, error = ('',)*2
    if volunteer_id and date_id:
        try:
            volunteer_user = WIS_User.objects.get(id=volunteer_id)
            volunteer_date = Volunteer_Date.objects.get(id=date_id)

            if volunteer_date.is_past:
                error = 'You cannot cancel registration for a date that has already passed'
            elif volunteer_date.is_two_days_or_less_prior:
                error = 'You cannot cancel registration for a date less than 1 week in advance'
            elif volunteer_user not in volunteer_date.volunteers:
                error = 'You are not already registered for this event'
            else:
                # remove registration from the volunteer's list
                for registration in volunteer_user.registrations:
                    if registration.volunteer_date.id == volunteer_date.id:
                        volunteer_user.registrations.remove(registration)
                        # update the registration object
                        volunteer_registration = Volunteer_Date_Registration.objects.get(id=registration.id)
                        volunteer_registration.cancelled = True
                        volunteer_registration.cancel_time = datetime.datetime.utcnow()
                        volunteer_registration.save()
                volunteer_user.save()

                # remove volunteer from list of volunteers for the date
                volunteer_date.volunteers.remove(volunteer_user)
                volunteer_date.save()

                # localize the volunteer date times for displaying
                localized_start = localize(volunteer_date.event_begin)
                localized_end = localize(volunteer_date.event_end)

                # send confirmation email
                send_date_cancelled_email(volunteer_user, localized_start, localized_end)

                success = 'You have successfully cancelled your volunteering registration on ' \
                          '{0} from {1} to {2}'.format(localized_start.strftime('%A, %B %-d, %Y'),
                                                       localized_start.strftime('%-I:%M %p'),
                                                       localized_end.strftime('%-I:%M %p'))
        except DoesNotExist:
            error = 'Selected date does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)
Exemplo n.º 11
0
def volunteer_date_register(volunteer_id, date_id):
    success, error = ('',)*2
    if volunteer_id and date_id:
        try:
            volunteer_user = WIS_User.objects.get(id=volunteer_id)
            volunteer_date = Volunteer_Date.objects.get(id=date_id)

            if volunteer_date.slots_available < 1:
                error = 'There are no slots available for that date'
            elif volunteer_date.is_past:
                error = 'You cannot signup for a date that has already passed'
            elif volunteer_date.check_if_user_registered(volunteer_user):
                error = 'You have already registered for this date'
            else:
                # create registration object
                registration = Volunteer_Date_Registration(volunteer_date=volunteer_date,
                                                           volunteer=volunteer_user)
                registration.save()

                # localize the volunteer date times for displaying
                localized_start = localize(volunteer_date.event_begin)
                localized_end = localize(volunteer_date.event_end)

                # calculate cutoff time for cancelling
                cutoff_time = localized_start - datetime.timedelta(days=CANCELLATION_CUTOFF_DAYS)

                # send confirmation email
                send_date_registered_email(volunteer_user, localized_start, localized_end, cutoff_time)

                success = 'You have successfully signed up for volunteering on ' \
                          '{0} from {1} to {2}'.format(localized_start.strftime('%A, %B %-d, %Y'),
                                                       localized_start.strftime('%-I:%M %p'),
                                                       localized_end.strftime('%-I:%M %p'))
        except:
            error = 'Selected date does not exist'
    else:
        error = 'Incomplete form data'
    return (success, error,)