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:
parent
23ac3b7222
commit
12a4b8efa7
1 changed files with 56 additions and 52 deletions
|
@ -379,80 +379,84 @@ 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
|
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:
|
if "num" in request_dict:
|
||||||
del request_dict["num"]
|
del request_dict["num"]
|
||||||
success = False
|
|
||||||
|
# -----
|
||||||
|
# Remplissage des formulaires
|
||||||
|
# -----
|
||||||
|
|
||||||
user_form = RegistrationUserForm(request_dict)
|
user_form = RegistrationUserForm(request_dict)
|
||||||
profile_form = RegistrationProfileForm(request_dict)
|
|
||||||
events = Event.objects.filter(old=False).all()
|
|
||||||
EventFormset = formset_factory(AdminEventForm,
|
EventFormset = formset_factory(AdminEventForm,
|
||||||
BaseEventRegistrationFormset)
|
BaseEventRegistrationFormset)
|
||||||
event_formset = EventFormset(events=events, data=request_dict,
|
event_formset = EventFormset(events=events, data=request_dict,
|
||||||
prefix='events')
|
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"]:
|
if "user_exists" in request_dict and request_dict["user_exists"]:
|
||||||
username = request_dict["username"]
|
username = request_dict["username"]
|
||||||
try:
|
try:
|
||||||
member = User.objects.filter(username=username).get()
|
member = User.objects.get(username=username)
|
||||||
(profile, _) = CofProfile.objects.get_or_create(user=member)
|
|
||||||
user_form = RegistrationUserForm(request_dict, instance=member)
|
user_form = RegistrationUserForm(request_dict, instance=member)
|
||||||
profile_form = RegistrationProfileForm(request_dict,
|
|
||||||
instance=profile)
|
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
try:
|
try:
|
||||||
clipper = Clipper.objects.filter(username=username).get()
|
clipper = Clipper.objects.get(username=username)
|
||||||
login_clipper = clipper.username
|
login_clipper = clipper.username
|
||||||
except Clipper.DoesNotExist:
|
except Clipper.DoesNotExist:
|
||||||
pass
|
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()
|
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
|
was_cof = profile.is_cof
|
||||||
request_dict["num"] = profile.num
|
request_dict["num"] = profile.num
|
||||||
|
# Maintenant on remplit le formulaire de profil
|
||||||
profile_form = RegistrationProfileForm(request_dict,
|
profile_form = RegistrationProfileForm(request_dict,
|
||||||
instance=profile)
|
instance=profile)
|
||||||
profile_form.save()
|
if profile_form.is_valid() and event_formset.is_valid():
|
||||||
(profile, _) = CofProfile.objects.get_or_create(user=member)
|
profile = profile_form.save()
|
||||||
if profile.is_cof and not was_cof:
|
if profile.is_cof and not was_cof:
|
||||||
send_custom_mail(member, "bienvenue")
|
send_custom_mail(member, "bienvenue")
|
||||||
for form in event_formset:
|
for form in event_formset:
|
||||||
if 'status' not in form.cleaned_data:
|
if 'status' not in form.cleaned_data:
|
||||||
form.cleaned_data['status'] = 'no'
|
form.cleaned_data['status'] = 'no'
|
||||||
if form.cleaned_data['status'] == 'no':
|
if form.cleaned_data['status'] == 'no':
|
||||||
try:
|
try:
|
||||||
current_registration = EventRegistration.objects.get(
|
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)
|
user=member, event=form.event)
|
||||||
current_registration.delete()
|
update_event_form_comments(form.event, form,
|
||||||
except EventRegistration.DoesNotExist:
|
current_registration)
|
||||||
pass
|
current_registration.options = all_choices
|
||||||
continue
|
current_registration.paid = \
|
||||||
all_choices = get_event_form_choices(form.event, form)
|
(form.cleaned_data['status'] == 'paid')
|
||||||
(current_registration, created_reg) = \
|
current_registration.save()
|
||||||
EventRegistration.objects.get_or_create(user=member,
|
if form.event.title == "Mega 15" and created_reg:
|
||||||
event=form.event)
|
field = EventCommentField.objects.get(
|
||||||
update_event_form_comments(form.event, form,
|
event=form.event, name="Commentaires")
|
||||||
current_registration)
|
try:
|
||||||
current_registration.options = all_choices
|
comments = EventCommentValue.objects.get(
|
||||||
current_registration.paid = \
|
commentfield=field,
|
||||||
(form.cleaned_data['status'] == 'paid')
|
registration=current_registration).content
|
||||||
current_registration.save()
|
except EventCommentValue.DoesNotExist:
|
||||||
if form.event.title == "Mega 15" and created_reg:
|
comments = field.default
|
||||||
field = EventCommentField.objects.get(event=form.event,
|
send_custom_mail(member, "mega",
|
||||||
name="Commentaires")
|
{"remarques": comments})
|
||||||
try:
|
success = True
|
||||||
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",
|
return render(request, "registration_post.html",
|
||||||
{"success": success,
|
{"success": success,
|
||||||
"user_form": user_form,
|
"user_form": user_form,
|
||||||
|
|
Loading…
Reference in a new issue