[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 05 May 2010 10:28:55 +0200
changeset 5467 57372dbfd114
parent 5466 b5af2ac0c43c
child 5468 7199fddc0a88
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
devtools/fake.py
etwist/server.py
goa/skel/loader.py
goa/skel/main.py
goa/tools/laxctl.py
web/formwidgets.py
web/propertysheet.py
web/request.py
web/views/basecomponents.py
web/views/basecontrollers.py
web/views/basetemplates.py
web/views/idownloadable.py
web/views/igeocodable.py
web/views/schema.py
web/views/tableview.py
web/views/xmlrss.py
web/webconfig.py
--- a/devtools/fake.py	Wed May 05 10:22:11 2010 +0200
+++ b/devtools/fake.py	Wed May 05 10:28:55 2010 +0200
@@ -30,6 +30,7 @@
 
 class FakeConfig(dict, BaseApptestConfiguration):
     translations = {}
+    uiprops = {}
     apphome = None
     def __init__(self, appid='data', apphome=None, cubes=()):
         self.appid = appid
--- a/etwist/server.py	Wed May 05 10:22:11 2010 +0200
+++ b/etwist/server.py	Wed May 05 10:28:55 2010 +0200
@@ -178,6 +178,9 @@
         pre_path = request.path.split('/')[1:]
         if pre_path[0] == 'https':
             pre_path.pop(0)
+            uiprops = self.config.https_uiprops
+        else:
+            uiprops = self.config.uiprops
         directory = pre_path[0]
         # Anything in data/, static/, fckeditor/ and the generated versioned
         # data directory is treated as static files
@@ -187,7 +190,7 @@
             if directory == 'static':
                 return File(self.config.static_directory)
             if directory == 'fckeditor':
-                return File(self.config.ext_resources['FCKEDITOR_PATH'])
+                return File(uiprops['FCKEDITOR_PATH'])
             if directory != 'data':
                 # versioned directory, use specific file with http cache
                 # headers so their are cached for a very long time
@@ -195,7 +198,7 @@
             else:
                 cls = File
             if path == 'fckeditor':
-                return cls(self.config.ext_resources['FCKEDITOR_PATH'])
+                return cls(uiprops['FCKEDITOR_PATH'])
             if path == directory: # recurse
                 return self
             datadir = self.config.locate_resource(path)
@@ -211,6 +214,8 @@
         # reload modified files in debug mode
         if self.config.debugmode:
             self.config.uiprops.reload_if_needed()
+            if self.https_url:
+                self.config.https_uiprops.reload_if_needed()
             self.appli.vreg.reload_if_needed()
         if self.config['profile']: # default profiler don't trace threads
             return self.render_request(request)
--- a/goa/skel/loader.py	Wed May 05 10:22:11 2010 +0200
+++ b/goa/skel/loader.py	Wed May 05 10:28:55 2010 +0200
@@ -30,7 +30,7 @@
     # apply monkey patches first
     goa.do_monkey_patch()
     # get instance's configuration (will be loaded from app.conf file)
-    GAEConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
+    GAEConfiguration.uiprops['JAVASCRIPTS'].append('DATADIR/goa.js')
     config = GAEConfiguration('toto', APPLROOT)
     # create default groups
     create_groups()
--- a/goa/skel/main.py	Wed May 05 10:22:11 2010 +0200
+++ b/goa/skel/main.py	Wed May 05 10:28:55 2010 +0200
@@ -31,7 +31,7 @@
 
 # get instance's configuration (will be loaded from app.conf file)
 from cubicweb.goa.goaconfig import GAEConfiguration
-GAEConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
+GAEConfiguration.uiprops['JAVASCRIPTS'].append('DATADIR/goa.js')
 config = GAEConfiguration('toto', APPLROOT)
 
 # dynamic objects registry
--- a/goa/tools/laxctl.py	Wed May 05 10:22:11 2010 +0200
+++ b/goa/tools/laxctl.py	Wed May 05 10:28:55 2010 +0200
@@ -43,7 +43,7 @@
     do_monkey_patch()
     from cubicweb.goa.goavreg import GAEVregistry
     from cubicweb.goa.goaconfig import GAEConfiguration
-    #WebConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
+    #WebConfiguration.uiprops['JAVASCRIPTS'].append('DATADIR/goa.js')
     config = GAEConfiguration('toto', applroot)
     vreg = GAEVregistry(config)
     vreg.set_schema(config.load_schema())
--- a/web/formwidgets.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/formwidgets.py	Wed May 05 10:28:55 2010 +0200
@@ -549,7 +549,7 @@
         return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper">
 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>"""
                 % (helperid, inputid, year, month,
-                   form._cw.vreg.config.uiprops['CALENDAR_ICON'],
+                   form._cw.uiprops['CALENDAR_ICON'],
                    form._cw._('calendar'), helperid) )
 
 
@@ -573,7 +573,7 @@
         req.add_onload(u'jqNode("%s").datepicker('
                        '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,'
                        ' showOn: "button", buttonImageOnly: true})' % (
-                           domid, req.vreg.config.uiprops['CALENDAR_ICON'], fmt))
+                           domid, req.uiprops['CALENDAR_ICON'], fmt))
         if self.datestr is None:
             value = self.values(form, field)[0]
         else:
@@ -935,7 +935,7 @@
         if self.settabindex and not 'tabindex' in attrs:
             attrs['tabindex'] = form._cw.next_tabindex()
         if self.icon:
-            img = tags.img(src=form._cw.vreg.config.uiprops[self.icon], alt=self.icon)
+            img = tags.img(src=form._cw.uiprops[self.icon], alt=self.icon)
         else:
             img = u''
         return tags.button(img + xml_escape(label), escapecontent=False,
@@ -966,7 +966,7 @@
 
     def render(self, form, field=None, renderer=None):
         label = form._cw._(self.label)
-        imgsrc = form._cw.vreg.config.uiprops[self.imgressource]
+        imgsrc = form._cw.uiprops[self.imgressource]
         return '<a id="%(domid)s" href="%(href)s">'\
                '<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % {
             'label': label, 'imgsrc': imgsrc,
--- a/web/propertysheet.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/propertysheet.py	Wed May 05 10:28:55 2010 +0200
@@ -27,7 +27,7 @@
 class PropertySheet(dict):
     def __init__(self, cache_directory, **context):
         self._cache_directory = cache_directory
-        self._context = context
+        self.context = context
         self.reset()
         context['sheet'] = self
         self._percent_rgx = re.compile('%(?!\()')
@@ -40,7 +40,7 @@
         self._cache = {}
 
     def load(self, fpath):
-        scriptglobals = self._context.copy()
+        scriptglobals = self.context.copy()
         scriptglobals['__file__'] = fpath
         execfile(fpath, scriptglobals, self)
         self._propfile_mtime[fpath] = os.stat(fpath)[-2]
--- a/web/request.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/request.py	Wed May 05 10:28:55 2010 +0200
@@ -83,6 +83,12 @@
         super(CubicWebRequestBase, self).__init__(vreg)
         self.authmode = vreg.config['auth-mode']
         self.https = https
+        if https:
+            self.uiprops = vreg.config.https_uiprops
+            self.datadir_url = vreg.config.https_datadir_url
+        else:
+            self.uiprops = vreg.config.uiprops
+            self.datadir_url = vreg.config.datadir_url
         # raw html headers that can be added from any view
         self.html_headers = HTMLHead()
         # form parameters
@@ -99,7 +105,6 @@
         self.next_tabindex = self.tabindexgen.next
         # page id, set by htmlheader template
         self.pageid = None
-        self.datadir_url = vreg.config.datadir_url
         self._set_pageid()
         # prepare output header
         self.headers_out = Headers()
@@ -794,14 +799,14 @@
                     u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">')
         return u'<div>'
 
-    @deprecated('[3.9] use req.vreg.config.uiprops[rid]')
+    @deprecated('[3.9] use req.uiprops[rid]')
     def external_resource(self, rid, default=_MARKER):
         """return a path to an external resource, using its identifier
 
         raise `KeyError` if the resource is not defined
         """
         try:
-            return self.vreg.config.uiprops[rid]
+            return self.uiprops[rid]
         except KeyError:
             if default is _MARKER:
                 raise
--- a/web/views/basecomponents.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/basecomponents.py	Wed May 05 10:28:55 2010 +0200
@@ -79,7 +79,7 @@
 
     def call(self):
         self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>'
-               % (self._cw.base_url(), self._cw.vreg.config.uiprops['LOGO']))
+               % (self._cw.base_url(), self._cw.uiprops['LOGO']))
 
 
 class ApplHelp(component.Component):
--- a/web/views/basecontrollers.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/basecontrollers.py	Wed May 05 10:28:55 2010 +0200
@@ -463,7 +463,7 @@
     @jsonize
     def js_external_resource(self, resource):
         """returns the URL of the external resource named `resource`"""
-        return self._cw.vreg.config.uiprops[resource]
+        return self._cw.uiprops[resource]
 
     @check_pageid
     @jsonize
--- a/web/views/basetemplates.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/basetemplates.py	Wed May 05 10:28:55 2010 +0200
@@ -294,22 +294,22 @@
         self.alternates()
 
     def favicon(self):
-        favicon = self._cw.vreg.config.uiprops.get('FAVICON', None)
+        favicon = self._cw.uiprops.get('FAVICON', None)
         if favicon:
             self.whead(u'<link rel="shortcut icon" href="%s"/>\n' % favicon)
 
     def stylesheets(self):
         req = self._cw
         add_css = req.add_css
-        for css in req.vreg.config.uiprops['STYLESHEETS']:
+        for css in req.uiprops['STYLESHEETS']:
             add_css(css, localfile=False)
-        for css in req.vreg.config.uiprops['STYLESHEETS_PRINT']:
+        for css in req.uiprops['STYLESHEETS_PRINT']:
             add_css(css, u'print', localfile=False)
-        for css in req.vreg.config.uiprops['STYLESHEETS_IE']:
+        for css in req.uiprops['STYLESHEETS_IE']:
             add_css(css, localfile=False, ieonly=True)
 
     def javascripts(self):
-        for jscript in self._cw.vreg.config.uiprops['JAVASCRIPTS']:
+        for jscript in self._cw.uiprops['JAVASCRIPTS']:
             self._cw.add_js(jscript, localfile=False)
 
     def alternates(self):
--- a/web/views/idownloadable.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/idownloadable.py	Wed May 05 10:28:55 2010 +0200
@@ -48,7 +48,7 @@
     w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">')
     w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>'
       % (xml_escape(entity.download_url()),
-         req.vreg.config.uiprops['DOWNLOAD_ICON'],
+         req.uiprops['DOWNLOAD_ICON'],
          _('download icon'), xml_escape(label or entity.dc_title())))
     w(u'%s</div>' % footer)
     w(u'</div></div>\n')
--- a/web/views/igeocodable.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/igeocodable.py	Wed May 05 10:28:55 2010 +0200
@@ -59,7 +59,7 @@
         if hasattr(entity, 'marker_icon'):
             icon = entity.marker_icon()
         else:
-            icon = (self._cw.vreg.config.uiprops['GMARKER_ICON'], (20, 34), (4, 34), None)
+            icon = (self._cw.uiprops['GMARKER_ICON'], (20, 34), (4, 34), None)
         return {'latitude': entity.latitude, 'longitude': entity.longitude,
                 'title': entity.dc_long_title(),
                 #icon defines : (icon._url, icon.size,  icon.iconAncho', icon.shadow)
--- a/web/views/schema.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/schema.py	Wed May 05 10:28:55 2010 +0200
@@ -248,7 +248,7 @@
                 eschema.type, self._cw.build_url('cwetype/%s' % eschema.type),
                 eschema.type, _(eschema.type)))
             self.w(u'<a href="%s#schema_security"><img src="%s" alt="%s"/></a>' % (
-                url,  self._cw.vreg.config.uiprops['UP_ICON'], _('up')))
+                url,  self._cw.uiprops['UP_ICON'], _('up')))
             self.w(u'</h3>')
             self.w(u'<div style="margin: 0px 1.5em">')
             self.permissions_table(eschema)
@@ -277,7 +277,7 @@
                 rschema.type, self._cw.build_url('cwrtype/%s' % rschema.type),
                 rschema.type, _(rschema.type)))
             self.w(u'<a href="%s#schema_security"><img src="%s" alt="%s"/></a>' % (
-                url,  self._cw.vreg.config.uiprops['UP_ICON'], _('up')))
+                url,  self._cw.uiprops['UP_ICON'], _('up')))
             self.w(u'</h3>')
             self.grouped_permissions_table(rschema)
 
--- a/web/views/tableview.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/tableview.py	Wed May 05 10:28:55 2010 +0200
@@ -204,7 +204,7 @@
 
     def render_actions(self, divid, actions):
         box = MenuWidget('', 'tableActionsBox', _class='', islist=False)
-        label = tags.img(src=self._cw.vreg.config.uiprops['PUCE_DOWN'],
+        label = tags.img(src=self._cw.uiprops['PUCE_DOWN'],
                          alt=xml_escape(self._cw._('action(s) on this selection')))
         menu = PopupBoxMenu(label, isitem=False, link_class='actionsBox',
                             ident='%sActions' % divid)
--- a/web/views/xmlrss.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/views/xmlrss.py	Wed May 05 10:28:55 2010 +0200
@@ -147,7 +147,7 @@
 
     def call(self, **kwargs):
         try:
-            rss = self._cw.vreg.config.uiprops['RSS_LOGO']
+            rss = self._cw.uiprops['RSS_LOGO']
         except KeyError:
             self.error('missing RSS_LOGO external resource')
             return
--- a/web/webconfig.py	Wed May 05 10:22:11 2010 +0200
+++ b/web/webconfig.py	Wed May 05 10:28:55 2010 +0200
@@ -302,10 +302,15 @@
         if not self.repairing:
             self.global_set_option('base-url', baseurl)
         httpsurl = self['https-url']
-        if httpsurl and httpsurl[-1] != '/':
-            httpsurl += '/'
-            if not self.repairing:
-                self.global_set_option('https-url', httpsurl)
+        if httpsurl:
+            if httpsurl[-1] != '/':
+                httpsurl += '/'
+                if not self.repairing:
+                    self.global_set_option('https-url', httpsurl)
+            if self.debugmode:
+                self.https_datadir_url = httpsurl + 'data/'
+            else:
+                self.https_datadir_url = httpsurl + 'data%s/' % self.instance_md5_version()
         if self.debugmode:
             self.datadir_url = baseurl + 'data/'
         else:
@@ -318,31 +323,41 @@
             join(self.appdatahome, 'uicache'),
             data=lambda x: self.datadir_url + x,
             datadir_url=self.datadir_url[:-1])
+        self._init_uiprops(self.uiprops)
+        if self['https-url']:
+            self.https_uiprops = PropertySheet(
+                join(self.appdatahome, 'uicache'),
+                data=lambda x: self.https_datadir_url + x,
+                datadir_url=self.https_datadir_url[:-1])
+            self._init_uiprops(self.https_uiprops)
+
+    def _init_uiprops(self, uiprops):
         libuiprops = join(self.shared_dir(), 'data', 'uiprops.py')
-        self.uiprops.load(libuiprops)
+        uiprops.load(libuiprops)
         for path in reversed([self.apphome] + self.cubes_path()):
-            self._load_ui_properties(path)
-        self._load_ui_properties(self.apphome)
+            self._load_ui_properties_file(uiprops, path)
+        self._load_ui_properties_file(uiprops, self.apphome)
 
-    def _load_ui_properties(self, path):
+    def _load_ui_properties_file(self, uiprops, path):
         resourcesfile = join(path, 'data', 'external_resources')
         if exists(resourcesfile):
             warn('[3.9] %s file is deprecated, use an uiprops.py file'
                  % resourcesfile, DeprecationWarning)
+            datadir_url = uiprops.context['datadir_url']
             for rid, val in read_config(resourcesfile).iteritems():
                 if rid in ('STYLESHEETS', 'STYLESHEETS_PRINT',
                            'IE_STYLESHEETS', 'JAVASCRIPTS'):
-                    val = [w.strip().replace('DATADIR/', self.datadir_url)
+                    val = [w.strip().replace('DATADIR', datadir_url)
                            for w in val.split(',') if w.strip()]
                     if rid == 'IE_STYLESHEETS':
                         rid = 'STYLESHEETS_IE'
                 else:
-                    val = val.strip().replace('DATADIR/', self.datadir_url)
-                self.uiprops[rid] = val
+                    val = val.strip().replace('DATADIR', datadir_url)
+                uiprops[rid] = val
         uipropsfile = join(path, 'uiprops.py')
         if exists(uipropsfile):
             self.debug('loading %s', uipropsfile)
-            self.uiprops.load(uipropsfile)
+            uiprops.load(uipropsfile)
 
     # static files handling ###################################################