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