コード例 #1
0
 def test_save_waiting_list(self):
     self.participant = ActivityParticipant(
         activity=self.activity,
         member=self.member
     )
     self.participant.save()
     self.assertFalse(WaitingList.objects.filter(pk=self.waitinglist_id).exists())
コード例 #2
0
class TestModelActivityParticipant(TestCase):
    # ToDo: Maybe test payment
    def setUp(self):
        self.union = Union()
        self.union.save()

        self.department = Department(
            union=self.union
        )
        self.department.save()

        self.activity = Activity(
            start_date=datetime.now(),
            end_date=datetime.now() + timedelta(days=365),  # Has to be long enough to be a season
            department=self.department
        )
        self.activity.save()
        self.assertTrue(self.activity.is_season())  # If this fail increase the end_date

        self.family = Family(
            email='*****@*****.**'
        )
        self.family.save()

        self.person = Person(
            family=self.family
        )
        self.person.save()

        self.member = Member(
            department=self.department,
            person=self.person,
            is_active=True
        )
        self.member.save()

        waitinglist = WaitingList(
            person=self.person,
            department=self.department,
            on_waiting_list_since=datetime.now() - timedelta(days=1)
        )
        waitinglist.save()
        self.waitinglist_id = waitinglist.id

    def test_save_waiting_list(self):
        self.participant = ActivityParticipant(
            activity=self.activity,
            member=self.member
        )
        self.participant.save()
        self.assertFalse(WaitingList.objects.filter(pk=self.waitinglist_id).exists())
コード例 #3
0
def ActivitySignup(request, activity_id, person_id=None):
    # TODO: is should be possible to view an activity without loggin in
    if(person_id is None):
        # View only mode
        view_only_mode = True
    else:
        view_only_mode = False

    activity = get_object_or_404(Activity, pk=activity_id)

    participating = False

    if(request.resolver_match.url_name == 'activity_view_person'):
        view_only_mode = True

    family = user_to_person(request.user).family

    if person_id:
        try:
            person = family.person_set.get(pk=person_id)

            # Check not already signed up
            try:
                participant = ActivityParticipant.objects.get(activity=activity, member__person=person)
                # found - we can only allow one - switch to view mode
                participating = True
                view_only_mode = True
            except ActivityParticipant.DoesNotExist:
                participating = False  # this was expected - if not signed up yet

        except Person.DoesNotExist:
            raise Http404('Person not found on family')
    else:
        person = None

    if(not activity.open_invite):
        ''' Make sure valid not expired invitation to event exists '''
        try:
            invitation = ActivityInvite.objects.get(activity=activity, person=person, expire_dtm__gte=timezone.now())
        except ActivityInvite.DoesNotExist:
            view_only_mode = True  # not invited - switch to view mode
            invitation = None
    else:
        invitation = None

    # signup_closed should default to False
    signup_closed = False

    # if activity is closed for signup, only invited persons can still join
    if activity.signup_closing < timezone.now().date() and invitation is None:
        view_only_mode = True  # Activivty closed for signup
        signup_closed = True

    # check if activity is full
    if activity.seats_left() <= 0:
        view_only_mode = True  # activity full
        signup_closed = True

    if(request.method == "POST"):
        if view_only_mode:
            return HttpResponse('Du kan ikke tilmelde dette event nu. (ikke inviteret / tilmelding lukket / du er allerede tilmeldt eller aktiviteten er fuldt booket)')

        if activity.max_age < person.age_years() or activity.min_age > person.age_years():
            return HttpResponse('Barnet skal være mellem ' + str(activity.min_age) + ' og ' + str(activity.max_age) + ' år gammel for at deltage. (Er fødselsdatoen udfyldt korrekt ?)')

        if Person.objects.filter(family=family).exclude(membertype=Person.CHILD).count() <= 0:
            return HttpResponse('Barnet skal have en forælder eller værge. Gå tilbage og tilføj en før du tilmelder.')

        signup_form = ActivitySignupForm(request.POST)

        if signup_form.is_valid():
            # Sign up and redirect to payment link or family page

            # Calculate membership
            membership_start = timezone.datetime(year=activity.start_date.year, month=1, day=1)
            membership_end = timezone.datetime(year=activity.start_date.year, month=12, day=31)
            # check if person is member, otherwise make a member
            try:
                member = Member.objects.get(person=person)
            except Member.DoesNotExist:
                member = Member(
                    department=activity.department,
                    person=person,
                    member_since=membership_start,
                    member_until=membership_end,
                )
                member.save()

            # update membership end date
            member.member_until = membership_end
            member.save()

            # Make ActivityParticipant
            participant = ActivityParticipant(member=member, activity=activity, note=signup_form.cleaned_data['note'])

            # If conditions not accepted, make error
            if signup_form.cleaned_data['read_conditions'] == "NO":
                return HttpResponse("For at gå til en Coding Pirates aktivitet skal du acceptere vores betingelser.")

            # Make sure people have selected yes or no in photo permission and update photo permission
            if signup_form.cleaned_data['photo_permission'] == "Choose":
                return HttpResponse("Du skal vælge om vi må tage billeder eller ej.")
            participant.photo_permission = signup_form.cleaned_data['photo_permission']
            participant.save()

            return_link_url = reverse('activity_view_person', args=[activity.id, person.id])

            # Make payment if activity costs
            if activity.price_in_dkk is not None and activity.price_in_dkk != 0:
                # using creditcard ?
                if signup_form.cleaned_data['payment_option'] == Payment.CREDITCARD:
                    payment = Payment(
                        payment_type=Payment.CREDITCARD,
                        activity=activity,
                        activityparticipant=participant,
                        person=person,
                        family=family,
                        body_text=timezone.now().strftime("%Y-%m-%d") + ' Betaling for ' + activity.name + ' på ' + activity.department.name,
                        amount_ore=int(activity.price_in_dkk * 100),
                    )
                    payment.save()

                    return_link_url = payment.get_quickpaytransaction().get_link_url(return_url=settings.BASE_URL + reverse('activity_view_person', args=[activity.id, person.id]))

            # expire invitation
            if invitation:
                invitation.expire_dtm = timezone.now() - timezone.timedelta(days=1)
                invitation.save()

            # reject all seasonal invitations on person if this was a seasonal invite
            # (to avoid signups on multiple departments for club season)
            if activity.is_season():
                invites = ActivityInvite.objects.filter(person=person).exclude(activity=activity)
                for invite in invites:
                    if invite.activity.is_season():
                        invite.rejected_dtm = timezone.now()
                        invite.save()

            return HttpResponseRedirect(return_link_url)
        # fall through else
    else:

        signup_form = ActivitySignupForm()

    union = activity.department.union

    context = {
        'family': family,
        'activity': activity,
        'person': person,
        'invitation': invitation,
        'price': activity.price_in_dkk,
        'seats_left': activity.seats_left(),
        'signupform': signup_form,
        'signup_closed': signup_closed,
        'view_only_mode': view_only_mode,
        'participating': participating,
        'union': union,
    }
    return render(request, 'members/activity_signup.html', context)
コード例 #4
0
def ActivitySignup(request, activity_id, unique=None, person_id=None):
    try:
        if unique is not None:
            unique = uuid.UUID(unique)
    except ValueError:
        return HttpResponseBadRequest("Familie id er ugyldigt")

    if (unique is None or person_id is None):
        # View only mode
        view_only_mode = True
    else:
        view_only_mode = False

    activity = get_object_or_404(Activity, pk=activity_id)

    participants = ActivityParticipant.objects.filter(
        activity=activity).order_by('member__person__name')
    participating = False

    if (request.resolver_match.url_name == 'activity_view_person'):
        view_only_mode = True

    if unique:
        family = get_object_or_404(Family, unique=unique)
    else:
        family = None

    if person_id:
        try:
            person = family.person_set.get(pk=person_id)

            # Check not already signed up
            try:
                participant = ActivityParticipant.objects.get(
                    activity=activity, member__person=person)
                # found - we can only allow one - switch to view mode
                participating = True
                view_only_mode = True
            except ActivityParticipant.DoesNotExist:
                participating = False  # this was expected - if not signed up yet

        except Person.DoesNotExist:
            raise Http404('Person not found on family')
    else:
        person = None

    if (not activity.open_invite):
        ''' Make sure valid not expired invitation to event exists '''
        try:
            invitation = ActivityInvite.objects.get(
                activity=activity,
                person=person,
                expire_dtm__gte=timezone.now())
        except ActivityInvite.DoesNotExist:
            view_only_mode = True  # not invited - switch to view mode
            invitation = None
    else:
        invitation = None

    # if activity is closed for signup, only invited persons can still join
    if activity.signup_closing < timezone.now().date() and invitation is None:
        view_only_mode = True  # Activivty closed for signup
        signup_closed = True

    # check if activity is full
    if activity.seats_left() <= 0:
        view_only_mode = True  # activity full
        signup_closed = True

    if (request.method == "POST"):
        if view_only_mode:
            return HttpResponse(
                'Du kan ikke tilmelde dette event nu. (ikke inviteret / tilmelding lukket / du er allerede tilmeldt eller aktiviteten er fuldt booket)'
            )

        if activity.max_age < person.age_years(
        ) or activity.min_age > person.age_years():
            return HttpResponse(
                'Barnet skal være mellem ' + str(activity.min_age) + ' og ' +
                str(activity.max_age) +
                ' år gammel for at deltage. (Er fødselsdatoen udfyldt korrekt ?)'
            )

        if Person.objects.filter(family=family).exclude(
                membertype=Person.CHILD).count() <= 0:
            return HttpResponse(
                'Barnet skal have en forælder eller værge. Gå tilbage og tilføj en før du tilmelder.'
            )

        signup_form = ActivitySignupForm(request.POST)

        if signup_form.is_valid():
            # Sign up and redirect to payment link or family page

            # Calculate membership
            membership_start = timezone.datetime(year=activity.start_date.year,
                                                 month=1,
                                                 day=1)
            membership_end = timezone.datetime(year=activity.start_date.year,
                                               month=12,
                                               day=31)
            # check if person is member, otherwise make a member
            try:
                member = Member.objects.get(person=person)
            except Member.DoesNotExist:
                member = Member(
                    department=activity.department,
                    person=person,
                    member_since=membership_start,
                    member_until=membership_end,
                )
                member.save()

            # update membership end date
            member.member_until = membership_end
            member.save()

            # Make ActivityParticipant
            participant = ActivityParticipant(
                member=member,
                activity=activity,
                note=signup_form.cleaned_data['note'])

            # update photo permission and contact open info
            participant.photo_permission = True  # signup_form.cleaned_data['photo_permission']
            participant.contact_visible = signup_form.cleaned_data[
                'address_permission'] == "YES"
            participant.save()

            return_link_url = reverse(
                'activity_view_person',
                args=[family.unique, activity.id, person.id])

            # Make payment if activity costs
            if activity.price_in_dkk is not None and activity.price_in_dkk != 0:
                # using creditcard ?
                if signup_form.cleaned_data[
                        'payment_option'] == Payment.CREDITCARD:
                    payment = Payment(
                        payment_type=Payment.CREDITCARD,
                        activity=activity,
                        activityparticipant=participant,
                        person=person,
                        family=family,
                        body_text=timezone.now().strftime("%Y-%m-%d") +
                        ' Betaling for ' + activity.name + ' på ' +
                        activity.department.name,
                        amount_ore=int(activity.price_in_dkk * 100),
                    )
                    payment.save()

                    return_link_url = payment.get_quickpaytransaction(
                    ).get_link_url(
                        return_url=settings.BASE_URL +
                        reverse('activity_view_person',
                                args=[family.unique, activity.id, person.id]))

            # expire invitation
            if invitation:
                invitation.expire_dtm = timezone.now() - timezone.timedelta(
                    days=1)
                invitation.save()

            # reject all seasonal invitations on person if this was a seasonal invite
            # (to avoid signups on multiple departments for club season)
            if activity.is_season():
                invites = ActivityInvite.objects.filter(person=person).exclude(
                    activity=activity)
                for invite in invites:
                    if invite.activity.is_season():
                        invite.rejected_dtm = timezone.now()
                        invite.save()

            return HttpResponseRedirect(return_link_url)
        # fall through else
    else:

        signup_form = ActivitySignupForm()

    union = activity.department.union

    context = {
        'family': family,
        'activity': activity,
        'person': person,
        'invitation': invitation,
        'price': activity.price_in_dkk,
        'seats_left': activity.seats_left(),
        'signupform': signup_form,
        'view_only_mode': view_only_mode,
        'participating': participating,
        'participants': participants,
        'union': union,
    }
    return render(request, 'members/activity_signup.html', context)
コード例 #5
0
def ActivitySignup(request, activity_id, person_id=None):
    # TODO: is should be possible to view an activity without loggin in
    if person_id is None:
        # View only mode
        view_only_mode = True
    else:
        view_only_mode = False

    activity = get_object_or_404(Activity, pk=activity_id)

    participating = False

    if request.resolver_match.url_name == "activity_view_person":
        view_only_mode = True

    family = user_to_person(request.user).family

    if person_id:
        try:
            person = family.person_set.get(pk=person_id)

            # Check not already signed up
            try:
                participant = ActivityParticipant.objects.get(
                    activity=activity, member__person=person)
                # found - we can only allow one - switch to view mode
                participating = True
                view_only_mode = True
            except ActivityParticipant.DoesNotExist:
                participating = False  # this was expected - if not signed up yet

        except Person.DoesNotExist:
            raise Http404("Person not found on family")
    else:
        person = None

    if not activity.open_invite:
        """ Make sure valid not expired invitation to event exists """
        try:
            invitation = ActivityInvite.objects.get(
                activity=activity,
                person=person,
                expire_dtm__gte=timezone.now())
        except ActivityInvite.DoesNotExist:
            view_only_mode = True  # not invited - switch to view mode
            invitation = None
    else:
        invitation = None

    # signup_closed should default to False
    signup_closed = False

    # if activity is closed for signup, only invited persons can still join
    if activity.signup_closing < timezone.now().date() and invitation is None:
        view_only_mode = True  # Activivty closed for signup
        signup_closed = True

    # check if activity is full
    if activity.seats_left() <= 0:
        view_only_mode = True  # activity full
        signup_closed = True

    if request.method == "POST":
        if view_only_mode:
            return HttpResponse(
                "Du kan ikke tilmelde dette event nu. (ikke inviteret / tilmelding lukket / du er allerede tilmeldt eller aktiviteten er fuldt booket)"
            )

        if (activity.max_age < person.age_years()
                or activity.min_age > person.age_years()):
            return HttpResponse(
                "Barnet skal være mellem " + str(activity.min_age) + " og " +
                str(activity.max_age) +
                " år gammel for at deltage. (Er fødselsdatoen udfyldt korrekt ?)"
            )

        if (Person.objects.filter(family=family).exclude(
                membertype=Person.CHILD).count() <= 0):
            return HttpResponse(
                "Barnet skal have en forælder eller værge. Gå tilbage og tilføj en før du tilmelder."
            )

        signup_form = ActivitySignupForm(request.POST)

        if signup_form.is_valid():
            # Sign up and redirect to payment link or family page

            # Calculate membership
            membership_start = timezone.datetime(year=activity.start_date.year,
                                                 month=1,
                                                 day=1)
            membership_end = timezone.datetime(year=activity.start_date.year,
                                               month=12,
                                               day=31)
            # check if person is member, otherwise make a member
            try:
                member = Member.objects.get(person=person)
            except Member.DoesNotExist:
                member = Member(
                    department=activity.department,
                    person=person,
                    member_since=membership_start,
                    member_until=membership_end,
                )
                member.save()

            # update membership end date
            member.member_until = membership_end
            member.save()

            # Make ActivityParticipant
            participant = ActivityParticipant(
                member=member,
                activity=activity,
                note=signup_form.cleaned_data["note"])

            # If conditions not accepted, make error
            if signup_form.cleaned_data["read_conditions"] == "NO":
                return HttpResponse(
                    "For at gå til en Coding Pirates aktivitet skal du acceptere vores betingelser."
                )

            # Make sure people have selected yes or no in photo permission and update photo permission
            if signup_form.cleaned_data["photo_permission"] == "Choose":
                return HttpResponse(
                    "Du skal vælge om vi må tage billeder eller ej.")
            participant.photo_permission = signup_form.cleaned_data[
                "photo_permission"]
            participant.save()

            return_link_url = reverse("activity_view_person",
                                      args=[activity.id, person.id])

            # Make payment if activity costs
            if activity.price_in_dkk is not None and activity.price_in_dkk != 0:
                # using creditcard ?
                if signup_form.cleaned_data[
                        "payment_option"] == Payment.CREDITCARD:
                    payment = Payment(
                        payment_type=Payment.CREDITCARD,
                        activity=activity,
                        activityparticipant=participant,
                        person=person,
                        family=family,
                        body_text=timezone.now().strftime("%Y-%m-%d") +
                        " Betaling for " + activity.name + " på " +
                        activity.department.name,
                        amount_ore=int(activity.price_in_dkk * 100),
                    )
                    payment.save()

                    return_link_url = payment.get_quickpaytransaction(
                    ).get_link_url(return_url=settings.BASE_URL + reverse(
                        "activity_view_person", args=[activity.id, person.id]))

            # expire invitation
            if invitation:
                invitation.expire_dtm = timezone.now() - timezone.timedelta(
                    days=1)
                invitation.save()

            # reject all seasonal invitations on person if this was a seasonal invite
            # (to avoid signups on multiple departments for club season)
            if activity.is_season():
                invites = ActivityInvite.objects.filter(person=person).exclude(
                    activity=activity)
                for invite in invites:
                    if invite.activity.is_season():
                        invite.rejected_dtm = timezone.now()
                        invite.save()

            return HttpResponseRedirect(return_link_url)
        # fall through else
    else:

        signup_form = ActivitySignupForm()

    union = activity.department.union

    context = {
        "family": family,
        "activity": activity,
        "person": person,
        "invitation": invitation,
        "price": activity.price_in_dkk,
        "seats_left": activity.seats_left(),
        "signupform": signup_form,
        "signup_closed": signup_closed,
        "view_only_mode": view_only_mode,
        "participating": participating,
        "union": union,
    }
    return render(request, "members/activity_signup.html", context)