proper use of messages in registration

This commit is contained in:
Martin Pépin 2017-01-30 13:36:51 +01:00
parent b7ecac3db6
commit 51c0e2dabc
2 changed files with 12 additions and 8 deletions

View file

@ -2,10 +2,6 @@
{% block realcontent %} {% block realcontent %}
<h2>Inscription d'un nouveau membre</h2> <h2>Inscription d'un nouveau membre</h2>
{% if success %}
<p class="success">L'inscription de {{ member.first_name }} {{ member.last_name }} (<tt>{{ member.username }}</tt>) a été enregistrée avec succès.
{% if member.profile.is_cof %}Il est désormais membre du COF n°{{ member.profile.num }} !{% endif %}</p>
{% endif %}
<div id="form-placeholder"> <div id="form-placeholder">
{% include "registration_form.html" %} {% include "registration_form.html" %}
</div> </div>

View file

@ -388,7 +388,7 @@ def registration_form2(request, login_clipper=None, username=None):
profile_form = RegistrationProfileForm() profile_form = RegistrationProfileForm()
event_formset = EventFormset(events=events, prefix='events') event_formset = EventFormset(events=events, prefix='events')
clubs_form = ClubsForm() clubs_form = ClubsForm()
return render(request, "registration_form.html", return render(request, "gestioncof/registration_form.html",
{"member": member, "login_clipper": login_clipper, {"member": member, "login_clipper": login_clipper,
"user_form": user_form, "user_form": user_form,
"profile_form": profile_form, "profile_form": profile_form,
@ -491,9 +491,17 @@ def registration(request):
club.membres.add(member) club.membres.add(member)
club.save() club.save()
success = True success = True
return render(request, "registration_post.html", # Messages
{"success": success, if success:
"user_form": user_form, msg = ("L'inscription de {:s} (<tt>{:s}</tt>) a été "
"enregistrées avec succès"
.format(member.get_full_name(), member.email))
if member.profile.is_cof:
msg += "Il est désormais membre du COF n°{:d} !".format(
member.profile.num)
messages.success(request, msg, extra_tags='safe')
return render(request, "gestioncof/registration_post.html",
{"user_form": user_form,
"profile_form": profile_form, "profile_form": profile_form,
"member": member, "member": member,
"login_clipper": login_clipper, "login_clipper": login_clipper,