Beispiel #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)
def label_row(event_type, committee_name=None):
    """ Returns the first row of the section of the attendance csv for event_type. This simply contains the label for
    the row, either the event_type's human readable name or the committee's name

    :param Event Class event_type:
        The Event Class whose events should appear on the csv

    :param str committee_name:
        An optional parameter that is passed in when CommitteeMeetingEvent is passed in. The name of the committee
        whose title should appear on the csv

    :returns:
        the row to be printed
    :rtype: [str]

    """
    row = ['', get_human_readable_model_name(event_type.objects.all()[0])]
    if (event_type is CommitteeMeetingEvent) and (committee_name is not None):
        row = [
            '',
            Committee.objects.get(
                committee=committee_name).get_committee_display() +
            ' Committee'
        ]
    return row
Beispiel #3
0
def brother_hs_event(request, event_id, view):
    """ Renders the brother page for health and safety event with a excuse form """
    if not request.user.is_authenticated:  # brother auth check
        messages.error(
            request,
            "Brother not logged in before viewing brother Health and Safety events"
        )
        return HttpResponseRedirect(reverse('dashboard:home'))

    brother = request.user.brother
    # get the excuses the brother has submitted for this event
    excuse = Excuse.objects.filter(event=event_id, brother=brother)

    event = HealthAndSafetyEvent.objects.get(pk=event_id)

    form = ExcuseForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            instance = form.save(commit=False)
            instance.brother = brother
            instance.event = event
            instance.save()
            return HttpResponseRedirect(reverse('dashboard:brother'))

    context = {
        'type': view,
        'event': event,
        'form': form,
        'excuse_exists': excuse.exists(),
        'brother': brother,
        'attended': event.attendees_brothers.filter(pk=brother.pk).exists(),
        'button': 'Submit Excuse',
        'event_type': get_human_readable_model_name(event)
    }

    # if an excuse has been submitted, add the excuse to the context
    if excuse.exists():
        context.update({
            'excuse': excuse[0],
        })
    elif not excuse.exists():
        context.update({'button_name': 'excuse'})

    return render(request, "events/base-event.html", context)
Beispiel #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)