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] 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