comparison 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
comparison
equal deleted inserted replaced
956:dabecab10faa 957:67bf14c91d5c
1694 """called when page's on_data_post has been called successfuly 1694 """called when page's on_data_post has been called successfuly
1695 1695
1696 this method redirect to the same page, using Post/Redirect/Get pattern 1696 this method redirect to the same page, using Post/Redirect/Get pattern
1697 HTTP status code "See Other" (303) is the recommanded code in this case 1697 HTTP status code "See Other" (303) is the recommanded code in this case
1698 """ 1698 """
1699 session_data = self.host.getSessionData(request, session_iface.ISATSession)
1700 session_data.flags.add(C.FLAG_CONFIRM)
1699 request.setResponseCode(C.HTTP_SEE_OTHER) 1701 request.setResponseCode(C.HTTP_SEE_OTHER)
1700 request.setHeader("location", request.uri) 1702 request.setHeader("location", request.uri)
1701 request.finish() 1703 request.finish()
1702 raise failure.Failure(exceptions.CancelError(u'Post/Redirect/Get is used')) 1704 raise failure.Failure(exceptions.CancelError(u'Post/Redirect/Get is used'))
1703 1705
1788 1790
1789 def renderPage(self, request, skip_parse_url=False): 1791 def renderPage(self, request, skip_parse_url=False):
1790 """Main method to handle the workflow of a LiberviaPage""" 1792 """Main method to handle the workflow of a LiberviaPage"""
1791 # template_data are the variables passed to template 1793 # template_data are the variables passed to template
1792 if not hasattr(request, 'template_data'): 1794 if not hasattr(request, 'template_data'):
1793 csrf_token = self.host.getSessionData(request, session_iface.ISATSession).csrf_token 1795 session_data = self.host.getSessionData(request, session_iface.ISATSession)
1794 request.template_data = {'csrf_token': csrf_token} 1796 csrf_token = session_data.csrf_token
1797 request.template_data = {u'csrf_token': csrf_token}
1798 if C.FLAG_CONFIRM in session_data.flags:
1799 request.template_data[u'confirm'] = True
1800 session_data.flags.remove(C.FLAG_CONFIRM)
1795 1801
1796 # XXX: here is the code which need to be executed once 1802 # XXX: here is the code which need to be executed once
1797 # at the beginning of the request hanling 1803 # at the beginning of the request hanling
1798 if request.postpath and not request.postpath[-1]: 1804 if request.postpath and not request.postpath[-1]:
1799 # we don't differenciate URLs finishing with '/' or not 1805 # we don't differenciate URLs finishing with '/' or not