changeset 957:67bf14c91d5c

server (pages): added a confirm flag on successful post: A new set is used in SATSession to keep flags. First flag is "confirm": it is set when some data have been posted (so a confirmation message can be displayed in template). If seen in session, the template "confirm" variable is set to True, and the flag is removed from session (a refresh of the page will not display the confirm message anymore).
author Goffi <goffi@goffi.org>
date Tue, 11 Jul 2017 07:46:20 +0200
parents dabecab10faa
children 3c81203840a4
files src/server/constants.py src/server/server.py src/server/session_iface.py
diffstat 3 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/constants.py	Mon Jul 10 19:10:31 2017 +0200
+++ b/src/server/constants.py	Tue Jul 11 07:46:20 2017 +0200
@@ -58,6 +58,9 @@
     PAGES_ACCESS_ADMIN = u"admin"  # only profiles set in admins_list can access the page
     PAGES_ACCESS_ALL = (PAGES_ACCESS_NONE, PAGES_ACCESS_PUBLIC, PAGES_ACCESS_PROFILE, PAGES_ACCESS_ADMIN)
 
+    ## Session flags ##
+    FLAG_CONFIRM = u"confirm"
+
     ## HTTP methods ##
     HTTP_METHOD_GET = u'GET'
     HTTP_METHOD_POST = u'POST'
--- a/src/server/server.py	Mon Jul 10 19:10:31 2017 +0200
+++ b/src/server/server.py	Tue Jul 11 07:46:20 2017 +0200
@@ -1696,6 +1696,8 @@
         this method redirect to the same page, using Post/Redirect/Get pattern
         HTTP status code "See Other" (303) is the recommanded code in this case
         """
+        session_data = self.host.getSessionData(request, session_iface.ISATSession)
+        session_data.flags.add(C.FLAG_CONFIRM)
         request.setResponseCode(C.HTTP_SEE_OTHER)
         request.setHeader("location", request.uri)
         request.finish()
@@ -1790,8 +1792,12 @@
         """Main method to handle the workflow of a LiberviaPage"""
         # template_data are the variables passed to template
         if not hasattr(request, 'template_data'):
-            csrf_token = self.host.getSessionData(request, session_iface.ISATSession).csrf_token
-            request.template_data = {'csrf_token': csrf_token}
+            session_data = self.host.getSessionData(request, session_iface.ISATSession)
+            csrf_token = session_data.csrf_token
+            request.template_data = {u'csrf_token': csrf_token}
+            if C.FLAG_CONFIRM in session_data.flags:
+                request.template_data[u'confirm'] = True
+                session_data.flags.remove(C.FLAG_CONFIRM)
 
             # XXX: here is the code which need to be executed once
             #      at the beginning of the request hanling
--- a/src/server/session_iface.py	Mon Jul 10 19:10:31 2017 +0200
+++ b/src/server/session_iface.py	Tue Jul 11 07:46:20 2017 +0200
@@ -36,6 +36,7 @@
         self.uuid = unicode(shortuuid.uuid())
         self.identities = data_objects.Identities()
         self.csrf_token = unicode(shortuuid.uuid())
+        self.flags = set()
 
 
 class ISATGuestSession(Interface):