[web] set pageid at request instanciation rather than in htmlheader template stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Tue, 10 Nov 2009 18:11:24 +0100
branchstable
changeset 3816 37b376bb4088
parent 3814 a4659adf4eee
child 3817 9fcf048e14b7
[web] set pageid at request instanciation rather than in htmlheader template In some occasions, we need to force a pageid: typically an ajax-rendererd creation form would need to use the pageid of the main page to correclty set it's page_data (e.g. rql varmker). If pageid is found in req.form, it's used, otherwise we build a new one with. make_uid(). The behaviour should be consistent with the former one in JSonController.
web/request.py
web/views/basecontrollers.py
web/views/basetemplates.py
--- a/web/request.py	Tue Nov 10 15:46:34 2009 +0100
+++ b/web/request.py	Tue Nov 10 18:11:24 2009 +0100
@@ -25,7 +25,7 @@
 from cubicweb.dbapi import DBAPIRequest
 from cubicweb.common.mail import header
 from cubicweb.common.uilib import remove_html_tags
-from cubicweb.utils import SizeConstrainedList, HTMLHead
+from cubicweb.utils import SizeConstrainedList, HTMLHead, make_uid
 from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE_NOEXT
 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit,
                           RequestError, StatusResponse)
@@ -83,10 +83,20 @@
         # tabindex generator
         self.tabindexgen = count(1)
         self.next_tabindex = self.tabindexgen.next
-        # page id, set by htmlheader template
-        self.pageid = None
         self.varmaker = rqlvar_maker()
         self.datadir_url = self._datadir_url()
+        self._set_pageid()
+
+    def _set_pageid(self):
+        """initialize self.pageid
+        if req.form provides a specific pageid, use it, otherwise build a
+        new one.
+        """
+        pid = self.form.get('pageid')
+        if pid is None:
+            pid = make_uid(id(self))
+        self.pageid = pid
+        self.html_headers.define_var('pageid', pid)
 
     def set_connection(self, cnx, user=None):
         """method called by the session handler when the user is authenticated
--- a/web/views/basecontrollers.py	Tue Nov 10 15:46:34 2009 +0100
+++ b/web/views/basecontrollers.py	Tue Nov 10 18:11:24 2009 +0100
@@ -250,7 +250,6 @@
         response content type
         """
         self.req.json_request = True
-        self.req.pageid = self.req.form.get('pageid')
         try:
             fname = self.req.form['fname']
             func = getattr(self, 'js_%s' % fname)
--- a/web/views/basetemplates.py	Tue Nov 10 15:46:34 2009 +0100
+++ b/web/views/basetemplates.py	Tue Nov 10 18:11:24 2009 +0100
@@ -13,7 +13,7 @@
 from cubicweb.appobject import objectify_selector
 from cubicweb.selectors import match_kwargs
 from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW
-from cubicweb.utils import make_uid, UStringIO, can_do_pdf_conversion
+from cubicweb.utils import UStringIO, can_do_pdf_conversion
 from cubicweb.schema import display_name
 
 # main templates ##############################################################
@@ -316,7 +316,6 @@
         self.stylesheets()
         self.javascripts()
         self.alternates()
-        self.pageid()
 
     def favicon(self):
         favicon = self.req.external_resource('FAVICON', None)
@@ -344,12 +343,6 @@
             self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n'
                        %  xml_escape(urlgetter.feed_url()))
 
-    def pageid(self):
-        req = self.req
-        pid = make_uid(id(req))
-        req.pageid = pid
-        req.html_headers.define_var('pageid', pid)
-
 
 class HTMLPageHeader(View):
     """default html page header"""