Exemplo n.º 1
0
 def get_context_data(self, **kwargs):
     """ Get a list of all other participants who've requested pairing. """
     context = super().get_context_data(**kwargs)
     self.participant = self.request.participant
     context['pair_requests'] = self.pair_requests
     context['is_winter_school'] = is_winter_school()
     return context
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     """ Get a list of all other participants who've requested pairing. """
     context = super().get_context_data(**kwargs)
     self.participant = self.request.participant
     context['pair_requests'] = self.pair_requests
     context['is_winter_school'] = is_winter_school()
     return context
Exemplo n.º 3
0
 def test_is_winter_school(self, local_now):
     for day, expected in [(datetime(2016, 12, 28), False),
                           (datetime(2017,  1,  1), True),
                           (datetime(2017,  1, 14), True),
                           (datetime(2017,  1, 31), True),
                           (datetime(2017,  2, 10), False)]:
         local_now.return_value = day
         self.assertEqual(date_utils.is_winter_school(), expected)
Exemplo n.º 4
0
    def supply_all_messages(self):
        if not self.request.participant or not dateutils.is_winter_school():
            return
        self.warn_if_missing_lottery()
        self.warn_if_car_missing()

        if self.lotteryinfo:  # (warnings are redundant if no lottery info)
            self.warn_if_no_ranked_trips()
            self.warn_if_dated_info()
Exemplo n.º 5
0
    def supply_all_messages(self):
        if not self.request.participant or not is_winter_school():
            return
        self.warn_if_missing_lottery()
        self.warn_if_car_missing()

        if self.lotteryinfo:  # (warnings are redundant if no lottery info)
            self.warn_if_no_ranked_trips()
            self.warn_if_dated_info()
Exemplo n.º 6
0
 def get_context_data(self, **kwargs):
     self.participant = self.request.participant
     return {
         'is_winter_school': is_winter_school(),
         'ranked_signups': json.dumps(self.ranked_signups_dict),
         'car_form': self.get_car_form(use_post=True),
         'lottery_form': self.get_lottery_form(),
         'reciprocally_paired': self.reciprocally_paired,
         'paired_par': self.paired_par
     }
Exemplo n.º 7
0
 def get_context_data(self, **kwargs):
     self.participant = self.request.participant
     return {
         'is_winter_school': is_winter_school(),
         'ranked_signups': json.dumps(self.ranked_signups_dict),
         'car_form': self.get_car_form(use_post=True),
         'lottery_form': self.get_lottery_form(),
         'reciprocally_paired': self.reciprocally_paired,
         'paired_par': self.paired_par,
     }
Exemplo n.º 8
0
    def can_set_attendance(self, participant):
        # WS chairs can set any time for any user
        if perm_utils.is_chair(self.request.user, 'winter_school', True):
            return True

        # Non-chairs are only allowed during WS when setting enabled
        if not is_winter_school():
            return False
        settings = models.WinterSchoolSettings.load()
        if not settings.allow_setting_attendance:
            return False

        # Non-chairs may only set attendance for themselves
        return participant == self.request.participant
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    def can_set_attendance(self, participant):
        # WS chairs can set any time for any user
        if perm_utils.is_chair(self.request.user, 'winter_school', True):
            return True

        # Non-chairs are only allowed during WS when setting enabled
        if not is_winter_school():
            return False
        settings = models.WinterSchoolSettings.load()
        if not settings.allow_setting_attendance:
            return False

        # Non-chairs may only set attendance for themselves
        return participant == self.request.participant
Exemplo n.º 11
0
    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['initial'] = kwargs.get('initial', {})
        if not self.request.user.is_superuser:
            allowed_activities = self.request.participant.allowed_activities
            kwargs['allowed_activities'] = allowed_activities

            if is_winter_school() and 'winter_school' in allowed_activities:
                kwargs['initial']['activity'] = 'winter_school'
            else:
                # The first activity may not be open to the leader.
                # We restrict choices, so ensure leader can lead this activity.
                kwargs['initial']['activity'] = kwargs['allowed_activities'][0]
        return kwargs