Ejemplo n.º 1
0
    def test_chair_activities(self):
        """ The admin qualifies as a chair when allow_superusers is set. """
        # This admin is not a chair in the normal context
        self.assertFalse(
            perm_utils.chair_activities(self.admin, allow_superusers=False))
        self.assertFalse(perm_utils.chair_activities(self.admin))

        admin_allowed_activities = perm_utils.chair_activities(
            self.admin, allow_superusers=True)

        # Considered the chair for closed activities
        self.assertCountEqual(admin_allowed_activities, enums.Activity)
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        # Super calls DetailView's `get_context_data` so we'll manually add form
        context = super().get_context_data(**kwargs)
        assigned_rating = self.assigned_rating
        context['assigned_rating'] = assigned_rating
        context['recommendations'] = self.get_recommendations(assigned_rating)
        context['leader_form'] = self.get_form()
        context['all_feedback'] = self.get_feedback()
        context['prev_app'], context['next_app'] = self.get_other_apps()

        participant = self.object.participant
        context['active_ratings'] = list(participant.ratings(rating_active=True))
        participant_chair_activities = set(
            perm_utils.chair_activities(participant.user)
        )
        context['chair_activities'] = [
            label
            for (activity, label) in models.LeaderRating.ACTIVITY_CHOICES
            if activity in participant_chair_activities
        ]
        context['existing_rating'] = self.existing_rating
        context['existing_rec'] = self.existing_rec
        context['hide_recs'] = not (assigned_rating or context['existing_rec'])

        all_trips_led = self.object.participant.trips_led
        trips_led = all_trips_led.filter(self.before_rating, activity=self.activity)
        context['trips_led'] = trips_led.prefetch_related('leaders__leaderrating_set')
        return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        # Super calls DetailView's `get_context_data` so we'll manually add form
        context = super().get_context_data(**kwargs)
        assigned_rating = self.assigned_rating
        context['assigned_rating'] = assigned_rating
        context['recommendations'] = self.get_recommendations()
        context['leader_form'] = self.get_form()
        context['all_feedback'] = self.get_feedback()
        context['prev_app'], context['next_app'] = self.get_other_apps()

        participant = self.object.participant
        context['active_ratings'] = list(
            participant.ratings(must_be_active=True))
        participant_chair_activities = set(
            perm_utils.chair_activities(participant.user))
        context['chair_activities'] = [
            label for (activity, label) in models.LeaderRating.ACTIVITY_CHOICES
            if activity in participant_chair_activities
        ]
        context['existing_rating'] = self.existing_rating()
        context['existing_rec'] = self.existing_rec()
        context['hide_recs'] = not (assigned_rating or context['existing_rec'])

        all_trips_led = self.object.participant.trips_led
        trips_led = all_trips_led.filter(self.before_rating,
                                         activity=self.activity)
        context['trips_led'] = trips_led.prefetch_related(
            'leaders__leaderrating_set')
        return context
Ejemplo n.º 4
0
    def test_chair_activities(self):
        """ The admin qualifies as a chair when allow_superusers is set. """
        # This admin is not a chair in the normal context
        self.assertFalse(
            perm_utils.chair_activities(self.admin, allow_superusers=False)
        )
        self.assertFalse(perm_utils.chair_activities(self.admin))

        allowed_activities = set(
            perm_utils.chair_activities(self.admin, allow_superusers=True)
        )

        # Considered the chair for closed activities
        self.assertEqual(allowed_activities, set(models.BaseRating.CLOSED_ACTIVITIES))
        # No open activities are included in the set
        self.assertFalse(
            allowed_activities.intersection(models.BaseRating.OPEN_ACTIVITIES)
        )
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def labeled_chair_activities(user):
    chair_activities = set(perm_utils.chair_activities(user, True))
    return [
        choice for choice in models.LeaderRating.CLOSED_ACTIVITY_CHOICES
        if choice[0] in chair_activities
    ]
Ejemplo n.º 7
0
 def allowed_activities(self):
     return perm_utils.chair_activities(self.request.user, True)
Ejemplo n.º 8
0
 def allowed_activities(self):
     return perm_utils.chair_activities(self.request.user, True)
Ejemplo n.º 9
0
def chair_activities(user, allow_superusers=True):
    return perm_utils.chair_activities(user, allow_superusers)
Ejemplo n.º 10
0
 def get_form_kwargs(self):
     return {
         **super().get_form_kwargs(),
         'allowed_activities': perm_utils.chair_activities(self.request.user, True),
         'hide_activity': True,
     }