From 19456756e4cab8b663ade488b3ab8b38bc441e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 6 Aug 2016 15:34:01 +0200 Subject: [PATCH 1/5] =?UTF-8?q?Cache=20les=20vieux=20=C3=A9v=C3=A9nements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestioncof/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gestioncof/views.py b/gestioncof/views.py index be0adb35..ed35efa7 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -188,7 +188,7 @@ def update_event_form_comments(event, form, registration): @login_required def event(request, event_id): event = get_object_or_404(Event, id=event_id) - if not event.registration_open: + if (not event.registration_open) or event.old: raise Http404 success = False if request.method == "POST": From b60b9f4e17827fd4d79c6b35b1d247b0ea571e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 7 Aug 2016 18:47:59 +0200 Subject: [PATCH 2/5] Utilisation d'un formset pour l'inscription - Changements mineurs dans `AdminEventForm` - Ajout d'une base pour le formset : `BaseEventRegistrationFormset` - Adaptation des vues de l'inscription et suppression d'une vue inutile. --- gestioncof/forms.py | 32 +++++-- gestioncof/templates/registration_form.html | 9 +- gestioncof/views.py | 95 ++++++--------------- 3 files changed, 54 insertions(+), 82 deletions(-) diff --git a/gestioncof/forms.py b/gestioncof/forms.py index 15db25ce..7aac9e5f 100644 --- a/gestioncof/forms.py +++ b/gestioncof/forms.py @@ -8,6 +8,7 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User from django.forms.widgets import RadioSelect, CheckboxSelectMultiple +from django.forms.formsets import BaseFormSet from django.db.models import Max from gestioncof.models import CofProfile, EventCommentValue, \ @@ -263,17 +264,15 @@ STATUS_CHOICES = (('no', 'Non'), class AdminEventForm(forms.Form): - status = forms.ChoiceField(label="Inscription", + status = forms.ChoiceField(label="Inscription", initial="no", choices=STATUS_CHOICES, widget=RadioSelect) def __init__(self, *args, **kwargs): - event = kwargs.pop("event") - self.event = event + self.event = kwargs.pop("event") registration = kwargs.pop("current_registration", None) - current_choices = \ - registration.options.all() if registration is not None\ - else [] - paid = kwargs.pop("paid", None) + current_choices, paid = \ + (registration.options.all(), registration.paid) \ + if registration is not None else ([], None) if paid is True: kwargs["initial"] = {"status": "paid"} elif paid is False: @@ -288,7 +287,7 @@ class AdminEventForm(forms.Form): else: choices[choice.event_option.id].append(choice.id) all_choices = choices - for option in event.options.all(): + for option in self.event.options.all(): choices = [(choice.id, choice.value) for choice in option.choices.all()] if option.multi_choices: @@ -310,7 +309,7 @@ class AdminEventForm(forms.Form): initial=initial) field.option_id = option.id self.fields["option_%d" % option.id] = field - for commentfield in event.commentfields.all(): + for commentfield in self.event.commentfields.all(): initial = commentfield.default if registration is not None: try: @@ -338,6 +337,21 @@ class AdminEventForm(forms.Form): yield (self.fields[name].comment_id, value) +class BaseEventRegistrationFormset(BaseFormSet): + def __init__(self, *args, **kwargs): + self.events = kwargs.pop('events') + self.current_registrations = kwargs.pop('current_registrations', None) + self.extra = len(self.events) + super(BaseEventRegistrationFormset, self).__init__(*args, **kwargs) + + def _construct_form(self, index, **kwargs): + kwargs['event'] = self.events[index] + if self.current_registrations is not None: + kwargs['current_registration'] = self.current_registrations[index] + return super(BaseEventRegistrationFormset, self)._construct_form( + index, **kwargs) + + class CalendarForm(forms.ModelForm): subscribe_to_events = forms.BooleanField( initial=True, diff --git a/gestioncof/templates/registration_form.html b/gestioncof/templates/registration_form.html index b9699647..1eb16393 100644 --- a/gestioncof/templates/registration_form.html +++ b/gestioncof/templates/registration_form.html @@ -12,16 +12,15 @@ {{ user_form | bootstrap }} {{ profile_form | bootstrap }} - {% if event_forms %}
- {% for event_form in event_forms %} + {{ event_formset.management_form }} + {% for event_form in event_formset %}
-

Inscription {{ event_form.event.title }} :

+

Inscription {{ event_form.event.title }} :

- {{ event_form | bootstrap }} + {{ event_form | bootstrap }}
{% endfor %} - {% endif %} {% if login_clipper or member %} {% endif %} diff --git a/gestioncof/views.py b/gestioncof/views.py index ed35efa7..1b8019a2 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -14,6 +14,7 @@ from django.http import Http404, HttpResponse from django.contrib.auth.decorators import login_required from django.contrib.auth.views import login as django_login_view from django.contrib.auth.models import User +from django.forms.models import formset_factory import django.utils.six as six from gestioncof.models import Survey, SurveyAnswer, SurveyQuestion, \ @@ -27,7 +28,8 @@ from gestioncof.models import CofProfile, Clipper from gestioncof.decorators import buro_required, cof_required from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \ SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \ - RegistrationProfileForm, AdminEventForm, EventForm, CalendarForm + RegistrationProfileForm, AdminEventForm, EventForm, CalendarForm, \ + BaseEventRegistrationFormset from bda.models import Tirage, Spectacle @@ -313,49 +315,12 @@ def registration_set_ro_fields(user_form, profile_form): profile_form.fields['login_clipper'].widget.attrs['readonly'] = True -@buro_required -def registration_form(request, login_clipper=None, username=None): - member = None - if login_clipper: - clipper = get_object_or_404(Clipper, username=login_clipper) - try: # check if the given user is already registered - member = User.objects.filter(username=login_clipper).get() - username = member.username - login_clipper = None - except User.DoesNotExist: - # new user, but prefill - user_form = RegistrationUserForm() - profile_form = RegistrationProfileForm() - user_form.fields['username'].initial = login_clipper - user_form.fields['email'].initial = \ - login_clipper + "@clipper.ens.fr" - profile_form.fields['login_clipper'].initial = login_clipper - if clipper.fullname: - bits = clipper.fullname.split(" ") - user_form.fields['first_name'].initial = bits[0] - if len(bits) > 1: - user_form.fields['last_name'].initial = " ".join(bits[1:]) - registration_set_ro_fields(user_form, profile_form) - if username: - member = get_object_or_404(User, username=username) - (profile, _) = CofProfile.objects.get_or_create(user=member) - # already existing, prefill - user_form = RegistrationUserForm(instance=member) - profile_form = RegistrationProfileForm(instance=profile) - registration_set_ro_fields(user_form, profile_form) - elif not login_clipper: - # new user - user_form = RegistrationUserForm() - profile_form = RegistrationProfileForm() - return render(request, "registration_form.html", - {"user_form": user_form, "profile_form": profile_form, - "member": member, "login_clipper": login_clipper}) - - @buro_required def registration_form2(request, login_clipper=None, username=None): events = Event.objects.filter(old=False).all() member = None + EventFormset = formset_factory(AdminEventForm, + BaseEventRegistrationFormset) if login_clipper: clipper = get_object_or_404(Clipper, username=login_clipper) try: # check if the given user is already registered @@ -366,10 +331,10 @@ def registration_form2(request, login_clipper=None, username=None): # new user, but prefill user_form = RegistrationUserForm() profile_form = RegistrationProfileForm() - event_forms = [AdminEventForm(event=event) for event in events] + event_formset = EventFormset(events=events, prefix='events') user_form.fields['username'].initial = login_clipper - user_form.fields['email'].initial = \ - login_clipper + "@clipper.ens.fr" + user_form.fields['email'].initial = "%s@clipper.ens.fr" \ + % login_clipper profile_form.fields['login_clipper'].initial = login_clipper if clipper.fullname: bits = clipper.fullname.split(" ") @@ -384,27 +349,25 @@ def registration_form2(request, login_clipper=None, username=None): user_form = RegistrationUserForm(instance=member) profile_form = RegistrationProfileForm(instance=profile) registration_set_ro_fields(user_form, profile_form) - event_forms = [] + current_registrations = [] for event in events: try: - current_registration = EventRegistration.objects.get( - user=member, event=event) - form = AdminEventForm( - event=event, - current_registration=current_registration, - paid=current_registration.paid) + current_registrations.append( + EventRegistration.objects.get(user=member, event=event)) except EventRegistration.DoesNotExist: - form = AdminEventForm(event=event) - event_forms.append(form) + current_registrations.append(None) + event_formset = EventFormset( + events=events, prefix='events', + current_registrations=current_registrations) elif not login_clipper: # new user user_form = RegistrationUserForm() profile_form = RegistrationProfileForm() - event_forms = [AdminEventForm(event=event) for event in events] + event_formset = EventFormset(events=events, prefix='events') return render(request, "registration_form.html", {"user_form": user_form, "profile_form": profile_form, "member": member, "login_clipper": login_clipper, - "event_forms": event_forms}) + "event_formset": event_formset}) @buro_required @@ -417,12 +380,13 @@ def registration(request): user_form = RegistrationUserForm(request_dict) profile_form = RegistrationProfileForm(request_dict) events = Event.objects.filter(old=False).all() - event_forms = \ - [AdminEventForm(request_dict, event=event) for event in events] + EventFormset = formset_factory(AdminEventForm, + BaseEventRegistrationFormset) + event_formset = EventFormset(events=events, data=request_dict, + prefix='events') user_form.is_valid() profile_form.is_valid() - for event_form in event_forms: - event_form.is_valid() + event_formset.is_valid() member = None login_clipper = None if "user_exists" in request_dict and request_dict["user_exists"]: @@ -439,26 +403,21 @@ def registration(request): login_clipper = clipper.username except Clipper.DoesNotExist: pass - for form in event_forms: - if not form.is_valid(): - break - if form.cleaned_data['status'] == 'no': - continue - all_choices = get_event_form_choices(form.event, form) if user_form.is_valid() and profile_form.is_valid() \ - and not any([not form.is_valid() for form in event_forms]): + and event_formset.is_valid(): member = user_form.save() (profile, _) = CofProfile.objects.get_or_create(user=member) was_cof = profile.is_cof request_dict["num"] = profile.num profile_form = RegistrationProfileForm(request_dict, instance=profile) - profile_form.is_valid() profile_form.save() (profile, _) = CofProfile.objects.get_or_create(user=member) if profile.is_cof and not was_cof: send_custom_mail(member, "bienvenue") - for form in event_forms: + for form in event_formset: + if 'status' not in form.cleaned_data: + form.cleaned_data['status'] = 'no' if form.cleaned_data['status'] == 'no': try: current_registration = EventRegistration.objects.get( @@ -494,7 +453,7 @@ def registration(request): "profile_form": profile_form, "member": member, "login_clipper": login_clipper, - "event_forms": event_forms}) + "event_formset": event_formset}) else: return render(request, "registration.html") From 23ac3b722257e4379c7be1d5759698d23137e8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 13 Aug 2016 02:56:42 +0200 Subject: [PATCH 3/5] Nettoyage --- gestioncof/views.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gestioncof/views.py b/gestioncof/views.py index 263cad32..e632011a 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -320,30 +320,32 @@ def registration_set_ro_fields(user_form, profile_form): @buro_required def registration_form2(request, login_clipper=None, username=None): events = Event.objects.filter(old=False).all() - member = None EventFormset = formset_factory(AdminEventForm, BaseEventRegistrationFormset) + member = None if login_clipper: clipper = get_object_or_404(Clipper, username=login_clipper) try: # check if the given user is already registered - member = User.objects.filter(username=login_clipper).get() + member = User.objects.get(username=login_clipper) username = member.username login_clipper = None except User.DoesNotExist: # new user, but prefill - user_form = RegistrationUserForm() - profile_form = RegistrationProfileForm() - event_formset = EventFormset(events=events, prefix='events') - user_form.fields['username'].initial = login_clipper - user_form.fields['email'].initial = "%s@clipper.ens.fr" \ - % login_clipper - profile_form.fields['login_clipper'].initial = login_clipper + # user + user_form = RegistrationUserForm(initial={ + 'username': login_clipper, + 'email': "%s@clipper.ens.fr" % login_clipper}) if clipper.fullname: bits = clipper.fullname.split(" ") user_form.fields['first_name'].initial = bits[0] if len(bits) > 1: user_form.fields['last_name'].initial = " ".join(bits[1:]) + # profile + profile_form = RegistrationProfileForm(initial={ + 'login_clipper': login_clipper}) registration_set_ro_fields(user_form, profile_form) + # events + event_formset = EventFormset(events=events, prefix='events') if username: member = get_object_or_404(User, username=username) (profile, _) = CofProfile.objects.get_or_create(user=member) @@ -351,6 +353,7 @@ def registration_form2(request, login_clipper=None, username=None): user_form = RegistrationUserForm(instance=member) profile_form = RegistrationProfileForm(instance=profile) registration_set_ro_fields(user_form, profile_form) + # events current_registrations = [] for event in events: try: @@ -376,6 +379,7 @@ def registration_form2(request, login_clipper=None, username=None): def registration(request): if request.POST: request_dict = request.POST.copy() + # num ne peut pas être définit manuellement if "num" in request_dict: del request_dict["num"] success = False From 12a4b8efa74d6c63a203e37019b6574e1f518372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 14 Aug 2016 12:10:50 +0200 Subject: [PATCH 4/5] Petits changements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ajout d'un FIXME dans `gestioncof/forms.py` au niveua de la surcharge de la méthode privée `_construct_form` : ce trick ne sera plus nécessaire à partir de Django 1.9 - Utilisation correcte des `form.is_valid` dans `gestioncof.views.registration` --- gestioncof/views.py | 108 +++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/gestioncof/views.py b/gestioncof/views.py index e632011a..4ba41061 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -379,80 +379,84 @@ def registration_form2(request, login_clipper=None, username=None): def registration(request): if request.POST: request_dict = request.POST.copy() - # num ne peut pas être définit manuellement + member = None + login_clipper = None + success = False + events = Event.objects.filter(old=False).all() + # num ne peut pas être défini manuellement if "num" in request_dict: del request_dict["num"] - success = False + + # ----- + # Remplissage des formulaires + # ----- + user_form = RegistrationUserForm(request_dict) - profile_form = RegistrationProfileForm(request_dict) - events = Event.objects.filter(old=False).all() EventFormset = formset_factory(AdminEventForm, BaseEventRegistrationFormset) event_formset = EventFormset(events=events, data=request_dict, prefix='events') - user_form.is_valid() - profile_form.is_valid() - event_formset.is_valid() - member = None - login_clipper = None if "user_exists" in request_dict and request_dict["user_exists"]: username = request_dict["username"] try: - member = User.objects.filter(username=username).get() - (profile, _) = CofProfile.objects.get_or_create(user=member) + member = User.objects.get(username=username) user_form = RegistrationUserForm(request_dict, instance=member) - profile_form = RegistrationProfileForm(request_dict, - instance=profile) except User.DoesNotExist: try: - clipper = Clipper.objects.filter(username=username).get() + clipper = Clipper.objects.get(username=username) login_clipper = clipper.username except Clipper.DoesNotExist: pass - if user_form.is_valid() and profile_form.is_valid() \ - and event_formset.is_valid(): + + # ----- + # Validation des formulaires + # ----- + + if user_form.is_valid(): member = user_form.save() - (profile, _) = CofProfile.objects.get_or_create(user=member) + profile, _ = CofProfile.objects.get_or_create(user=member) was_cof = profile.is_cof request_dict["num"] = profile.num + # Maintenant on remplit le formulaire de profil profile_form = RegistrationProfileForm(request_dict, instance=profile) - profile_form.save() - (profile, _) = CofProfile.objects.get_or_create(user=member) - if profile.is_cof and not was_cof: - send_custom_mail(member, "bienvenue") - for form in event_formset: - if 'status' not in form.cleaned_data: - form.cleaned_data['status'] = 'no' - if form.cleaned_data['status'] == 'no': - try: - current_registration = EventRegistration.objects.get( + if profile_form.is_valid() and event_formset.is_valid(): + profile = profile_form.save() + if profile.is_cof and not was_cof: + send_custom_mail(member, "bienvenue") + for form in event_formset: + if 'status' not in form.cleaned_data: + form.cleaned_data['status'] = 'no' + if form.cleaned_data['status'] == 'no': + try: + current_registration = EventRegistration.objects \ + .get(user=member, event=form.event) + current_registration.delete() + except EventRegistration.DoesNotExist: + pass + continue + all_choices = get_event_form_choices(form.event, form) + (current_registration, created_reg) = \ + EventRegistration.objects.get_or_create( user=member, event=form.event) - current_registration.delete() - except EventRegistration.DoesNotExist: - pass - continue - all_choices = get_event_form_choices(form.event, form) - (current_registration, created_reg) = \ - EventRegistration.objects.get_or_create(user=member, - event=form.event) - update_event_form_comments(form.event, form, - current_registration) - current_registration.options = all_choices - current_registration.paid = \ - (form.cleaned_data['status'] == 'paid') - current_registration.save() - if form.event.title == "Mega 15" and created_reg: - field = EventCommentField.objects.get(event=form.event, - name="Commentaires") - try: - comments = EventCommentValue.objects.get( - commentfield=field, - registration=current_registration).content - except EventCommentValue.DoesNotExist: - comments = field.default - send_custom_mail(member, "mega", {"remarques": comments}) - success = True + update_event_form_comments(form.event, form, + current_registration) + current_registration.options = all_choices + current_registration.paid = \ + (form.cleaned_data['status'] == 'paid') + current_registration.save() + if form.event.title == "Mega 15" and created_reg: + field = EventCommentField.objects.get( + event=form.event, name="Commentaires") + try: + comments = EventCommentValue.objects.get( + commentfield=field, + registration=current_registration).content + except EventCommentValue.DoesNotExist: + comments = field.default + send_custom_mail(member, "mega", + {"remarques": comments}) + success = True return render(request, "registration_post.html", {"success": success, "user_form": user_form, From 5b0b60fadb7a15d642831540b9c9ab7e2232e0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Wed, 17 Aug 2016 15:34:01 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Meilleure=20inscription=20des=20ext=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lors de la création d'un compte exté via la vue `/registration` (i.e. compte non associé à un clipper), deux champs sont ajoutés au formulaire pour la création d'un mot de passe. Il est toujours possible de changer ce mot de passe via l'admin s'il est perdu par l'utilisateur. --- gestioncof/forms.py | 29 ++++++++++++++++++++++++++++- gestioncof/views.py | 25 ++++++++++++------------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/gestioncof/forms.py b/gestioncof/forms.py index 7aac9e5f..5fb3d0b3 100644 --- a/gestioncof/forms.py +++ b/gestioncof/forms.py @@ -8,7 +8,7 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User from django.forms.widgets import RadioSelect, CheckboxSelectMultiple -from django.forms.formsets import BaseFormSet +from django.forms.formsets import BaseFormSet, formset_factory from django.db.models import Max from gestioncof.models import CofProfile, EventCommentValue, \ @@ -215,6 +215,32 @@ class RegistrationUserForm(forms.ModelForm): fields = ("username", "first_name", "last_name", "email") +class RegistrationPassUserForm(RegistrationUserForm): + """ + Formulaire pour changer le mot de passe d'un utilisateur. + """ + password1 = forms.CharField(label=_('Mot de passe'), + widget=forms.PasswordInput) + password2 = forms.CharField(label=_('Confirmation du mot de passe'), + widget=forms.PasswordInput) + + def clean_password2(self): + pass1 = self.cleaned_data['password1'] + pass2 = self.cleaned_data['password2'] + if pass1 and pass2: + if pass1 != pass2: + raise forms.ValidationError(_('Mots de passe non identiques.')) + return pass2 + + def save(self, commit=True, *args, **kwargs): + user = super(RegistrationPassUserForm, self).save(commit, *args, + **kwargs) + user.set_password(self.cleaned_data['password2']) + if commit: + user.save() + return user + + class RegistrationProfileForm(forms.ModelForm): def __init__(self, *args, **kw): super(RegistrationProfileForm, self).__init__(*args, **kw) @@ -350,6 +376,7 @@ class BaseEventRegistrationFormset(BaseFormSet): kwargs['current_registration'] = self.current_registrations[index] return super(BaseEventRegistrationFormset, self)._construct_form( index, **kwargs) +EventFormset = formset_factory(AdminEventForm, BaseEventRegistrationFormset) class CalendarForm(forms.ModelForm): diff --git a/gestioncof/views.py b/gestioncof/views.py index 4ba41061..5a665860 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -14,7 +14,6 @@ from django.http import Http404, HttpResponse from django.contrib.auth.decorators import login_required from django.contrib.auth.views import login as django_login_view from django.contrib.auth.models import User -from django.forms.models import formset_factory from django.utils import timezone import django.utils.six as six @@ -29,8 +28,8 @@ from gestioncof.models import CofProfile, Clipper from gestioncof.decorators import buro_required, cof_required from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \ SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \ - RegistrationProfileForm, AdminEventForm, EventForm, CalendarForm, \ - BaseEventRegistrationFormset + RegistrationProfileForm, EventForm, CalendarForm, EventFormset, \ + RegistrationPassUserForm from bda.models import Tirage, Spectacle @@ -320,8 +319,6 @@ def registration_set_ro_fields(user_form, profile_form): @buro_required def registration_form2(request, login_clipper=None, username=None): events = Event.objects.filter(old=False).all() - EventFormset = formset_factory(AdminEventForm, - BaseEventRegistrationFormset) member = None if login_clipper: clipper = get_object_or_404(Clipper, username=login_clipper) @@ -366,7 +363,7 @@ def registration_form2(request, login_clipper=None, username=None): current_registrations=current_registrations) elif not login_clipper: # new user - user_form = RegistrationUserForm() + user_form = RegistrationPassUserForm() profile_form = RegistrationProfileForm() event_formset = EventFormset(events=events, prefix='events') return render(request, "registration_form.html", @@ -379,21 +376,23 @@ def registration_form2(request, login_clipper=None, username=None): def registration(request): if request.POST: request_dict = request.POST.copy() - member = None - login_clipper = None - success = False - events = Event.objects.filter(old=False).all() # num ne peut pas être défini manuellement if "num" in request_dict: del request_dict["num"] + member = None + login_clipper = None + success = False # ----- # Remplissage des formulaires # ----- - user_form = RegistrationUserForm(request_dict) - EventFormset = formset_factory(AdminEventForm, - BaseEventRegistrationFormset) + if 'password1' in request_dict or 'password2' in request_dict: + user_form = RegistrationPassUserForm(request_dict) + else: + user_form = RegistrationUserForm + profile_form = RegistrationProfileForm(request_dict) + events = Event.objects.filter(old=False).all() event_formset = EventFormset(events=events, data=request_dict, prefix='events') if "user_exists" in request_dict and request_dict["user_exists"]: