Skip to content

Commit

Permalink
Feature/study long to benefactor (#3848)
Browse files Browse the repository at this point in the history
* update renewal form to allow benefactorer renewals when having a study long membership

* Fix services to allow for benefactorer registrations when having study long membership

* Update views.py to allow for benefactorer extension

* Fix tests
  • Loading branch information
T8902 authored Nov 18, 2024
1 parent e4a5c40 commit 9559540
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions website/registrations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def clean(self):
if (
self.cleaned_data["member"].latest_membership
and self.cleaned_data["member"].latest_membership.study_long
and self.cleaned_data["membership_type"] != Membership.BENEFACTOR
):
raise ValidationError("It's not possible to renew a study long membership.")

Expand Down
12 changes: 6 additions & 6 deletions website/registrations/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def complete_renewal(renewal: Renewal):

latest_membership = member.latest_membership
current_membership = member.current_membership
if (latest_membership and latest_membership.study_long) or (
current_membership
and (current_membership.study_long or current_membership.until is None)
and not renewal.membership_type == Membership.BENEFACTOR
):
raise ValueError("This member already has a never ending membership")
if (
latest_membership
and latest_membership.study_long
and renewal.membership_type != Membership.BENEFACTOR
) or (current_membership and current_membership.until is None):
raise ValueError("This member already has a never ending membership.")
until = timezone.datetime(year=lecture_year + 1, month=9, day=1).date()
with transaction.atomic():
if renewal.length == Renewal.MEMBERSHIP_STUDY:
Expand Down
15 changes: 9 additions & 6 deletions website/registrations/templates/registrations/renewal.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ <h3>{% trans "Membership history" %}</h3>
have to renew your membership.
{% endblocktrans %}
</p>
{% elif latest_membership.study_long %}
<p>
You seem to be on the wrong page for your membership type.
follow <a href="{% url 'registrations:renew-studylong' %}">this link</a> to renew your membership.
</p>
{% elif not request.member.profile.is_minimized %}
{% for error in form.errors.items %}
{% for message in error.1 %}
Expand All @@ -144,11 +139,19 @@ <h3>{% trans "Membership history" %}</h3>
data-benefactor-type="{{ benefactor_type }}">
{% csrf_token %}
<fieldset>
{% if not latest_membership.type == 'benefactor' %}
{% if not latest_membership.type == 'benefactor' and not latest_membership.study_long %}
{% bootstrap_field form.membership_type %}
{% bootstrap_field form.length %}
{% bootstrap_field form.contribution form_group_class='form-row required-field d-none' %}
{% else %}
{% if latest_membership.study_long %}
<div class="col-md-12">
<div class="alert alert-info">
You seem to have a membership which you can freely extend until the end of your studies. If you are still studying Computing Science/Information Sience, <a style="text-decoration: underline; color:white" href="{% url 'registrations:renew-studylong' %}">click this link to extend your membership for free.</a> Otherwise continue with the form below to become benefactor.
</div>
</div>
{% endif %}

<div class="form-row">
<label
for="id_membership_type">{% trans 'membership type'|capfirst %}</label>
Expand Down
2 changes: 1 addition & 1 deletion website/registrations/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ def test_post(self, super_post):
request.member = MagicMock()
request.member.pk = 2
self.view.request = request
request.member.latest_membership.study_long = False

request.member.latest_membership.type = Membership.MEMBER
self.view.post(request)

request = super_post.call_args[0][0]
Expand Down
7 changes: 6 additions & 1 deletion website/registrations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from django.views import View
from django.views.generic import CreateView, FormView
from django.views.generic.base import TemplateResponseMixin, TemplateView

from django_ratelimit.decorators import ratelimit

from members.decorators import membership_required
from members.models import Membership

Expand Down Expand Up @@ -289,7 +291,10 @@ def get_form(self, form_class=None):

def post(self, request, *args, **kwargs):
request.POST = request.POST.dict()
if request.member.latest_membership.type == Membership.BENEFACTOR:
if (
request.member.latest_membership.type == Membership.BENEFACTOR
or request.member.latest_membership.study_long
):
request.POST["membership_type"] = Membership.BENEFACTOR
request.POST["length"] = Entry.MEMBERSHIP_YEAR
request.POST["member"] = request.member.pk
Expand Down

0 comments on commit 9559540

Please sign in to comment.