Esempio n. 1
0
    def get_context_data(self, **kwargs):
        participant = self.object = self.get_object()
        trips = self.get_trips()

        e_info = participant.emergency_info
        e_contact = e_info.emergency_contact
        user_viewing = self.request.participant == participant

        context = {
            **super().get_context_data(**kwargs),
            **self._lecture_info(participant, user_viewing),
            'car_form': participant.car and forms.CarForm(instance=participant.car),
            'emergency_contact_form': forms.EmergencyContactForm(instance=e_contact),
            'emergency_info_form': forms.EmergencyInfoForm(instance=e_info),
            'participant': participant,
            'ratings': participant.ratings(must_be_active=True),
            'stats': self.get_stats(trips),
            'trips': trips,
            'user_viewing': user_viewing,
            'wimp': self.wimp,
        }

        if not user_viewing:
            context['all_feedback'] = participant.feedback_set.select_related(
                'trip', 'leader'
            ).prefetch_related('leader__leaderrating_set')

        return context
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        """ Return a dictionary primarily of forms to for template rendering.
        Also includes a value for the "I have a car" checkbox.

        Outputs three types of forms:
            - Bound forms, if POSTed
            - Empty forms if GET, and no stored Participant data
            - Filled forms if GET, and Participant data exists

        Forms are bound to model instances for UPDATE if such instances exist.
        """
        post = self.request.POST if self.request.method == "POST" else None
        participant = self.participant

        # Access other models within participant
        car = participant and participant.car
        e_info = participant and participant.emergency_info
        e_contact = e_info and e_info.emergency_contact

        # If no Participant object, fill at least with User email
        par_kwargs = self.prefix("participant", instance=participant)
        par_kwargs["user"] = self.user
        if not participant:
            par_kwargs["initial"] = {'email': self.user.email}
        elif participant.affiliation_dated or not participant.info_current:
            # Nulling this out forces the user to consciously choose an accurate value
            # (Only null out the field if it's the user editing their own profile, though)
            if self.request.participant == participant:
                par_kwargs["initial"] = {'affiliation': None}

        context = {
            'currently_has_car':
            bool(car),
            'participant_form':
            forms.ParticipantForm(post, **par_kwargs),
            'car_form':
            forms.CarForm(post, instance=car, **self.prefix('car')),
            'emergency_info_form':
            forms.EmergencyInfoForm(post,
                                    instance=e_info,
                                    **self.prefix('einfo')),
            'emergency_contact_form':
            forms.EmergencyContactForm(post,
                                       instance=e_contact,
                                       **self.prefix('econtact')),
        }

        # Boolean: Already responded to question.
        # None: has not responded yet
        if post:
            context['has_car_checked'] = self.has_car
        elif participant:
            context['has_car_checked'] = bool(participant.car)
        else:
            context['has_car_checked'] = None

        return context
Esempio n. 3
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
Esempio n. 4
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'] = 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
Esempio n. 5
0
    def get_context_data(self, **kwargs):
        """Return a dictionary primarily of forms to for template rendering.
        Also includes a value for the "I have a car" checkbox.

        Outputs three types of forms:
            - Bound forms, if POSTed
            - Empty forms if GET, and no stored Participant data
            - Filled forms if GET, and Participant data exists

        Forms are bound to model instances for UPDATE if such instances exist.
        """
        post = self.request.POST if self.request.method == "POST" else None
        participant = self.participant

        # Access other models within participant
        car = participant and participant.car
        e_info = participant and participant.emergency_info
        e_contact = e_info and e_info.emergency_contact

        par_kwargs = {
            'prefix': 'participant',
            'instance': participant,
            'user': self.user,
        }
        if not participant:
            par_kwargs["initial"] = {'email': self.user.email}
        elif participant.affiliation_dated or not participant.info_current:
            # Nulling this out forces the user to consciously choose an accurate value
            # (Only null out the field if it's the user editing their own profile, though)
            if self.request.participant == participant:
                par_kwargs["initial"] = {'affiliation': None}

        verified_mit_emails = self.user.emailaddress_set.filter(
            verified=True, email__iendswith='mit.edu'
        )

        context = {
            # For everybody but an admin, `participant` is just `viewing_participant`
            'participant': participant,
            'medical_info_scrubbed': bool(
                participant and e_info and not e_info.allergies
            ),
            'has_mit_email': verified_mit_emails.exists(),
            'currently_has_car': bool(car),
            'participant_form': forms.ParticipantForm(post, **par_kwargs),
            'car_form': forms.CarForm(post, instance=car, prefix='car'),
            'emergency_info_form': forms.EmergencyInfoForm(
                post, instance=e_info, prefix='einfo'
            ),
            'emergency_contact_form': forms.EmergencyContactForm(
                post, instance=e_contact, prefix='econtact'
            ),
        }

        # Boolean: Already responded to question.
        # None: has not responded yet
        if post:
            context['has_car_checked'] = self.has_car
        elif participant:
            context['has_car_checked'] = bool(participant.car)
        else:
            context['has_car_checked'] = None

        return context