From 51c0e2dabccd9a31e84dc91450be603caaffeae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 30 Jan 2017 13:36:51 +0100 Subject: [PATCH] proper use of messages in registration --- .../templates/gestioncof/registration_post.html | 4 ---- gestioncof/views.py | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gestioncof/templates/gestioncof/registration_post.html b/gestioncof/templates/gestioncof/registration_post.html index ce2f3786..e96fa1e7 100644 --- a/gestioncof/templates/gestioncof/registration_post.html +++ b/gestioncof/templates/gestioncof/registration_post.html @@ -2,10 +2,6 @@ {% block realcontent %}

Inscription d'un nouveau membre

- {% if success %} -

L'inscription de {{ member.first_name }} {{ member.last_name }} ({{ member.username }}) a été enregistrée avec succès. - {% if member.profile.is_cof %}Il est désormais membre du COF n°{{ member.profile.num }} !{% endif %}

- {% endif %}
{% include "registration_form.html" %}
diff --git a/gestioncof/views.py b/gestioncof/views.py index 32fd39a4..3fdafd28 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -388,7 +388,7 @@ def registration_form2(request, login_clipper=None, username=None): profile_form = RegistrationProfileForm() event_formset = EventFormset(events=events, prefix='events') clubs_form = ClubsForm() - return render(request, "registration_form.html", + return render(request, "gestioncof/registration_form.html", {"member": member, "login_clipper": login_clipper, "user_form": user_form, "profile_form": profile_form, @@ -491,9 +491,17 @@ def registration(request): club.membres.add(member) club.save() success = True - return render(request, "registration_post.html", - {"success": success, - "user_form": user_form, + # Messages + if success: + msg = ("L'inscription de {:s} ({:s}) 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, "member": member, "login_clipper": login_clipper,