comparison src/server/pages.py @ 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 f88325b56a6a
children 05cc33d8e328
comparison
equal deleted inserted replaced
997:3bf61858a123 998:0848b8b0188d
680 self.pageError(request) 680 self.pageError(request)
681 else: 681 else:
682 child.render(request) 682 child.render(request)
683 raise failure.Failure(exceptions.CancelError(u'subpage page is used')) 683 raise failure.Failure(exceptions.CancelError(u'subpage page is used'))
684 684
685 def _prepare_dynamic(self, dummy, request):
686 # we need to activate dynamic page
687 # we set data for template, and create/register token
688 socket_token = unicode(uuid.uuid4())
689 socket_url = self.host.getWebsocketURL(request)
690 socket_debug = C.boolConst(self.host.debug)
691 request.template_data['websocket'] = WebsocketMeta(socket_url, socket_token, socket_debug)
692 self.host.registerWSToken(socket_token, self, request)
693 # we will keep track of handlers to remove
694 request._signals_registered = []
695 # we will cache registered signals until socket is opened
696 request._signals_cache = []
697
685 def _prepare_render(self, dummy, request): 698 def _prepare_render(self, dummy, request):
686 return defer.maybeDeferred(self.prepare_render, self, request) 699 return defer.maybeDeferred(self.prepare_render, self, request)
687 700
688 def _render_method(self, dummy, request): 701 def _render_method(self, dummy, request):
689 return defer.maybeDeferred(self.render_method, self, request) 702 return defer.maybeDeferred(self.render_method, self, request)
911 if not hasattr(request, 'template_data'): 924 if not hasattr(request, 'template_data'):
912 session_data = self.host.getSessionData(request, session_iface.ISATSession) 925 session_data = self.host.getSessionData(request, session_iface.ISATSession)
913 csrf_token = session_data.csrf_token 926 csrf_token = session_data.csrf_token
914 request.template_data = {u'profile': session_data.profile, 927 request.template_data = {u'profile': session_data.profile,
915 u'csrf_token': csrf_token} 928 u'csrf_token': csrf_token}
916 if self.dynamic:
917 # we need to activate dynamic page
918 # we set data for template, and create/register token
919 socket_token = unicode(uuid.uuid4())
920 socket_url = self.host.getWebsocketURL(request)
921 socket_debug = C.boolConst(self.host.debug)
922 request.template_data['websocket'] = WebsocketMeta(socket_url, socket_token, socket_debug)
923 self.host.registerWSToken(socket_token, self, request)
924 # we will keep track of handlers to remove
925 request._signals_registered = []
926 # we will cache registered signals until socket is opened
927 request._signals_cache = []
928 929
929 # XXX: here is the code which need to be executed once 930 # XXX: here is the code which need to be executed once
930 # at the beginning of the request hanling 931 # at the beginning of the request hanling
931 if request.postpath and not request.postpath[-1]: 932 if request.postpath and not request.postpath[-1]:
932 # we don't differenciate URLs finishing with '/' or not 933 # we don't differenciate URLs finishing with '/' or not
955 else: 956 else:
956 d.addCallback(self._on_data_post, request) 957 d.addCallback(self._on_data_post, request)
957 # by default, POST follow normal behaviour after on_data_post is called 958 # by default, POST follow normal behaviour after on_data_post is called
958 # this can be changed by a redirection or other method call in on_data_post 959 # this can be changed by a redirection or other method call in on_data_post
959 960
961 if self.dynamic:
962 d.addCallback(self._prepare_dynamic, request)
963
960 if self.prepare_render: 964 if self.prepare_render:
961 d.addCallback(self._prepare_render, request) 965 d.addCallback(self._prepare_render, request)
962 966
963 if self.template: 967 if self.template:
964 d.addCallback(self._render_template, request) 968 d.addCallback(self._render_template, request)