diff src/server/server.py @ 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 968eda9e982a
line wrap: on
line diff
--- 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