changeset 998:0848b8b0188d

pages: dynamic set up is now done just before prepare_render call: dynamic set up is not done at the beginning of the page workflow anymore because dynamic method should not be used during parse_url and page workflow may switch in case of redirection.
author Goffi <goffi@goffi.org>
date Fri, 05 Jan 2018 16:29:29 +0100
parents 3bf61858a123
children ded41172dcb5
files src/server/pages.py
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/pages.py	Fri Jan 05 13:01:49 2018 +0100
+++ b/src/server/pages.py	Fri Jan 05 16:29:29 2018 +0100
@@ -682,6 +682,19 @@
                 child.render(request)
                 raise failure.Failure(exceptions.CancelError(u'subpage page is used'))
 
+    def _prepare_dynamic(self, dummy, request):
+        # we need to activate dynamic page
+        # we set data for template, and create/register token
+        socket_token = unicode(uuid.uuid4())
+        socket_url = self.host.getWebsocketURL(request)
+        socket_debug = C.boolConst(self.host.debug)
+        request.template_data['websocket'] = WebsocketMeta(socket_url, socket_token, socket_debug)
+        self.host.registerWSToken(socket_token, self, request)
+        # we will keep track of handlers to remove
+        request._signals_registered = []
+        # we will cache registered signals until socket is opened
+        request._signals_cache = []
+
     def _prepare_render(self, dummy, request):
         return defer.maybeDeferred(self.prepare_render, self, request)
 
@@ -913,18 +926,6 @@
             csrf_token = session_data.csrf_token
             request.template_data = {u'profile': session_data.profile,
                                      u'csrf_token': csrf_token}
-            if self.dynamic:
-                # we need to activate dynamic page
-                # we set data for template, and create/register token
-                socket_token = unicode(uuid.uuid4())
-                socket_url = self.host.getWebsocketURL(request)
-                socket_debug = C.boolConst(self.host.debug)
-                request.template_data['websocket'] = WebsocketMeta(socket_url, socket_token, socket_debug)
-                self.host.registerWSToken(socket_token, self, request)
-                # we will keep track of handlers to remove
-                request._signals_registered = []
-                # we will cache registered signals until socket is opened
-                request._signals_cache = []
 
             # XXX: here is the code which need to be executed once
             #      at the beginning of the request hanling
@@ -957,6 +958,9 @@
             # by default, POST follow normal behaviour after on_data_post is called
             # this can be changed by a redirection or other method call in on_data_post
 
+        if self.dynamic:
+            d.addCallback(self._prepare_dynamic, request)
+
         if self.prepare_render:
             d.addCallback(self._prepare_render, request)