# HG changeset patch # User Goffi # Date 1515166169 -3600 # Node ID 0848b8b0188d5d2a4604e7fae3583197e4d8c681 # Parent 3bf61858a12379311f4179b813f3a649c443c47f 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. diff -r 3bf61858a123 -r 0848b8b0188d src/server/pages.py --- 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)