def _lecture_info(self, participant, user_viewing: bool) -> Dict[str, bool]: """Describe the participant's lecture attendance, if applicable.""" can_set_attendance = self.can_set_attendance(participant) # There are only *two* times of year where it's important to show "yes, you attended" # 1. The enrollment period where participants can record attendance (2nd lecture) # 2. The first week of WS, after lectures but before weekend trips # (this is when participants may not have recorded attendance correctly) # In later weeks, we'll enforce lecture attendance as part of trip signup. show_attendance = date_utils.is_currently_iap() and ( can_set_attendance or date_utils.ws_lectures_complete() ) if show_attendance: attended_lectures = participant.attended_lectures(date_utils.ws_year()) # We don't need to tell participants "You attended lectures!" later in WS. # This is because signup rules enforce lecture attendance *after* week 1. if user_viewing and models.Trip.objects.filter( program=enums.Program.WINTER_SCHOOL.value, trip_date__gte=date_utils.jan_1(), trip_date__lt=date_utils.local_date(), ): show_attendance = False else: # Skip unnecessary db queries attended_lectures = False # Maybe they actually did, but we're not showing. return { 'can_set_attendance': can_set_attendance, 'show_attendance': show_attendance, 'attended_lectures': attended_lectures, }
def missed_lectures(participant, year): """ Whether the participant missed WS lectures in the given year. """ if year < 2016: return False # We lack records for 2014 & 2015; assume present if year == dateutils.ws_year() and not ws_lectures_complete(): return False # Lectures aren't over yet, so nobody "missed" lectures return not participant.lectureattendance_set.filter(year=year).exists()
def missed_lectures(participant, year): """ Whether the participant missed WS lectures in the given year. """ if year < 2016: # We lack records for 2014 & 2015; assume present return False absent = not participant.lectureattendance_set.filter(year=year).exists() # If this year's lectures haven't happened yet, don't consider to have missed if year == dateutils.ws_year(): return ws_lectures_complete() and absent else: return absent
def get_context_data(self, **kwargs): participant = self.object = self.get_object() user_viewing = self.request.participant == participant context = super().get_context_data(**kwargs) can_set_attendance = self.can_set_attendance(participant) context['can_set_attendance'] = can_set_attendance context['show_attendance'] = (is_winter_school() and (ws_lectures_complete() or can_set_attendance)) if can_set_attendance: context[ 'attended_lectures'] = models.LectureAttendance.objects.filter( participant=participant, year=ws_year()).exists() context['user_viewing'] = user_viewing if user_viewing: user = self.request.user else: user = participant.user context['par_user'] = user context['trips'] = trips = self.get_trips() context['stats'] = self.get_stats(trips) self.include_pairing(context) e_info = participant.emergency_info e_contact = e_info.emergency_contact context['emergency_info_form'] = forms.EmergencyInfoForm( instance=e_info) context['emergency_contact_form'] = forms.EmergencyContactForm( instance=e_contact) context['participant'] = participant if not user_viewing: feedback = participant.feedback_set.select_related( 'trip', 'leader') feedback = feedback.prefetch_related('leader__leaderrating_set') context['all_feedback'] = feedback context['ratings'] = participant.ratings(rating_active=True) chair_activities = set(perm_utils.chair_activities(user)) context['chair_activities'] = [ label for (activity, label) in models.LeaderRating.ACTIVITY_CHOICES if activity in chair_activities ] if participant.car: context['car_form'] = forms.CarForm(instance=participant.car) return context
def form_valid(self, form): participant = form.cleaned_data['participant'] if not self.can_set_attendance(participant): return self.form_invalid(form) attended, _ = models.LectureAttendance.objects.get_or_create( participant=participant, year=ws_year(), creator=self.request.participant ) attended.save() # Notifications aren't shown when viewing other participants if participant == self.request.participant: messages.success(self.request, "Marked as having attended lectures!") return redirect(reverse('view_participant', args=(participant.pk,)))
def form_valid(self, form): participant = form.cleaned_data['participant'] if not self.can_set_attendance(participant): return self.form_invalid(form) attended, _ = models.LectureAttendance.objects.get_or_create( participant=participant, year=ws_year(), creator=self.request.participant ) attended.save() # Notifications aren't shown when viewing other participants if participant == self.request.participant: messages.success(self.request, "Marked as having attended lectures!") return redirect(reverse('view_participant', args=(participant.pk,)))
def get_context_data(self, **kwargs): participant = self.object = self.get_object() user_viewing = self.request.participant == participant context = super().get_context_data(**kwargs) can_set_attendance = self.can_set_attendance(participant) context['can_set_attendance'] = can_set_attendance context['show_attendance'] = date_utils.is_currently_iap() and ( date_utils.ws_lectures_complete() or can_set_attendance) if can_set_attendance: context[ 'attended_lectures'] = models.LectureAttendance.objects.filter( participant=participant, year=date_utils.ws_year()).exists() context['user_viewing'] = user_viewing if user_viewing: user = self.request.user else: user = participant.user context['par_user'] = user context['trips'] = trips = self.get_trips() context['stats'] = self.get_stats(trips) self.include_pairing(context) e_info = participant.emergency_info e_contact = e_info.emergency_contact context['emergency_info_form'] = forms.EmergencyInfoForm( instance=e_info) context['emergency_contact_form'] = forms.EmergencyContactForm( instance=e_contact) context['participant'] = participant if not user_viewing: feedback = participant.feedback_set.select_related( 'trip', 'leader') feedback = feedback.prefetch_related('leader__leaderrating_set') context['all_feedback'] = feedback context['ratings'] = participant.ratings(must_be_active=True) if participant.car: context['car_form'] = forms.CarForm(instance=participant.car) context['wimp'] = self.wimp return context
def lecture_attendance(participant, user_viewing, can_set_attendance=False): """ Show the participant's record for Winter School lecture attendance. If allowed, let the user change said participant's attendance. Cases where we allow this: - The activity chair marks them manually as having attended - The user marks themselves during the allowed window """ attendance = participant.lectureattendance_set this_year = ws_year() form = AttendedLecturesForm(initial={'participant': participant}) form.fields['participant'].widget = HiddenInput() # Will be checked by view return {'form': form, 'participant': participant, 'user_viewing': user_viewing, 'attended_lectures': attendance.filter(year=this_year).exists(), 'past_attendance': attendance.exclude(year=this_year), 'can_set_attendance': can_set_attendance}
def lecture_attendance(participant, user_viewing, can_set_attendance=False): """ Show the participant's record for Winter School lecture attendance. If allowed, let the user change said participant's attendance. Cases where we allow this: - The activity chair marks them manually as having attended - The user marks themselves during the allowed window """ attendance = participant.lectureattendance_set this_year = ws_year() form = AttendedLecturesForm(initial={'participant': participant}) form.fields['participant'].widget = HiddenInput() # Will be checked by view return { 'form': form, 'participant': participant, 'user_viewing': user_viewing, 'attended_lectures': attendance.filter(year=this_year).exists(), 'past_attendance': attendance.exclude(year=this_year), 'can_set_attendance': can_set_attendance, }
def application_year(self): if self.activity == 'winter_school': return ws_year() else: return local_date().year
def application_year(self): if self.activity == LeaderRating.WINTER_SCHOOL: return dateutils.ws_year() else: return dateutils.local_date().year
def application_year(self): if self.activity == 'winter_school': return ws_year() return local_date().year