[MERGE] js and css enumeration and loading by chs
authorAntony Lesuisse <al@openerp.com>
Mon, 17 Oct 2011 14:54:30 +0000 (16:54 +0200)
committerAntony Lesuisse <al@openerp.com>
Mon, 17 Oct 2011 14:54:30 +0000 (16:54 +0200)
bzr revid: al@openerp.com-20111017145430-a7i3d3yo8fhjhg39

1  2 
addons/web/controllers/main.py
addons/web/static/src/js/core.js

@@@ -79,48 -76,46 +76,47 @@@ class WebClient(openerpweb.Controller)
              manifest = openerpweb.addons_manifest.get(addon, None)
              if not manifest:
                  continue
-             addons_path = manifest['addons_path']
 -            addons_path = os.path.join(manifest['addons_path'], '')[:-1]    # ensure does not ends with /
++            # ensure does not ends with /
++            addons_path = os.path.join(manifest['addons_path'], '')[:-1]
              globlist = manifest.get(key, [])
              for pattern in globlist:
-                 for path in glob.glob(os.path.join(addons_path, addon, pattern)):
-                     files.append(path[len(addons_path):])
-         return files
+                 for path in glob.glob(os.path.normpath(os.path.join(addons_path, addon, pattern))):
+                     yield path, path[len(addons_path):]
 -    def _list(self, req, mods, extension):
++    def manifest_list(self, req, mods, extension):
+         if not req.debug:
+             path = '/web/webclient/' + extension
+             if mods is not None:
+                 path += '?mods=' + mods
+             return [path]
+         return ['%s?debug=%s' % (wp, os.path.getmtime(fp)) for fp, wp in self.manifest_glob(req, mods, extension)]
  
      @openerpweb.jsonrequest
      def csslist(self, req, mods=None):
-         return self.manifest_glob(req, mods, 'css')
 -        return self._list(req, mods, 'css')
++        return self.manifest_list(req, mods, 'css')
  
      @openerpweb.jsonrequest
      def jslist(self, req, mods=None):
-         return self.manifest_glob(req, mods, 'js')
 -        return self._list(req, mods, 'js')
++        return self.manifest_list(req, mods, 'js')
  
      @openerpweb.httprequest
      def css(self, req, mods=None):
-         files = self.manifest_glob(req, mods, 'css')
-         content,timestamp = concat_files(req.config.addons_path, files)
-         # TODO request set the Date of last modif and Etag
 -        files = map(operator.itemgetter(0), self.manifest_glob(req, mods, 'css'))
++        files = [f[0] for f in self.manifest_glob(req, mods, 'css')]
+         content,timestamp = concat_files(files)
 -        # TODO request set the Date of last modif and Etag
++        # TODO use timestamp to set Last mofified date and E-tag
          return req.make_response(content, [('Content-Type', 'text/css')])
  
      @openerpweb.httprequest
      def js(self, req, mods=None):
-         files = self.manifest_glob(req, mods, 'js')
-         content,timestamp = concat_files(req.config.addons_path, files)
-         # TODO request set the Date of last modif and Etag
 -        files = map(operator.itemgetter(0), self.manifest_glob(req, mods, 'js'))
++        files = [f[0] for f in self.manifest_glob(req, mods, 'js')]
+         content,timestamp = concat_files(files)
 -        # TODO request set the Date of last modif and Etag
++        # TODO use timestamp to set Last mofified date and E-tag
          return req.make_response(content, [('Content-Type', 'application/javascript')])
  
      @openerpweb.httprequest
      def home(self, req, s_action=None, **kw):
-         # script tags
-         jslist = ['/web/webclient/js']
-         if req.debug:
-             jslist = [i + '?debug=' + str(time.time()) for i in self.manifest_glob(req, None, 'js')]
-         js = "\n        ".join(['<script type="text/javascript" src="%s"></script>'%i for i in jslist])
-         # css tags
-         csslist = ['/web/webclient/css']
-         if req.debug:
-             csslist = [i + '?debug=' + str(time.time()) for i in self.manifest_glob(req, None, 'css')]
-         css = "\n        ".join(['<link rel="stylesheet" href="%s">'%i for i in csslist])
 -        js = "\n        ".join('<script type="text/javascript" src="%s"></script>'%i for i in self._list(req, None, 'js'))
 -        css = "\n        ".join('<link rel="stylesheet" href="%s">'%i for i in self._list(req, None, 'css'))
++        js = "\n        ".join('<script type="text/javascript" src="%s"></script>'%i for i in self.manifest_list(req, None, 'js'))
++        css = "\n        ".join('<link rel="stylesheet" href="%s">'%i for i in self.manifest_list(req, None, 'css'))
  
          r = home_template % {
              'javascript': js,
@@@ -384,6 -384,7 +384,8 @@@ openerp.web.Session = openerp.web.Callb
          var self = this;
          // Construct a JSON-RPC2 request, method is currently unused
          params.session_id = this.session_id;
 -        if (this.debug) params.debug = 1;
++        if (this.debug)
++            params.debug = 1;
  
          // Call using the rpc_mode
          var deferred = $.Deferred();