Petits changements

- 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`
This commit is contained in:
Martin Pépin 2016-08-14 12:10:50 +02:00
parent 23ac3b7222
commit 12a4b8efa7

View file

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