# HG changeset patch # User Goffi # Date 1499751980 -7200 # Node ID 67bf14c91d5c4d8f6c3abcedb68a29e70f301c06 # Parent dabecab10faa6c4a71fc0a577bd6b5e098d9072c 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). diff -r dabecab10faa -r 67bf14c91d5c src/server/constants.py --- 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' diff -r dabecab10faa -r 67bf14c91d5c src/server/server.py --- 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 diff -r dabecab10faa -r 67bf14c91d5c src/server/session_iface.py --- 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):