def get(self, request, *args, **kwargs): year = kwargs.get('year') semester = kwargs.get('semester') year, semester = parse_year_semester(year, semester) prev_semester = delta_semester(semester=semester, year=year, delta=-1, as_dict=True) next_semester = delta_semester(semester=semester, year=year, delta=1, as_dict=True) collect_dues = dues_required(semester=semester, year=year) person = request.user.person if not person.is_active(semester=next_semester['semester'], year=next_semester['year']): next_semester = None if not person.is_active(semester=prev_semester['semester'], year=prev_semester['year']): prev_semester = None person.cached_status = { 'tours_status': person.tours_status(year=year, semester=semester), 'shifts_status': person.shifts_status(year=year, semester=semester), 'dues_status': person.dues_status(year=year, semester=semester), } # determine status tours_status = person.cached_status['tours_status']['status'] shifts_status = person.cached_status['shifts_status']['status'] dues_status = person.cached_status['dues_status'] statuses = (tours_status, shifts_status, dues_status) if tours_status == 'incomplete' or shifts_status == 'incomplete' or dues_status == 'incomplete': status = 'incomplete' elif all([x in ('complete', 'projected', 'not_required') for x in statuses]) and any([x == 'projected' for x in statuses]): status = 'projected' else: status = 'complete' status_names = { 'incomplete': 'Requirements Incomplete', 'projected': 'Projected to Complete', 'complete': 'Requirements Complete', } context = { 'person': person, 'status_class': status, 'status': status_names[status], 'tours': person.tours.semester(year=year, semester=semester).order_by('time'), 'shifts': person.shifts.semester(year=year, semester=semester).order_by('time'), 'next_semester': next_semester, 'prev_semester': prev_semester, 'collect_dues': collect_dues, } return render(request, 'public/profile.html', context)
def get(self, request, *args, **kwargs): year = kwargs.get('year') semester = kwargs.get('semester') year, semester = parse_year_semester(year=year, semester=semester) prev_semester = delta_semester(semester=semester, year=year, delta=-1, as_dict=True) next_semester = delta_semester(semester=semester, year=year, delta=1, as_dict=True) collect_dues = dues_required(semester=semester, year=year) people = self.get_people(semester=semester, year=year) is_current_semester = semester == current_semester() and year == now().year # cache requirements status results so that we don't have to keep hitting the db for person in people: dues_status = person.dues_status(semester=semester, year=year) person.cached_status = { 'tours_status': person.tours_status(semester=semester, year=year), 'shifts_status': person.shifts_status(semester=semester, year=year), 'dues_status': dues_status, 'active': person.is_active(semester=semester, year=year) } # dues payments if collect_dues: paid = dues_status == 'complete' person.dues_payment_form = DuesPaymentForm(initial={'pk': person.pk, 'paid': paid}, prefix='pk_{}'.format(person.pk)) context = { 'semester': semester, 'year': year, 'people': people, 'prev_semester': prev_semester, 'next_semester': next_semester, 'collect_dues': collect_dues, 'is_current_semester': is_current_semester, } return render(request, 'profiles/roster.html', context)
def get(self, request, *args, **kwargs): year = kwargs.get('year') semester = kwargs.get('semester') year, semester = parse_year_semester(year, semester) prev_semester = delta_semester(semester=semester, year=year, delta=-1, as_dict=True) next_semester = delta_semester(semester=semester, year=year, delta=1, as_dict=True) collect_dues = dues_required(semester=semester, year=year) person = request.user.person if not person.is_active(semester=next_semester['semester'], year=next_semester['year']): next_semester = None if not person.is_active(semester=prev_semester['semester'], year=prev_semester['year']): prev_semester = None person.cached_status = { 'tours_status': person.tours_status(year=year, semester=semester), 'shifts_status': person.shifts_status(year=year, semester=semester), 'dues_status': person.dues_status(year=year, semester=semester), } # determine status tours_status = person.cached_status['tours_status']['status'] shifts_status = person.cached_status['shifts_status']['status'] dues_status = person.cached_status['dues_status'] statuses = (tours_status, shifts_status, dues_status) if tours_status == 'incomplete' or shifts_status == 'incomplete' or dues_status == 'incomplete': status = 'incomplete' elif all( [x in ('complete', 'projected', 'not_required') for x in statuses]) and any([x == 'projected' for x in statuses]): status = 'projected' else: status = 'complete' status_names = { 'incomplete': 'Requirements Incomplete', 'projected': 'Projected to Complete', 'complete': 'Requirements Complete', } context = { 'person': person, 'status_class': status, 'status': status_names[status], 'tours': person.tours.semester(year=year, semester=semester).order_by('time'), 'shifts': person.shifts.semester(year=year, semester=semester).order_by('time'), 'next_semester': next_semester, 'prev_semester': prev_semester, 'collect_dues': collect_dues, } return render(request, 'public/profile.html', context)