Nettoyage

This commit is contained in:
Martin Pépin 2016-08-13 02:56:42 +02:00
parent 9141c484ed
commit 23ac3b7222

View file

@ -320,30 +320,32 @@ def registration_set_ro_fields(user_form, profile_form):
@buro_required @buro_required
def registration_form2(request, login_clipper=None, username=None): def registration_form2(request, login_clipper=None, username=None):
events = Event.objects.filter(old=False).all() events = Event.objects.filter(old=False).all()
member = None
EventFormset = formset_factory(AdminEventForm, EventFormset = formset_factory(AdminEventForm,
BaseEventRegistrationFormset) BaseEventRegistrationFormset)
member = None
if login_clipper: if login_clipper:
clipper = get_object_or_404(Clipper, username=login_clipper) clipper = get_object_or_404(Clipper, username=login_clipper)
try: # check if the given user is already registered 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 username = member.username
login_clipper = None login_clipper = None
except User.DoesNotExist: except User.DoesNotExist:
# new user, but prefill # new user, but prefill
user_form = RegistrationUserForm() # user
profile_form = RegistrationProfileForm() user_form = RegistrationUserForm(initial={
event_formset = EventFormset(events=events, prefix='events') 'username': login_clipper,
user_form.fields['username'].initial = login_clipper 'email': "%s@clipper.ens.fr" % login_clipper})
user_form.fields['email'].initial = "%s@clipper.ens.fr" \
% login_clipper
profile_form.fields['login_clipper'].initial = login_clipper
if clipper.fullname: if clipper.fullname:
bits = clipper.fullname.split(" ") bits = clipper.fullname.split(" ")
user_form.fields['first_name'].initial = bits[0] user_form.fields['first_name'].initial = bits[0]
if len(bits) > 1: if len(bits) > 1:
user_form.fields['last_name'].initial = " ".join(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) registration_set_ro_fields(user_form, profile_form)
# events
event_formset = EventFormset(events=events, prefix='events')
if username: if username:
member = get_object_or_404(User, username=username) member = get_object_or_404(User, username=username)
(profile, _) = CofProfile.objects.get_or_create(user=member) (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) user_form = RegistrationUserForm(instance=member)
profile_form = RegistrationProfileForm(instance=profile) profile_form = RegistrationProfileForm(instance=profile)
registration_set_ro_fields(user_form, profile_form) registration_set_ro_fields(user_form, profile_form)
# events
current_registrations = [] current_registrations = []
for event in events: for event in events:
try: try:
@ -376,6 +379,7 @@ def registration_form2(request, login_clipper=None, username=None):
def registration(request): def registration(request):
if request.POST: if request.POST:
request_dict = request.POST.copy() request_dict = request.POST.copy()
# num ne peut pas être définit manuellement
if "num" in request_dict: if "num" in request_dict:
del request_dict["num"] del request_dict["num"]
success = False success = False