Esempio n. 1
0
    def test_user_without_participant_cannot_attend(self):
        user = factories.UserFactory.create()

        self.assertCountEqual(
            membership.reasons_cannot_attend(user, self.trip),
            [enums.TripIneligibilityReason.NO_PROFILE_INFO],
        )
Esempio n. 2
0
def not_yet_open(user, trip, signup_form, leader_signup_allowed):
    """ What to display in the signup section when trip signups aren't open (yet). """
    return {
        'trip': trip,
        'reasons_cannot_attend': list(reasons_cannot_attend(user, trip)),
        'signup_form': signup_form,
        'leader_signup_allowed': leader_signup_allowed,
    }
Esempio n. 3
0
def signups_open(user, participant, trip, signup_form, leader_signup_allowed):
    """ What to display when signups are open for a trip. """
    return {
        'user': user,
        'trip': trip,
        'same_day_trips': _same_day_trips(participant, trip),
        'reasons_cannot_attend': list(reasons_cannot_attend(user, trip)),
        'signup_form': signup_form,
        'leader_signup_allowed': leader_signup_allowed,
    }
Esempio n. 4
0
    def get_errors(self, signup):
        """ Take a signup (saved, but not committed), and validate. """
        errors = []
        # (user_info_required ensures that participant is present & not None)
        if signup.trip in signup.participant.trip_set.all():
            errors.append("Already signed up for this trip!")
        if signup.participant in signup.trip.leaders.all():
            errors.append("Already a leader on this trip!")

        # (Use the high-level utility method that enforces a cache refresh if necessary)
        for reason in reasons_cannot_attend(self.request.user, signup.trip):
            errors.append(reason.label)
        return errors
Esempio n. 5
0
 def _can_attend(self, user):
     return not any(membership.reasons_cannot_attend(user, self.trip))