summaryrefslogtreecommitdiff
path: root/addons/web/controllers/main.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@openerp.com>2011-11-08 17:36:44 +0100
committerChristophe Simonis <chs@openerp.com>2011-11-08 17:36:44 +0100
commit2ea47dc3b2aac73256f361c8ca65de7d8cb40e2c (patch)
tree48ba730f8783b0dcfae4d1230c9f4aeea7a9ff1a /addons/web/controllers/main.py
parent1b7125432843d0db93628b04e56065e77d7d14ee (diff)
parent61823d98e9177aefa0e6aecd8750ce2bcb192e9a (diff)
merge upstream
bzr revid: chs@openerp.com-20111108163644-8mlg48lua376lzgg
Diffstat (limited to 'addons/web/controllers/main.py')
-rw-r--r--addons/web/controllers/main.py86
1 files changed, 79 insertions, 7 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 8120141b4f6..74285b1f444 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -24,19 +24,51 @@ openerpweb = web.common.http
# OpenERP Web web Controllers
#----------------------------------------------------------
-def concat_files(file_list):
- """ Concatenate file content
+
+def concat_xml(file_list):
+ """Concatenate xml files
return (concat,timestamp)
concat: concatenation of file content
timestamp: max(os.path.getmtime of file_list)
"""
+ root = None
+ files_timestamp = 0
+ for fname in file_list:
+ ftime = os.path.getmtime(fname)
+ if ftime > files_timestamp:
+ files_timestamp = ftime
+
+ xml = ElementTree.parse(fname).getroot()
+
+ if root is None:
+ root = ElementTree.Element(xml.tag)
+ #elif root.tag != xml.tag:
+ # raise ValueError("Root tags missmatch: %r != %r" % (root.tag, xml.tag))
+
+ for child in xml.getchildren():
+ root.append(child)
+ return ElementTree.tostring(root, 'utf-8'), files_timestamp
+
+
+def concat_files(file_list, reader=None):
+ """ Concatenate file content
+ return (concat,timestamp)
+ concat: concatenation of file content, read by `reader`
+ timestamp: max(os.path.getmtime of file_list)
+ """
+ if reader is None:
+ def reader(f):
+ with open(f) as fp:
+ return fp.read()
+
files_content = []
files_timestamp = 0
for fname in file_list:
ftime = os.path.getmtime(fname)
if ftime > files_timestamp:
files_timestamp = ftime
- files_content.append(open(fname).read())
+
+ files_content.append(reader(fname))
files_concat = "".join(files_content)
return files_concat,files_timestamp
@@ -98,10 +130,42 @@ class WebClient(openerpweb.Controller):
def jslist(self, req, mods=None):
return self.manifest_list(req, mods, 'js')
+ @openerpweb.jsonrequest
+ def qweblist(self, req, mods=None):
+ return self.manifest_list(req, mods, 'qweb')
+
@openerpweb.httprequest
def css(self, req, mods=None):
- files = [f[0] for f in self.manifest_glob(req, mods, 'css')]
- content,timestamp = concat_files(files)
+
+ files = list(self.manifest_glob(req, mods, 'css'))
+ file_map = dict(files)
+
+ rx_import = re.compile(r"""@import\s+('|")(?!'|"|/|https?://)""", re.U)
+ rx_url = re.compile(r"""url\s*\(\s*('|"|)(?!'|"|/|https?://)""", re.U)
+
+
+ def reader(f):
+ """read the a css file and absolutify all relative uris"""
+ with open(f) as fp:
+ data = fp.read()
+
+ web_path = file_map[f]
+ web_dir = os.path.dirname(web_path)
+
+ data = re.sub(
+ rx_import,
+ r"""@import \1%s/""" % (web_dir,),
+ data,
+ )
+
+ data = re.sub(
+ rx_url,
+ r"""url(\1%s/""" % (web_dir,),
+ data,
+ )
+ return data
+
+ content,timestamp = concat_files((f[0] for f in files), reader)
# TODO use timestamp to set Last mofified date and E-tag
return req.make_response(content, [('Content-Type', 'text/css')])
@@ -113,6 +177,14 @@ class WebClient(openerpweb.Controller):
return req.make_response(content, [('Content-Type', 'application/javascript')])
@openerpweb.httprequest
+ def qweb(self, req, mods=None):
+ files = [f[0] for f in self.manifest_glob(req, mods, 'qweb')]
+ content,timestamp = concat_xml(files)
+ # TODO use timestamp to set Last mofified date and E-tag
+ return req.make_response(content, [('Content-Type', 'text/xml')])
+
+
+ @openerpweb.httprequest
def home(self, req, s_action=None, **kw):
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'))
@@ -451,7 +523,7 @@ def clean_action(req, action, do_not_eval=False):
# values come from the server, we can just eval them
if isinstance(action.get('context'), basestring):
action['context'] = eval( action['context'], eval_ctx ) or {}
-
+
if isinstance(action.get('domain'), basestring):
action['domain'] = eval( action['domain'], eval_ctx ) or []
else:
@@ -1412,7 +1484,7 @@ class Import(View):
return fields
@openerpweb.httprequest
- def detect_data(self, req, csvfile, csvsep, csvdel, csvcode, jsonp):
+ def detect_data(self, req, csvfile, csvsep=',', csvdel='"', csvcode='utf-8', jsonp='callback'):
try:
data = list(csv.reader(
csvfile, quotechar=str(csvdel), delimiter=str(csvsep)))