Ejemplo n.º 1
0
def health_and_safety_event(request, event_id):
    """ Renders the vphs way of view events """
    event = HealthAndSafetyEvent.objects.get(pk=event_id)
    brothers, brother_form_list = attendance_list(request, event)

    form = EditBrotherAttendanceForm(request.POST or None, event=event_id)

    if request.method == 'POST':
        if "update" in request.POST:
            if forms_is_valid(brother_form_list):
                mark_attendance_list(brother_form_list, brothers, event)
        if "edit" in request.POST:
            if form.is_valid():
                instance = form.clean()
                update_eligible_brothers(instance, event)
        return redirect(request.path_info, kwargs={'event_id': event_id})

    context = {
        'type': 'attendance',
        'brother_form_list': brother_form_list,
        'event': event,
        'form': form,
        'event_type': get_human_readable_model_name(event),
    }
    return render(request, "events/base-event.html", context)
Ejemplo n.º 2
0
def committee_event(request, event_id):
    event = CommitteeMeetingEvent.objects.get(pk=event_id)

    brothers = event.eligible_attendees.order_by('last_name', 'first_name')
    brother_form_list, pnm_form_list = attendance_list(request, event, brothers, None)

    current_brother = request.user.brother
    if current_brother in event.committee.chair.brothers.all():
        view_type = 'chairman'
    else:
        view_type = 'brother'

    form = EditBrotherAttendanceForm(request.POST or None, event=event_id)

    if request.method == 'POST':
        if "update" in request.POST:
            if forms_is_valid(brother_form_list):
                mark_attendance_list(brother_form_list, brothers, event)
        if "edit" in request.POST:
            if form.is_valid():
                instance = form.clean()
                update_eligible_brothers(instance, event)
        return redirect(request.path_info, kwargs={'event_id': event_id})

    context = {
        'type': view_type,
        'brother_form_list': brother_form_list,
        'event': event,
        'form': form,
        'position': Position.objects.get(title=event.slug),
    }

    return render(request, "committee-event.html", context)
def scholarship_c_gpa(request):
    """Renders Scholarship Gpa update page for the Scholarship Chair"""
    plans = ScholarshipReport.objects.filter(
        semester=get_semester()).order_by("brother__last_name")
    form_list = []

    for plan in plans:
        new_form = GPAForm(request.POST or None,
                           initial={
                               'cum_GPA': plan.cumulative_gpa,
                               'past_GPA': plan.past_semester_gpa
                           },
                           prefix=plan.id)
        form_list.append(new_form)

    form_plans = zip(form_list, plans)

    if request.method == 'POST':
        if forms_is_valid(form_list):
            for counter, form in enumerate(form_list):
                instance = form.clean()
                plan = plans[counter]
                plan.cumulative_gpa = instance['cum_GPA']
                plan.past_semester_gpa = instance['past_GPA']
                plan.save()
            return HttpResponseRedirect(reverse('dashboard:scholarship_c'))

    context = {
        'form_plans': form_plans,
    }

    return render(request, 'scholarship-chair/scholarship-gpa.html', context)
Ejemplo n.º 4
0
def event_view(request, position_slug, event_id):
    """ Renders the attendance sheet for any event """
    event_type = event_type_from_position(position_slug)
    event = event_type.objects.get(pk=event_id)
    brothers = event.eligible_attendees.order_by('last_name', 'first_name')
    pnms = None
    if position_slug == 'recruitment-chair':
        pnms = PotentialNewMember.objects.all().order_by(
            'last_name', 'first_name')
    brother_form_list, pnm_form_list = attendance_list(request, event,
                                                       brothers, pnms)

    form = EditBrotherAttendanceForm(request.POST or None, event=event_id)

    if request.method == 'POST':
        if "update" in request.POST:
            if forms_is_valid(brother_form_list):
                mark_attendance_list(brother_form_list, brothers, event)
        if "updatepnm" in request.POST:
            if forms_is_valid(pnm_form_list):
                mark_attendance_list(pnm_form_list, pnms, event)
        if "edit" in request.POST:
            if form.is_valid():
                instance = form.clean()
                update_eligible_brothers(instance, event)
        return redirect(request.path_info, kwargs={'event_id': event_id})

    context = {
        'type': 'attendance',
        'pnm_form_list': pnm_form_list,
        'brother_form_list': brother_form_list,
        'event': event,
        'media_root': settings.MEDIA_ROOT,
        'media_url': settings.MEDIA_URL,
        'form': form,
        'event_type': get_human_readable_model_name(event),
        'position': Position.objects.get(title=position_slug),
    }
    return render(request, "events/base-event.html", context)
Ejemplo n.º 5
0
def marshal(request):
    """ Renders the marshal page listing all the candidates and relevant information to them """
    candidates = Brother.objects.filter(brother_status='0').order_by(
        'last_name', 'first_name')
    events = ChapterEvent.objects.filter(semester=get_semester()).exclude(
        date__gt=datetime.date.today())
    excuses = Excuse.objects.filter(event__semester=get_semester(), status='1')
    events_excused_list = []
    events_unexcused_list = []
    randomized_list = request.session.pop('randomized_list', None)

    mab_form_list = []

    for counter, candidate in enumerate(candidates):
        assigned_mab = MeetABrother.objects.filter(
            candidate=candidate).values_list('brother', flat=True)
        eligible_brothers = Brother.objects.filter(brother_status=1).exclude(
            pk__in=assigned_mab).order_by('last_name', 'first_name')
        form = MeetABrotherForm(request.POST or None,
                                prefix=counter + 1,
                                candidate=candidate.first_name + ' ' +
                                candidate.last_name)
        mab_form_list.append(form)
        if randomized_list is not None or []:
            form.fields['assigned_brother1'].initial = randomized_list[
                counter][0]
            form.fields['assigned_brother2'].initial = randomized_list[
                counter][1]
            form.fields['randomize'].initial = randomized_list[counter][2]
        else:
            form.fields['randomize'].initial = True
        form.fields['assigned_brother1'].queryset = eligible_brothers
        form.fields['assigned_brother2'].queryset = eligible_brothers

    for candidate in candidates:
        events_excused = 0
        events_unexcused = 0
        if candidate.date_pledged:
            expected_events = events.exclude(
                date_pledged__lt=datetime.date.today())
        else:
            expected_events = events
        for event in expected_events:
            if not event.attendees_brothers.filter(id=candidate.id).exists():
                if excuses.filter(brother=candidate, event=event).exists():
                    events_excused += 1
                else:
                    events_unexcused += 1
        events_excused_list.append(events_excused)
        events_unexcused_list.append(events_unexcused)

    candidate_attendance = zip(candidates, events_excused_list,
                               events_unexcused_list)

    if request.method == 'POST':
        if 'submit' in request.POST:
            if forms_is_valid(mab_form_list):
                for counter, form in enumerate(mab_form_list):
                    instance = form.clean()
                    if instance['assigned_brother1']:
                        mab1 = MeetABrother(
                            candidate=candidates[counter],
                            brother=instance['assigned_brother1'])
                        mab1.save()
                    if instance['assigned_brother2']:
                        mab2 = MeetABrother(
                            candidate=candidates[counter],
                            brother=instance['assigned_brother2'])
                        mab2.save()
                return HttpResponseRedirect(
                    reverse('dashboard:meet_a_brother'))
        if 'randomize' in request.POST:
            if forms_is_valid(mab_form_list):
                randomized_list = []
                random1 = []
                random2 = []
                for form in mab_form_list:
                    instance = form.clean()
                    if instance['randomize']:
                        queryset1 = form.fields['assigned_brother1'].queryset
                        queryset2 = queryset1
                        if queryset1.exists():
                            random1 = random.choices(queryset1, k=1)[0].pk
                            queryset2 = queryset1.exclude(pk=random1)
                        if queryset2.exists():
                            random2 = random.choices(queryset2, k=1)[0].pk
                        randomized_list.append((random1, random2, True))
                    else:
                        if instance['assigned_brother1']:
                            random1 = instance['assigned_brother1'].pk
                        else:
                            random1 = []
                        if instance['assigned_brother2']:
                            random2 = instance['assigned_brother2'].pk
                        else:
                            random2 = []
                        randomized_list.append(
                            (random1, random2, instance['randomize']))
                request.session['randomized_list'] = randomized_list
                return HttpResponseRedirect(reverse('dashboard:marshal'))

    context = {
        'candidates': candidates,
        'candidate_attendance': candidate_attendance,
        'mab_form_list': mab_form_list,
        'position':
        Position.objects.get(title=Position.PositionChoices.MARSHAL)
    }
    return render(request, 'marshal/marshal.html', context)
Ejemplo n.º 6
0
def marshal_mab_edit(request):
    candidate = Brother.objects.get(pk=request.session.get('candidate', None))
    check_all = request.session.pop('check_all', False)

    mab_form_list = []

    brothers = Brother.objects.filter(brother_status='1').order_by(
        'last_name', 'first_name')

    arbitrary_date_before_time = datetime.datetime(1000, 1, 1)

    for counter, brother in enumerate(brothers):
        form = MeetABrotherEditForm(request.POST or None,
                                    prefix=counter + 1,
                                    brother=brother.pk,
                                    mab_exists=MeetABrother.objects.filter(
                                        brother=brother,
                                        candidate=candidate).exists())
        if check_all:
            form.fields['update'].initial = True
        mab_form_list.append(form)

    if request.method == 'POST':
        if 'submit' in request.POST:
            if forms_is_valid(mab_form_list):
                for counter, form in enumerate(mab_form_list):
                    instance = form.clean()
                    if instance[
                            'update'] is True:  #the user checked yes on this pairing of meet a brother, meaning we need to create a new one if it doesn't yet exist
                        mab, created = MeetABrother.objects.get_or_create(
                            candidate=candidate,
                            brother=brothers[counter],
                            defaults={
                                'completed': True,
                                'week': arbitrary_date_before_time
                            })
                        if created:  #if a new meet a brother is created we need to save it
                            mab.save()
                    elif instance[
                            'update'] is False:  #the user has not checked yes on this pairing of meet a brother
                        # we need to delete this meet a brother if it exists
                        try:  #get the meet a brother and delete it if it finds it
                            MeetABrother.objects.get(
                                candidate=candidate,
                                brother=brothers[counter]).delete()
                        except MeetABrother.DoesNotExist:  #get will return this exception if it doesn't find one so just continue if it's not found
                            continue
                    else:
                        pass  # instance['update'] is null
                request.session.pop('candidate', None)
                return HttpResponseRedirect(reverse('dashboard:marshal'))
        if 'check_all' in request.POST:
            request.session['check_all'] = True
            return HttpResponseRedirect(reverse('dashboard:marshal_mab_edit'))
        if 'go_back' in request.POST:
            return HttpResponseRedirect(
                reverse('dashboard:marshal_mab_edit_candidate'))

    context = {
        'candidate': candidate,
        'mab_form_list': mab_form_list,
    }

    return render(request, 'marshal/mab-edit.html', context)
Ejemplo n.º 7
0
def vice_president_committee_assignments(request):
    """Renders Committee assignment update page for the Vice President"""
    form_list = []
    brothers = Brother.objects.exclude(brother_status='2').order_by(
        'last_name', 'first_name')
    for brother in brothers:
        new_form = CommitteeForm(request.POST or None,
                                 initial={
                                     'standing_committees':
                                     get_standing_committees(brother),
                                     'operational_committees':
                                     get_operational_committees(brother)
                                 },
                                 prefix=brother.id)
        form_list.append(new_form)

    brother_forms = zip(brothers, form_list)

    if request.method == 'POST':
        if forms_is_valid(form_list):
            meeting_map = {}
            for counter, form in enumerate(form_list):
                instance = form.clean()
                # since the form was created in the same order that the brothers are ordered in you can just use
                # counter to get the brother associated with the form
                brother = brothers[counter]
                # all the committees the brother was a part of before new committees were assigned
                brother_committees = get_standing_committees(
                    brother) + get_operational_committees(brother)
                # unassigns the brother from all of their committees
                brother.committee_set.clear()
                # list of the committees the brother was now assigned to as strings representing the committees
                chosen_committees = instance['standing_committees'] + instance[
                    'operational_committees']
                # all committee options
                committee_choices = [
                    x for x, y in form.fields['standing_committees'].choices
                ] + [
                    x for x, y in form.fields['operational_committees'].choices
                ]
                for committee in committee_choices:
                    # if the committee is one that the brother has been assigned to
                    if committee in chosen_committees:
                        # adds the brother to the committee's member list again
                        committee_object = Committee.objects.get(
                            committee=committee)
                        committee_object.members.add(brother)
                        committee_object.save()
                        # if the brother was not previously a part of the committee
                        if committee not in brother_committees:
                            # iterates through all of the committee meetings after now
                            for meeting in committee_object.meetings.exclude(
                                    date__lte=datetime.datetime.now(),
                                    eligible_attendees=brother):
                                # if the meeting hasn't been previously added to the committee_map, adds it
                                # adds brother: true to the dictionary associated with this meeting
                                if meeting not in meeting_map:
                                    meeting_map[meeting] = {brother: True}
                                # if the meeting has been added, add the brother to the dictionary
                                else:
                                    meeting_map[meeting][brother] = True
                    # if the brother wasn't added to this committee
                    else:
                        # if the the brother was previously part of this commitee
                        if committee in brother_committees:
                            # iterate through all of the committee meetings after now
                            for meeting in Committee.objects.get(
                                    committee=committee).meetings.filter(
                                        date__gt=datetime.datetime.now(),
                                        eligible_attendees=brother):
                                # if the meeting hasn't been previously added to the committee_map, adds it
                                # adds brother: false to the dictionary associated with this meeting
                                if meeting not in meeting_map:
                                    meeting_map[meeting] = {brother: False}
                                else:
                                    meeting_map[meeting][brother] = False
            # for every meeting in the mapping, add the brothers associated with that meeting to the
            # eligible attendees list if true is assigned to the brother, and removes it if false
            for meeting, brother_map in meeting_map.items():
                add_list = [
                    brother_face for brother_face, boo in brother_map.items()
                    if boo is True
                ]
                remove_list = [
                    brother_face for brother_face, boo in brother_map.items()
                    if boo is False
                ]
                meeting.eligible_attendees.add(*add_list)
                meeting.eligible_attendees.remove(*remove_list)
                meeting.attendees_brothers.remove(*remove_list)
                meeting.save()
            return HttpResponseRedirect(reverse('dashboard:committee_list'))
    context = {
        'brother_forms': brother_forms,
    }

    return render(request, 'committee-assignment.html', context)