<reponame>beta-nu-theta-chi/ox-dashboard<filename>dashboard/views/_brother/_pnm.py<gh_stars>0
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse

from dashboard.models import PotentialNewMember, RecruitmentEvent
from dashboard.utils import get_season


def brother_pnm(request, pnm_id):
    """ Renders the pnm page for brothers """
    if not request.user.is_authenticated:  # brother auth check
        messages.error(request, "Please log in to view pnms")
        return HttpResponseRedirect(reverse('dashboard:home'))

    pnm = PotentialNewMember.objects.get(pk=pnm_id)
    events = RecruitmentEvent.objects.filter(semester=get_season()).order_by("date")

    attended_events = []
    for event in events:
        if event.attendees_pnms.filter(id=pnm_id).exists():
            attended_events.append(event)

    context = {
        'type': 'brother-view',
        'pnm': pnm,
        'events': attended_events,
    }
    return render(request, 'potential-new-member.html', context)

from django.contrib import messages
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse

from dashboard.models import PotentialNewMember, RecruitmentEvent
from dashboard.utils import get_season


def brother_pnm(request, pnm_id):
    """ Renders the pnm page for brothers """
    if not request.user.is_authenticated:  # brother auth check
        messages.error(request, "Please log in to view pnms")
        return HttpResponseRedirect(reverse('dashboard:home'))

    pnm = PotentialNewMember.objects.get(pk=pnm_id)
    events = RecruitmentEvent.objects.filter(semester=get_season()).order_by("date")

    attended_events = []
    for event in events:
        if event.attendees_pnms.filter(id=pnm_id).exists():
            attended_events.append(event)

    context = {
        'type': 'brother-view',
        'pnm': pnm,
        'events': attended_events,
    }
    return render(request, 'potential-new-member.html', context)
Renders the pnm page for brothers # brother auth check