Skip to content

Commit

Permalink
Fixed alumni newsletter opt out without filling in extra information (#…
Browse files Browse the repository at this point in the history
…3643)

* changed when fields are required

* Clean up docstring

---------

Co-authored-by: Dirk Doesburg <[email protected]>
  • Loading branch information
Noah-marc and DeD1rk authored Mar 13, 2024
1 parent 6c0b7ff commit 2d870c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
23 changes: 15 additions & 8 deletions website/members/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@


class ProfileForm(forms.ModelForm):
"""Form with all the user editable fields of a Profile model."""
"""Form with all the user editable fields of a Profile model.
If the profile is minimized, no fields are required, unless the `require_address`
keyword argument is True, which is set if a user is filling a minimized profile
in order to be able to create a Renewal.
"""

birthday = forms.DateField()

Expand Down Expand Up @@ -43,8 +48,9 @@ class Meta:
]
model = Profile

def __init__(self, *args, **kwargs):
def __init__(self, *args, require_address=False, **kwargs):
super().__init__(*args, **kwargs)
user = Member.objects.get(pk=kwargs["instance"].user_id)
for field in [
"birthday",
"address_street",
Expand All @@ -53,16 +59,17 @@ def __init__(self, *args, **kwargs):
"address_city",
"address_country",
]:
self.fields[field].required = True
if require_address or not user.profile.is_minimized:
self.fields[field].required = True
else:
self.fields[field].required = False

if not kwargs["instance"].user.is_staff:
self.fields["email_gsuite_only"].widget = self.fields[
"email_gsuite_only"
].hidden_widget()

if (
not Member.objects.get(pk=kwargs["instance"].user_id).has_been_member()
and not kwargs["instance"].receive_oldmembers
):
if not user.has_been_member() and not kwargs["instance"].receive_oldmembers:
self.fields["receive_oldmembers"].disabled = True
self.fields["receive_oldmembers"].help_text = (
"If you are a past member, receive emails about Thalia events aimed at alumni. "
Expand All @@ -72,7 +79,7 @@ def __init__(self, *args, **kwargs):
)

self.fields["birthday"].widget.input_type = "date"
if not Member.objects.get(pk=kwargs["instance"].user_id).profile.is_minimized:
if not user.profile.is_minimized:
self.fields["birthday"].disabled = True

self.render_app_specific_profile_form_fields()
Expand Down
5 changes: 5 additions & 0 deletions website/members/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ class UserProfileUpdateView(RedirectURLMixin, SuccessMessageMixin, UpdateView):
def get_object(self, queryset=None) -> Profile:
return get_object_or_404(models.Profile, user=self.request.user)

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["require_address"] = bool(self.request.GET.get("require_address", False))
return kwargs


@method_decorator(login_required, "dispatch")
class StatisticsView(TemplateView):
Expand Down
2 changes: 1 addition & 1 deletion website/registrations/templates/registrations/renewal.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ <h3>{% trans "Membership history" %}</h3>

You have a minimized profile. You can't renew your
membership until you have filled in all the required
fields.<a href="{% url "members:edit-profile" %}?next={% url "registrations:renew" %}"> Click here</a> to complete your profile.
fields.<a href="{% url "members:edit-profile" %}?require_address=1&next={% url "registrations:renew" %}"> Click here</a> to complete your profile.
</p>
{% endif %}
</div>
Expand Down

0 comments on commit 2d870c3

Please sign in to comment.