We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
AttributeError: 'Profile' object has no attribute 'is_minimised'
Sentry Issue: [CONCREXIT-P2](https://thalia.sentry.io/issues/4038068631/?referrer=github_integration)

```
AttributeError: 'Profile' object has no attribute 'is_minimised'
(3 additional frame(s) were not displayed)
...
  File "registrations/views.py", line 238, in get_context_data
    ) and self.request.member.profile.is_minimised:
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `website/registrations/views.py`
Content:
```
1 """Views provided by the registrations package."""
2 from django.conf import settings
3 from django.contrib import messages
4 from django.contrib.admin.utils import model_ngettext
5 from django.contrib.admin.views.decorators import staff_member_required
6 from django.contrib.auth.decorators import login_required, permission_required
7 from django.contrib.contenttypes.models import ContentType
8 from django.core.exceptions import ValidationError
9 from django.db.models import Q
10 from django.http import Http404
11 from django.shortcuts import get_object_or_404, redirect
12 from django.template.defaultfilters import floatformat
13 from django.urls import reverse
14 from django.utils import timezone
15 from django.utils.decorators import method_decorator
16 from django.utils.translation import gettext_lazy as _
17 from django.views import View
18 from django.views.generic import CreateView, FormView
19 from django.views.generic.base import TemplateResponseMixin, TemplateView
20 
21 from members.decorators import membership_required
22 from members.models import Membership
23 
24 from . import emails, forms, services
25 from .models import Entry, Reference, Registration, Renewal
26 
27 
28 class BecomeAMemberView(TemplateView):
29     """View that render a HTML template with context data."""
30 
31     template_name = "registrations/become_a_member.html"
32 
33     def get_context_data(self, **kwargs):
34         context = super().get_context_data(**kwargs)
35         context["year_fees"] = floatformat(
36             settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2
37         )
38         context["study_fees"] = floatformat(
39             settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2
40         )
41         return context
42 
43 
44 @method_decorator(staff_member_required, name="dispatch")
45 @method_decorator(
46     permission_required("registrations.review_entries"),
47     name="dispatch",
48 )
49 class EntryAdminView(View):
50     """View that handles the processing of entries."""
51 
52     def post(self, request, *args, **kwargs):
53         action = request.POST.get("action")
54         entry_qs = Entry.objects.filter(pk=kwargs["pk"])
55         try:
56             entry = entry_qs.get()
57         except Entry.DoesNotExist:
58             return redirect("admin:index")
59 
60         if action == "accept":
61             if not services.check_unique_user(entry):
62                 messages.error(
63                     request,
64                     _("Could not accept %s. Username is not unique.")
65                     % model_ngettext(entry, 1),
66                 )
67             elif services.accept_entries(request.user.pk, entry_qs) > 0:
68                 messages.success(
69                     request, _("Successfully accepted %s.") % model_ngettext(entry, 1)
70                 )
71             else:
72                 messages.error(
73                     request, _("Could not accept %s.") % model_ngettext(entry, 1)
74                 )
75         elif action == "reject":
76             if services.reject_entries(request.user.pk, entry_qs) > 0:
77                 messages.success(
78                     request, _("Successfully rejected %s.") % model_ngettext(entry, 1)
79                 )
80             else:
81                 messages.error(
82                     request, _("Could not reject %s.") % model_ngettext(entry, 1)
83                 )
84         elif action == "resend":
85             try:
86                 emails.send_registration_email_confirmation(entry.registration)
87             except Registration.DoesNotExist:
88                 pass
89         elif action == "revert":
90             services.revert_entry(request.user.pk, entry)
91 
92         if entry_qs.filter(renewal=None).exists():
93             content_type = ContentType.objects.get_for_model(Registration)
94         else:
95             content_type = ContentType.objects.get_for_model(Renewal)
96 
97         return redirect(
98             f"admin:{content_type.app_label}_{content_type.model}_change",
99             kwargs["pk"],
100         )
101 
102 
103 class ConfirmEmailView(View, TemplateResponseMixin):
104     """View that renders an HTML template and confirms the email address of the provided registration."""
105 
106     template_name = "registrations/confirm_email.html"
107 
108     def get(self, request, *args, **kwargs):
109         queryset = Registration.objects.filter(pk=kwargs["pk"])
110 
111         processed = 0
112         try:
113             processed = services.confirm_entry(queryset)
114         except ValidationError:
115             pass
116 
117         if processed == 0:
118             return redirect("registrations:register-member")
119 
120         registration = queryset.get()
121 
122         if (
123             registration.membership_type == Membership.BENEFACTOR
124             and not registration.no_references
125         ):
126             emails.send_references_information_message(registration)
127 
128         emails.send_new_registration_board_message(registration)
129 
130         return self.render_to_response({})
131 
132 
133 class BaseRegistrationFormView(FormView):
134     """View that renders a membership registration form."""
135 
136     form_class = forms.MemberRegistrationForm
137     template_name = "registrations/register_member.html"
138 
139     def get_context_data(self, **kwargs):
140         context = super().get_context_data(**kwargs)
141         context["google_api_key"] = settings.GOOGLE_PLACES_API_KEY
142         context["year_fees"] = floatformat(
143             settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2
144         )
145         context["study_fees"] = floatformat(
146             settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2
147         )
148         return context
149 
150     def get(self, request, *args, **kwargs):
151         if request.user.is_authenticated:
152             return redirect("registrations:renew")
153         return super().get(request, args, kwargs)
154 
155     def form_valid(self, form):
156         form.save()
157         emails.send_registration_email_confirmation(form.instance)
158         return redirect("registrations:register-success")
159 
160 
161 class MemberRegistrationFormView(BaseRegistrationFormView):
162     """View that renders the `member` membership registration form."""
163 
164     form_class = forms.MemberRegistrationForm
165     template_name = "registrations/register_member.html"
166 
167     def get_context_data(self, **kwargs):
168         context = super().get_context_data(**kwargs)
169         context["tpay_enabled"] = (
170             settings.THALIA_PAY_ENABLED_PAYMENT_METHOD
171             and settings.THALIA_PAY_FOR_NEW_MEMBERS
172         )
173         return context
174 
175     def post(self, request, *args, **kwargs):
176         request.POST = request.POST.dict()
177         request.POST["language"] = request.LANGUAGE_CODE
178         request.POST["membership_type"] = Membership.MEMBER
179         return super().post(request, *args, **kwargs)
180 
181 
182 class BenefactorRegistrationFormView(BaseRegistrationFormView):
183     """View that renders the `benefactor` membership registration form."""
184 
185     form_class = forms.BenefactorRegistrationForm
186     template_name = "registrations/register_benefactor.html"
187 
188     def get_context_data(self, **kwargs):
189         context = super().get_context_data(**kwargs)
190         context["tpay_enabled"] = (
191             settings.THALIA_PAY_ENABLED_PAYMENT_METHOD
192             and settings.THALIA_PAY_FOR_NEW_MEMBERS
193         )
194         return context
195 
196     def post(self, request, *args, **kwargs):
197         request.POST = request.POST.dict()
198         request.POST["language"] = request.LANGUAGE_CODE
199         request.POST["membership_type"] = Membership.BENEFACTOR
200         request.POST["length"] = Entry.MEMBERSHIP_YEAR
201         request.POST["remarks"] = (
202             "Registered as iCIS employee" if "icis_employee" in request.POST else ""
203         )
204         request.POST["no_references"] = "icis_employee" in request.POST
205         return super().post(request, *args, **kwargs)
206 
207 
208 @method_decorator(login_required, name="dispatch")
209 class RenewalFormView(FormView):
210     """View that renders the membership renewal form."""
211 
212     form_class = forms.RenewalForm
213     template_name = "registrations/renewal.html"
214 
215     def get_context_data(self, **kwargs):
216         context = super().get_context_data(**kwargs)
217         context["year_fees"] = floatformat(
218             settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2
219         )
220         context["study_fees"] = floatformat(
221             settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2
222         )
223         context["latest_membership"] = self.request.member.latest_membership
224         context["latest_renewal"] = Renewal.objects.filter(
225             Q(member=self.request.member)
226             & (
227                 Q(status=Registration.STATUS_ACCEPTED)
228                 | Q(status=Registration.STATUS_REVIEW)
229             )
230         ).last()
231         context["was_member"] = Membership.objects.filter(
232             user=self.request.member, type=Membership.MEMBER
233         ).exists()
234 
235         if (
236             self.request.member.latest_membership
237             and not self.request.member.latest_membership.is_active()
238         ) and self.request.member.profile.is_minimised:
239             messages.warning(
240                 self.request,
241                 _(
242                     "You seem to have been a member in the past, but your profile data has been deleted. Please contact the board to renew your membership."
243                 ),
244             )
245         context["benefactor_type"] = Membership.BENEFACTOR
246         return context
247 
248     def get_form(self, form_class=None):
249         form = super().get_form(form_class)
250         member = self.request.member
251         if member is not None and member.latest_membership is not None:
252             latest_membership = member.latest_membership
253             # If latest membership has not ended or does not ends
254             # within 1 month: do not show 'year' length and disable benefactor option
255             hide_year_choice = not (
256                 latest_membership is not None
257                 and latest_membership.until is not None
258                 and (latest_membership.until - timezone.now().date()).days <= 31
259             )
260 
261             if hide_year_choice:
262                 form.fields["length"].choices = [
263                     c
264                     for c in form.fields["length"].choices
265                     if c[0] != Entry.MEMBERSHIP_YEAR
266                 ]
267                 form.fields["membership_type"].choices = [
268                     c
269                     for c in form.fields["membership_type"].choices
270                     if c[0] != Membership.BENEFACTOR
271                 ]
272 
273         return form
274 
275     def post(self, request, *args, **kwargs):
276         request.POST = request.POST.dict()
277         if request.member.latest_membership.type == Membership.BENEFACTOR:
278             request.POST["membership_type"] = Membership.BENEFACTOR
279             request.POST["length"] = Entry.MEMBERSHIP_YEAR
280         request.POST["member"] = request.member.pk
281         request.POST["remarks"] = ""
282         request.POST["no_references"] = True
283 
284         if request.POST["membership_type"] == Membership.BENEFACTOR:
285             request.POST["no_references"] = False
286             if Membership.objects.filter(
287                 user=request.member, type=Membership.MEMBER
288             ).exists():
289                 request.POST["remarks"] = "Was a Thalia member in the past."
290                 request.POST["no_references"] = True
291             if "icis_employee" in request.POST:
292                 request.POST["remarks"] = "Registered as iCIS employee."
293                 request.POST["no_references"] = True
294 
295         return super().post(request, *args, **kwargs)
296 
297     def form_valid(self, form):
298         renewal = form.save()
299         if not renewal.no_references:
300             emails.send_references_information_message(renewal)
301         emails.send_new_renewal_board_message(renewal)
302         return redirect("registrations:renew-success")
303 
304 
305 @method_decorator(login_required, name="dispatch")
306 @method_decorator(membership_required, name="dispatch")
307 class ReferenceCreateView(CreateView):
308     """View that renders a reference creation form."""
309 
310     model = Reference
311     form_class = forms.ReferenceForm
312     template_name = "registrations/reference.html"
313     entry = None
314     success = False
315 
316     def get_success_url(self):
317         return reverse("registrations:reference-success", args=(self.entry.pk,))
318 
319     def get_context_data(self, **kwargs):
320         context = super().get_context_data(**kwargs)
321 
322         context["success"] = self.success
323         try:
324             context["name"] = self.entry.registration.get_full_name()
325         except Registration.DoesNotExist:
326             context["name"] = self.entry.renewal.member.get_full_name()
327 
328         return context
329 
330     def dispatch(self, request, *args, **kwargs):
331         self.entry = get_object_or_404(Entry, pk=kwargs.get("pk"))
332 
333         if (
334             self.entry.no_references
335             or self.entry.membership_type != Membership.BENEFACTOR
336         ):
337             raise Http404
338 
339         return super().dispatch(request, *args, **kwargs)
340 
341     def post(self, request, *args, **kwargs):
342         request.POST = request.POST.dict()
343         request.POST["member"] = request.member.pk
344         request.POST["entry"] = kwargs["pk"]
345         return super().post(request, *args, **kwargs)
346
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/website/registrations/views.py b/website/registrations/views.py
--- a/website/registrations/views.py
+++ b/website/registrations/views.py
@@ -235,7 +235,7 @@
         if (
             self.request.member.latest_membership
             and not self.request.member.latest_membership.is_active()
-        ) and self.request.member.profile.is_minimised:
+        ) and self.request.member.profile.is_minimized:
             messages.warning(
                 self.request,
                 _(

{"golden_diff": "diff --git a/website/registrations/views.py b/website/registrations/views.py\n--- a/website/registrations/views.py\n+++ b/website/registrations/views.py\n@@ -235,7 +235,7 @@\n         if (\n             self.request.member.latest_membership\n             and not self.request.member.latest_membership.is_active()\n-        ) and self.request.member.profile.is_minimised:\n+        ) and self.request.member.profile.is_minimized:\n             messages.warning(\n                 self.request,\n                 _(\n", "issue": "AttributeError: 'Profile' object has no attribute 'is_minimised'\nSentry Issue: [CONCREXIT-P2](https://thalia.sentry.io/issues/4038068631/?referrer=github_integration)\n\n```\nAttributeError: 'Profile' object has no attribute 'is_minimised'\n(3 additional frame(s) were not displayed)\n...\n  File \"registrations/views.py\", line 238, in get_context_data\n    ) and self.request.member.profile.is_minimised:\n```\n", "before_files": [{"content": "\"\"\"Views provided by the registrations package.\"\"\"\nfrom django.conf import settings\nfrom django.contrib import messages\nfrom django.contrib.admin.utils import model_ngettext\nfrom django.contrib.admin.views.decorators import staff_member_required\nfrom django.contrib.auth.decorators import login_required, permission_required\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.core.exceptions import ValidationError\nfrom django.db.models import Q\nfrom django.http import Http404\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.template.defaultfilters import floatformat\nfrom django.urls import reverse\nfrom django.utils import timezone\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import gettext_lazy as _\nfrom django.views import View\nfrom django.views.generic import CreateView, FormView\nfrom django.views.generic.base import TemplateResponseMixin, TemplateView\n\nfrom members.decorators import membership_required\nfrom members.models import Membership\n\nfrom . import emails, forms, services\nfrom .models import Entry, Reference, Registration, Renewal\n\n\nclass BecomeAMemberView(TemplateView):\n    \"\"\"View that render a HTML template with context data.\"\"\"\n\n    template_name = \"registrations/become_a_member.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"year_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2\n        )\n        context[\"study_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2\n        )\n        return context\n\n\n@method_decorator(staff_member_required, name=\"dispatch\")\n@method_decorator(\n    permission_required(\"registrations.review_entries\"),\n    name=\"dispatch\",\n)\nclass EntryAdminView(View):\n    \"\"\"View that handles the processing of entries.\"\"\"\n\n    def post(self, request, *args, **kwargs):\n        action = request.POST.get(\"action\")\n        entry_qs = Entry.objects.filter(pk=kwargs[\"pk\"])\n        try:\n            entry = entry_qs.get()\n        except Entry.DoesNotExist:\n            return redirect(\"admin:index\")\n\n        if action == \"accept\":\n            if not services.check_unique_user(entry):\n                messages.error(\n                    request,\n                    _(\"Could not accept %s. Username is not unique.\")\n                    % model_ngettext(entry, 1),\n                )\n            elif services.accept_entries(request.user.pk, entry_qs) > 0:\n                messages.success(\n                    request, _(\"Successfully accepted %s.\") % model_ngettext(entry, 1)\n                )\n            else:\n                messages.error(\n                    request, _(\"Could not accept %s.\") % model_ngettext(entry, 1)\n                )\n        elif action == \"reject\":\n            if services.reject_entries(request.user.pk, entry_qs) > 0:\n                messages.success(\n                    request, _(\"Successfully rejected %s.\") % model_ngettext(entry, 1)\n                )\n            else:\n                messages.error(\n                    request, _(\"Could not reject %s.\") % model_ngettext(entry, 1)\n                )\n        elif action == \"resend\":\n            try:\n                emails.send_registration_email_confirmation(entry.registration)\n            except Registration.DoesNotExist:\n                pass\n        elif action == \"revert\":\n            services.revert_entry(request.user.pk, entry)\n\n        if entry_qs.filter(renewal=None).exists():\n            content_type = ContentType.objects.get_for_model(Registration)\n        else:\n            content_type = ContentType.objects.get_for_model(Renewal)\n\n        return redirect(\n            f\"admin:{content_type.app_label}_{content_type.model}_change\",\n            kwargs[\"pk\"],\n        )\n\n\nclass ConfirmEmailView(View, TemplateResponseMixin):\n    \"\"\"View that renders an HTML template and confirms the email address of the provided registration.\"\"\"\n\n    template_name = \"registrations/confirm_email.html\"\n\n    def get(self, request, *args, **kwargs):\n        queryset = Registration.objects.filter(pk=kwargs[\"pk\"])\n\n        processed = 0\n        try:\n            processed = services.confirm_entry(queryset)\n        except ValidationError:\n            pass\n\n        if processed == 0:\n            return redirect(\"registrations:register-member\")\n\n        registration = queryset.get()\n\n        if (\n            registration.membership_type == Membership.BENEFACTOR\n            and not registration.no_references\n        ):\n            emails.send_references_information_message(registration)\n\n        emails.send_new_registration_board_message(registration)\n\n        return self.render_to_response({})\n\n\nclass BaseRegistrationFormView(FormView):\n    \"\"\"View that renders a membership registration form.\"\"\"\n\n    form_class = forms.MemberRegistrationForm\n    template_name = \"registrations/register_member.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"google_api_key\"] = settings.GOOGLE_PLACES_API_KEY\n        context[\"year_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2\n        )\n        context[\"study_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2\n        )\n        return context\n\n    def get(self, request, *args, **kwargs):\n        if request.user.is_authenticated:\n            return redirect(\"registrations:renew\")\n        return super().get(request, args, kwargs)\n\n    def form_valid(self, form):\n        form.save()\n        emails.send_registration_email_confirmation(form.instance)\n        return redirect(\"registrations:register-success\")\n\n\nclass MemberRegistrationFormView(BaseRegistrationFormView):\n    \"\"\"View that renders the `member` membership registration form.\"\"\"\n\n    form_class = forms.MemberRegistrationForm\n    template_name = \"registrations/register_member.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"tpay_enabled\"] = (\n            settings.THALIA_PAY_ENABLED_PAYMENT_METHOD\n            and settings.THALIA_PAY_FOR_NEW_MEMBERS\n        )\n        return context\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        request.POST[\"language\"] = request.LANGUAGE_CODE\n        request.POST[\"membership_type\"] = Membership.MEMBER\n        return super().post(request, *args, **kwargs)\n\n\nclass BenefactorRegistrationFormView(BaseRegistrationFormView):\n    \"\"\"View that renders the `benefactor` membership registration form.\"\"\"\n\n    form_class = forms.BenefactorRegistrationForm\n    template_name = \"registrations/register_benefactor.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"tpay_enabled\"] = (\n            settings.THALIA_PAY_ENABLED_PAYMENT_METHOD\n            and settings.THALIA_PAY_FOR_NEW_MEMBERS\n        )\n        return context\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        request.POST[\"language\"] = request.LANGUAGE_CODE\n        request.POST[\"membership_type\"] = Membership.BENEFACTOR\n        request.POST[\"length\"] = Entry.MEMBERSHIP_YEAR\n        request.POST[\"remarks\"] = (\n            \"Registered as iCIS employee\" if \"icis_employee\" in request.POST else \"\"\n        )\n        request.POST[\"no_references\"] = \"icis_employee\" in request.POST\n        return super().post(request, *args, **kwargs)\n\n\n@method_decorator(login_required, name=\"dispatch\")\nclass RenewalFormView(FormView):\n    \"\"\"View that renders the membership renewal form.\"\"\"\n\n    form_class = forms.RenewalForm\n    template_name = \"registrations/renewal.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"year_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2\n        )\n        context[\"study_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2\n        )\n        context[\"latest_membership\"] = self.request.member.latest_membership\n        context[\"latest_renewal\"] = Renewal.objects.filter(\n            Q(member=self.request.member)\n            & (\n                Q(status=Registration.STATUS_ACCEPTED)\n                | Q(status=Registration.STATUS_REVIEW)\n            )\n        ).last()\n        context[\"was_member\"] = Membership.objects.filter(\n            user=self.request.member, type=Membership.MEMBER\n        ).exists()\n\n        if (\n            self.request.member.latest_membership\n            and not self.request.member.latest_membership.is_active()\n        ) and self.request.member.profile.is_minimised:\n            messages.warning(\n                self.request,\n                _(\n                    \"You seem to have been a member in the past, but your profile data has been deleted. Please contact the board to renew your membership.\"\n                ),\n            )\n        context[\"benefactor_type\"] = Membership.BENEFACTOR\n        return context\n\n    def get_form(self, form_class=None):\n        form = super().get_form(form_class)\n        member = self.request.member\n        if member is not None and member.latest_membership is not None:\n            latest_membership = member.latest_membership\n            # If latest membership has not ended or does not ends\n            # within 1 month: do not show 'year' length and disable benefactor option\n            hide_year_choice = not (\n                latest_membership is not None\n                and latest_membership.until is not None\n                and (latest_membership.until - timezone.now().date()).days <= 31\n            )\n\n            if hide_year_choice:\n                form.fields[\"length\"].choices = [\n                    c\n                    for c in form.fields[\"length\"].choices\n                    if c[0] != Entry.MEMBERSHIP_YEAR\n                ]\n                form.fields[\"membership_type\"].choices = [\n                    c\n                    for c in form.fields[\"membership_type\"].choices\n                    if c[0] != Membership.BENEFACTOR\n                ]\n\n        return form\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        if request.member.latest_membership.type == Membership.BENEFACTOR:\n            request.POST[\"membership_type\"] = Membership.BENEFACTOR\n            request.POST[\"length\"] = Entry.MEMBERSHIP_YEAR\n        request.POST[\"member\"] = request.member.pk\n        request.POST[\"remarks\"] = \"\"\n        request.POST[\"no_references\"] = True\n\n        if request.POST[\"membership_type\"] == Membership.BENEFACTOR:\n            request.POST[\"no_references\"] = False\n            if Membership.objects.filter(\n                user=request.member, type=Membership.MEMBER\n            ).exists():\n                request.POST[\"remarks\"] = \"Was a Thalia member in the past.\"\n                request.POST[\"no_references\"] = True\n            if \"icis_employee\" in request.POST:\n                request.POST[\"remarks\"] = \"Registered as iCIS employee.\"\n                request.POST[\"no_references\"] = True\n\n        return super().post(request, *args, **kwargs)\n\n    def form_valid(self, form):\n        renewal = form.save()\n        if not renewal.no_references:\n            emails.send_references_information_message(renewal)\n        emails.send_new_renewal_board_message(renewal)\n        return redirect(\"registrations:renew-success\")\n\n\n@method_decorator(login_required, name=\"dispatch\")\n@method_decorator(membership_required, name=\"dispatch\")\nclass ReferenceCreateView(CreateView):\n    \"\"\"View that renders a reference creation form.\"\"\"\n\n    model = Reference\n    form_class = forms.ReferenceForm\n    template_name = \"registrations/reference.html\"\n    entry = None\n    success = False\n\n    def get_success_url(self):\n        return reverse(\"registrations:reference-success\", args=(self.entry.pk,))\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n\n        context[\"success\"] = self.success\n        try:\n            context[\"name\"] = self.entry.registration.get_full_name()\n        except Registration.DoesNotExist:\n            context[\"name\"] = self.entry.renewal.member.get_full_name()\n\n        return context\n\n    def dispatch(self, request, *args, **kwargs):\n        self.entry = get_object_or_404(Entry, pk=kwargs.get(\"pk\"))\n\n        if (\n            self.entry.no_references\n            or self.entry.membership_type != Membership.BENEFACTOR\n        ):\n            raise Http404\n\n        return super().dispatch(request, *args, **kwargs)\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        request.POST[\"member\"] = request.member.pk\n        request.POST[\"entry\"] = kwargs[\"pk\"]\n        return super().post(request, *args, **kwargs)\n", "path": "website/registrations/views.py"}], "after_files": [{"content": "\"\"\"Views provided by the registrations package.\"\"\"\nfrom django.conf import settings\nfrom django.contrib import messages\nfrom django.contrib.admin.utils import model_ngettext\nfrom django.contrib.admin.views.decorators import staff_member_required\nfrom django.contrib.auth.decorators import login_required, permission_required\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.core.exceptions import ValidationError\nfrom django.db.models import Q\nfrom django.http import Http404\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.template.defaultfilters import floatformat\nfrom django.urls import reverse\nfrom django.utils import timezone\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import gettext_lazy as _\nfrom django.views import View\nfrom django.views.generic import CreateView, FormView\nfrom django.views.generic.base import TemplateResponseMixin, TemplateView\n\nfrom members.decorators import membership_required\nfrom members.models import Membership\n\nfrom . import emails, forms, services\nfrom .models import Entry, Reference, Registration, Renewal\n\n\nclass BecomeAMemberView(TemplateView):\n    \"\"\"View that render a HTML template with context data.\"\"\"\n\n    template_name = \"registrations/become_a_member.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"year_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2\n        )\n        context[\"study_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2\n        )\n        return context\n\n\n@method_decorator(staff_member_required, name=\"dispatch\")\n@method_decorator(\n    permission_required(\"registrations.review_entries\"),\n    name=\"dispatch\",\n)\nclass EntryAdminView(View):\n    \"\"\"View that handles the processing of entries.\"\"\"\n\n    def post(self, request, *args, **kwargs):\n        action = request.POST.get(\"action\")\n        entry_qs = Entry.objects.filter(pk=kwargs[\"pk\"])\n        try:\n            entry = entry_qs.get()\n        except Entry.DoesNotExist:\n            return redirect(\"admin:index\")\n\n        if action == \"accept\":\n            if not services.check_unique_user(entry):\n                messages.error(\n                    request,\n                    _(\"Could not accept %s. Username is not unique.\")\n                    % model_ngettext(entry, 1),\n                )\n            elif services.accept_entries(request.user.pk, entry_qs) > 0:\n                messages.success(\n                    request, _(\"Successfully accepted %s.\") % model_ngettext(entry, 1)\n                )\n            else:\n                messages.error(\n                    request, _(\"Could not accept %s.\") % model_ngettext(entry, 1)\n                )\n        elif action == \"reject\":\n            if services.reject_entries(request.user.pk, entry_qs) > 0:\n                messages.success(\n                    request, _(\"Successfully rejected %s.\") % model_ngettext(entry, 1)\n                )\n            else:\n                messages.error(\n                    request, _(\"Could not reject %s.\") % model_ngettext(entry, 1)\n                )\n        elif action == \"resend\":\n            try:\n                emails.send_registration_email_confirmation(entry.registration)\n            except Registration.DoesNotExist:\n                pass\n        elif action == \"revert\":\n            services.revert_entry(request.user.pk, entry)\n\n        if entry_qs.filter(renewal=None).exists():\n            content_type = ContentType.objects.get_for_model(Registration)\n        else:\n            content_type = ContentType.objects.get_for_model(Renewal)\n\n        return redirect(\n            f\"admin:{content_type.app_label}_{content_type.model}_change\",\n            kwargs[\"pk\"],\n        )\n\n\nclass ConfirmEmailView(View, TemplateResponseMixin):\n    \"\"\"View that renders an HTML template and confirms the email address of the provided registration.\"\"\"\n\n    template_name = \"registrations/confirm_email.html\"\n\n    def get(self, request, *args, **kwargs):\n        queryset = Registration.objects.filter(pk=kwargs[\"pk\"])\n\n        processed = 0\n        try:\n            processed = services.confirm_entry(queryset)\n        except ValidationError:\n            pass\n\n        if processed == 0:\n            return redirect(\"registrations:register-member\")\n\n        registration = queryset.get()\n\n        if (\n            registration.membership_type == Membership.BENEFACTOR\n            and not registration.no_references\n        ):\n            emails.send_references_information_message(registration)\n\n        emails.send_new_registration_board_message(registration)\n\n        return self.render_to_response({})\n\n\nclass BaseRegistrationFormView(FormView):\n    \"\"\"View that renders a membership registration form.\"\"\"\n\n    form_class = forms.MemberRegistrationForm\n    template_name = \"registrations/register_member.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"google_api_key\"] = settings.GOOGLE_PLACES_API_KEY\n        context[\"year_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2\n        )\n        context[\"study_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2\n        )\n        return context\n\n    def get(self, request, *args, **kwargs):\n        if request.user.is_authenticated:\n            return redirect(\"registrations:renew\")\n        return super().get(request, args, kwargs)\n\n    def form_valid(self, form):\n        form.save()\n        emails.send_registration_email_confirmation(form.instance)\n        return redirect(\"registrations:register-success\")\n\n\nclass MemberRegistrationFormView(BaseRegistrationFormView):\n    \"\"\"View that renders the `member` membership registration form.\"\"\"\n\n    form_class = forms.MemberRegistrationForm\n    template_name = \"registrations/register_member.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"tpay_enabled\"] = (\n            settings.THALIA_PAY_ENABLED_PAYMENT_METHOD\n            and settings.THALIA_PAY_FOR_NEW_MEMBERS\n        )\n        return context\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        request.POST[\"language\"] = request.LANGUAGE_CODE\n        request.POST[\"membership_type\"] = Membership.MEMBER\n        return super().post(request, *args, **kwargs)\n\n\nclass BenefactorRegistrationFormView(BaseRegistrationFormView):\n    \"\"\"View that renders the `benefactor` membership registration form.\"\"\"\n\n    form_class = forms.BenefactorRegistrationForm\n    template_name = \"registrations/register_benefactor.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"tpay_enabled\"] = (\n            settings.THALIA_PAY_ENABLED_PAYMENT_METHOD\n            and settings.THALIA_PAY_FOR_NEW_MEMBERS\n        )\n        return context\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        request.POST[\"language\"] = request.LANGUAGE_CODE\n        request.POST[\"membership_type\"] = Membership.BENEFACTOR\n        request.POST[\"length\"] = Entry.MEMBERSHIP_YEAR\n        request.POST[\"remarks\"] = (\n            \"Registered as iCIS employee\" if \"icis_employee\" in request.POST else \"\"\n        )\n        request.POST[\"no_references\"] = \"icis_employee\" in request.POST\n        return super().post(request, *args, **kwargs)\n\n\n@method_decorator(login_required, name=\"dispatch\")\nclass RenewalFormView(FormView):\n    \"\"\"View that renders the membership renewal form.\"\"\"\n\n    form_class = forms.RenewalForm\n    template_name = \"registrations/renewal.html\"\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"year_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_YEAR], 2\n        )\n        context[\"study_fees\"] = floatformat(\n            settings.MEMBERSHIP_PRICES[Entry.MEMBERSHIP_STUDY], 2\n        )\n        context[\"latest_membership\"] = self.request.member.latest_membership\n        context[\"latest_renewal\"] = Renewal.objects.filter(\n            Q(member=self.request.member)\n            & (\n                Q(status=Registration.STATUS_ACCEPTED)\n                | Q(status=Registration.STATUS_REVIEW)\n            )\n        ).last()\n        context[\"was_member\"] = Membership.objects.filter(\n            user=self.request.member, type=Membership.MEMBER\n        ).exists()\n\n        if (\n            self.request.member.latest_membership\n            and not self.request.member.latest_membership.is_active()\n        ) and self.request.member.profile.is_minimized:\n            messages.warning(\n                self.request,\n                _(\n                    \"You seem to have been a member in the past, but your profile data has been deleted. Please contact the board to renew your membership.\"\n                ),\n            )\n        context[\"benefactor_type\"] = Membership.BENEFACTOR\n        return context\n\n    def get_form(self, form_class=None):\n        form = super().get_form(form_class)\n        member = self.request.member\n        if member is not None and member.latest_membership is not None:\n            latest_membership = member.latest_membership\n            # If latest membership has not ended or does not ends\n            # within 1 month: do not show 'year' length and disable benefactor option\n            hide_year_choice = not (\n                latest_membership is not None\n                and latest_membership.until is not None\n                and (latest_membership.until - timezone.now().date()).days <= 31\n            )\n\n            if hide_year_choice:\n                form.fields[\"length\"].choices = [\n                    c\n                    for c in form.fields[\"length\"].choices\n                    if c[0] != Entry.MEMBERSHIP_YEAR\n                ]\n                form.fields[\"membership_type\"].choices = [\n                    c\n                    for c in form.fields[\"membership_type\"].choices\n                    if c[0] != Membership.BENEFACTOR\n                ]\n\n        return form\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        if request.member.latest_membership.type == Membership.BENEFACTOR:\n            request.POST[\"membership_type\"] = Membership.BENEFACTOR\n            request.POST[\"length\"] = Entry.MEMBERSHIP_YEAR\n        request.POST[\"member\"] = request.member.pk\n        request.POST[\"remarks\"] = \"\"\n        request.POST[\"no_references\"] = True\n\n        if request.POST[\"membership_type\"] == Membership.BENEFACTOR:\n            request.POST[\"no_references\"] = False\n            if Membership.objects.filter(\n                user=request.member, type=Membership.MEMBER\n            ).exists():\n                request.POST[\"remarks\"] = \"Was a Thalia member in the past.\"\n                request.POST[\"no_references\"] = True\n            if \"icis_employee\" in request.POST:\n                request.POST[\"remarks\"] = \"Registered as iCIS employee.\"\n                request.POST[\"no_references\"] = True\n\n        return super().post(request, *args, **kwargs)\n\n    def form_valid(self, form):\n        renewal = form.save()\n        if not renewal.no_references:\n            emails.send_references_information_message(renewal)\n        emails.send_new_renewal_board_message(renewal)\n        return redirect(\"registrations:renew-success\")\n\n\n@method_decorator(login_required, name=\"dispatch\")\n@method_decorator(membership_required, name=\"dispatch\")\nclass ReferenceCreateView(CreateView):\n    \"\"\"View that renders a reference creation form.\"\"\"\n\n    model = Reference\n    form_class = forms.ReferenceForm\n    template_name = \"registrations/reference.html\"\n    entry = None\n    success = False\n\n    def get_success_url(self):\n        return reverse(\"registrations:reference-success\", args=(self.entry.pk,))\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n\n        context[\"success\"] = self.success\n        try:\n            context[\"name\"] = self.entry.registration.get_full_name()\n        except Registration.DoesNotExist:\n            context[\"name\"] = self.entry.renewal.member.get_full_name()\n\n        return context\n\n    def dispatch(self, request, *args, **kwargs):\n        self.entry = get_object_or_404(Entry, pk=kwargs.get(\"pk\"))\n\n        if (\n            self.entry.no_references\n            or self.entry.membership_type != Membership.BENEFACTOR\n        ):\n            raise Http404\n\n        return super().dispatch(request, *args, **kwargs)\n\n    def post(self, request, *args, **kwargs):\n        request.POST = request.POST.dict()\n        request.POST[\"member\"] = request.member.pk\n        request.POST[\"entry\"] = kwargs[\"pk\"]\n        return super().post(request, *args, **kwargs)\n", "path": "website/registrations/views.py"}]}