From 360a1e50e3d2638bda8699b9929a1de3774e64a1 Mon Sep 17 00:00:00 2001 From: "Turkesh Patel (Open ERP)" Date: Fri, 14 Oct 2011 16:39:42 +0530 Subject: [FIX] Fixed the issue of attachment file which can't open after save as lp bug: https://launchpad.net/bugs/872707 fixed bzr revid: tpa@tinyerp.com-20111014110942-9yk1cmeu8swtrcjj --- addons/web/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/controllers/main.py') diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 7ca80fbfdec..f2ce4b2f3dd 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1008,7 +1008,7 @@ class Binary(openerpweb.Controller): Model = req.session.model(model) context = req.session.eval_context(req.context) res = Model.read([int(id)], [field, fieldname], context)[0] - filecontent = res.get(field, '') + filecontent = base64.b64decode(res.get(field, '')) if not filecontent: return req.not_found() else: -- cgit v1.2.3 From 6e93a38f882d3afd6b472100fc8c3c02f292f28d Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 14 Oct 2011 17:29:46 +0200 Subject: [FIX] web: correctly concat_file when no debug bzr revid: chs@openerp.com-20111014152946-r307ol34kdlq5qrs --- addons/web/controllers/main.py | 49 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'addons/web/controllers/main.py') diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 7ca80fbfdec..29ceceeddd5 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -25,8 +25,7 @@ openerpweb = web.common.http # OpenERP Web web Controllers #---------------------------------------------------------- -# TODO change into concat_file(addons,key) taking care of addons_path -def concat_files(addons_path, file_list): +def concat_files(file_list): """ Concatenate file content return (concat,timestamp) concat: concatenation of file content @@ -34,8 +33,7 @@ def concat_files(addons_path, file_list): """ files_content = [] files_timestamp = 0 - for i in file_list: - fname = os.path.join(addons_path, i[1:]) + for fname in file_list: ftime = os.path.getmtime(fname) if ftime > files_timestamp: files_timestamp = ftime @@ -70,57 +68,54 @@ class WebClient(openerpweb.Controller): return addons def manifest_glob(self, req, addons, key): - if addons==None: + if addons is None: addons = self.server_wide_modules(req) else: addons = addons.split(',') - files = [] for addon in addons: 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 / 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): + 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') @openerpweb.jsonrequest def jslist(self, req, mods=None): - return self.manifest_glob(req, mods, 'js') + return self._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) + files = map(operator.itemgetter(0), self.manifest_glob(req, mods, 'css')) + content,timestamp = concat_files(files) # TODO request set the Date of last modif and Etag 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) + files = map(operator.itemgetter(0), self.manifest_glob(req, mods, 'js')) + content,timestamp = concat_files(files) # TODO request set the Date of last modif and Etag 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([''%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([''%i for i in csslist]) + js = "\n ".join(''%i for i in self._list(req, None, 'js')) + css = "\n ".join(''%i for i in self._list(req, None, 'css')) r = home_template % { 'javascript': js, -- cgit v1.2.3 From 548a809ff5853f3c97d6cd6bc3c71fa850d58289 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 17 Oct 2011 16:58:49 +0200 Subject: [FIX] downloading files from an unsaved/in-memory wizard fallback on default_get if record does not exist in db, as for e.g. Thunderbird and Outlook plugins lp bug: https://launchpad.net/bugs/856487 fixed bzr revid: xmo@openerp.com-20111017145849-p8dq0eprkru4xtl1 --- addons/web/controllers/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'addons/web/controllers/main.py') diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 42b90a4a6b8..4ca998aea14 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1003,7 +1003,10 @@ class Binary(openerpweb.Controller): def saveas(self, req, model, id, field, fieldname, **kw): Model = req.session.model(model) context = req.session.eval_context(req.context) - res = Model.read([int(id)], [field, fieldname], context)[0] + if id: + res = Model.read([int(id)], [field, fieldname], context)[0] + else: + res = Model.default_get([field, fieldname], context) filecontent = base64.b64decode(res.get(field, '')) if not filecontent: return req.not_found() -- cgit v1.2.3 From 6ce8a18fbe9c5273b79f3f5f5e079417f9acf404 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 18 Oct 2011 17:57:33 +0200 Subject: [fix] context problem in accounting lp bug: https://launchpad.net/bugs/871771 fixed bzr revid: nicolas.vanhoren@openerp.com-20111018155733-45xhk7hg2xsmj26h --- addons/web/controllers/main.py | 110 ++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 52 deletions(-) (limited to 'addons/web/controllers/main.py') diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 4ca998aea14..d8e587e3d4d 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -441,18 +441,24 @@ def load_actions_from_ir_values(req, key, key2, models, meta): return [(id, name, clean_action(req, action)) for id, name, action in actions] -def clean_action(req, action): +def clean_action(req, action, do_not_eval=False): action.setdefault('flags', {}) context = req.session.eval_context(req.context) eval_ctx = req.session.evaluation_context(context) - # 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 [] + if not do_not_eval: + # 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: + if 'context' in action: + action['context'] = parse_context(action['context'], req.session) + if 'domain' in action: + action['domain'] = parse_domain(action['domain'], req.session) if 'type' not in action: action['type'] = 'ir.actions.act_window_close' @@ -786,9 +792,9 @@ class View(openerpweb.Controller): for view in field["views"].itervalues(): self.process_view(session, view, None, transform) if field.get('domain'): - field["domain"] = self.parse_domain(field["domain"], session) + field["domain"] = parse_domain(field["domain"], session) if field.get('context'): - field["context"] = self.parse_context(field["context"], session) + field["context"] = parse_context(field["context"], session) def process_toolbar(self, req, toolbar): """ @@ -800,10 +806,10 @@ class View(openerpweb.Controller): for actions in toolbar.itervalues(): for action in actions: if 'context' in action: - action['context'] = self.parse_context( + action['context'] = parse_context( action['context'], req.session) if 'domain' in action: - action['domain'] = self.parse_domain( + action['domain'] = parse_domain( action['domain'], req.session) @openerpweb.jsonrequest @@ -842,39 +848,6 @@ class View(openerpweb.Controller): self.parse_domains_and_contexts(elem, session) return root - def parse_domain(self, domain, session): - """ Parses an arbitrary string containing a domain, transforms it - to either a literal domain or a :class:`web.common.nonliterals.Domain` - - :param domain: the domain to parse, if the domain is not a string it - is assumed to be a literal domain and is returned as-is - :param session: Current OpenERP session - :type session: openerpweb.openerpweb.OpenERPSession - """ - if not isinstance(domain, (str, unicode)): - return domain - try: - return ast.literal_eval(domain) - except ValueError: - # not a literal - return web.common.nonliterals.Domain(session, domain) - - def parse_context(self, context, session): - """ Parses an arbitrary string containing a context, transforms it - to either a literal context or a :class:`web.common.nonliterals.Context` - - :param context: the context to parse, if the context is not a string it - is assumed to be a literal domain and is returned as-is - :param session: Current OpenERP session - :type session: openerpweb.openerpweb.OpenERPSession - """ - if not isinstance(context, (str, unicode)): - return context - try: - return ast.literal_eval(context) - except ValueError: - return web.common.nonliterals.Context(session, context) - def parse_domains_and_contexts(self, elem, session): """ Converts domains and contexts from the view into Python objects, either literals if they can be parsed by literal_eval or a special @@ -889,16 +862,49 @@ class View(openerpweb.Controller): for el in ['domain', 'filter_domain']: domain = elem.get(el, '').strip() if domain: - elem.set(el, self.parse_domain(domain, session)) + elem.set(el, parse_domain(domain, session)) for el in ['context', 'default_get']: context_string = elem.get(el, '').strip() if context_string: - elem.set(el, self.parse_context(context_string, session)) + elem.set(el, parse_context(context_string, session)) @openerpweb.jsonrequest def load(self, req, model, view_id, view_type, toolbar=False): return self.fields_view_get(req, model, view_id, view_type, toolbar=toolbar) +def parse_domain(domain, session): + """ Parses an arbitrary string containing a domain, transforms it + to either a literal domain or a :class:`web.common.nonliterals.Domain` + + :param domain: the domain to parse, if the domain is not a string it + is assumed to be a literal domain and is returned as-is + :param session: Current OpenERP session + :type session: openerpweb.openerpweb.OpenERPSession + """ + if not isinstance(domain, (str, unicode)): + return domain + try: + return ast.literal_eval(domain) + except ValueError: + # not a literal + return web.common.nonliterals.Domain(session, domain) + +def parse_context(context, session): + """ Parses an arbitrary string containing a context, transforms it + to either a literal context or a :class:`web.common.nonliterals.Context` + + :param context: the context to parse, if the context is not a string it + is assumed to be a literal domain and is returned as-is + :param session: Current OpenERP session + :type session: openerpweb.openerpweb.OpenERPSession + """ + if not isinstance(context, (str, unicode)): + return context + try: + return ast.literal_eval(context) + except ValueError: + return web.common.nonliterals.Context(session, context) + class ListView(View): _cp_path = "/web/listview" @@ -944,9 +950,9 @@ class SearchView(View): for field in fields.values(): # shouldn't convert the views too? if field.get('domain'): - field["domain"] = self.parse_domain(field["domain"], req.session) + field["domain"] = parse_domain(field["domain"], req.session) if field.get('context'): - field["context"] = self.parse_domain(field["context"], req.session) + field["context"] = parse_context(field["context"], req.session) return {'fields': fields} @openerpweb.jsonrequest @@ -954,8 +960,8 @@ class SearchView(View): Model = req.session.model("ir.filters") filters = Model.get_filters(model) for filter in filters: - filter["context"] = req.session.eval_context(self.parse_context(filter["context"], req.session)) - filter["domain"] = req.session.eval_domain(self.parse_domain(filter["domain"], req.session)) + filter["context"] = req.session.eval_context(parse_context(filter["context"], req.session)) + filter["domain"] = req.session.eval_domain(parse_domain(filter["domain"], req.session)) return filters @openerpweb.jsonrequest @@ -1071,7 +1077,7 @@ class Action(openerpweb.Controller): _cp_path = "/web/action" @openerpweb.jsonrequest - def load(self, req, action_id): + def load(self, req, action_id, do_not_eval=False): Actions = req.session.model('ir.actions.actions') value = False context = req.session.eval_context(req.context) @@ -1083,7 +1089,7 @@ class Action(openerpweb.Controller): ctx.update(context) action = req.session.model(action_type[0]['type']).read([action_id], False, ctx) if action: - value = clean_action(req, action[0]) + value = clean_action(req, action[0], do_not_eval) return {'result': value} @openerpweb.jsonrequest -- cgit v1.2.3 From da7e08aa1bf81af5d84e0eb30add8324b3da57c1 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Tue, 18 Oct 2011 22:13:37 +0200 Subject: [IMP] html_template more generic bzr revid: al@openerp.com-20111018201337-tuh6wglp1qrixx5h --- addons/web/controllers/main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'addons/web/controllers/main.py') diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index d8e587e3d4d..e1fbe0370d7 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -9,7 +9,6 @@ import operator import os import re import simplejson -import textwrap import time import xmlrpclib import zlib @@ -41,7 +40,7 @@ def concat_files(file_list): files_concat = "".join(files_content) return files_concat,files_timestamp -home_template = textwrap.dedent(""" +html_template = """ @@ -51,15 +50,15 @@ home_template = textwrap.dedent(""" %(javascript)s -""") +""" + class WebClient(openerpweb.Controller): _cp_path = "/web/webclient" @@ -118,10 +117,11 @@ class WebClient(openerpweb.Controller): js = "\n ".join(''%i for i in self.manifest_list(req, None, 'js')) css = "\n ".join(''%i for i in self.manifest_list(req, None, 'css')) - r = home_template % { + r = html_template % { 'javascript': js, 'css': css, 'modules': simplejson.dumps(self.server_wide_modules(req)), + 'init': 'new s.web.WebClient("oe").start();', } return r -- cgit v1.2.3 From 11b5c602ce7ed1cd52f7a0fbf5c5a65909ecc176 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Tue, 18 Oct 2011 22:24:29 +0200 Subject: [IMP] html_template more generic use js bzr revid: al@openerp.com-20111018202429-7aulbfuyze4vcbck --- addons/web/controllers/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web/controllers/main.py') diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index e1fbe0370d7..55e23aae979 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -47,7 +47,7 @@ html_template = """ OpenERP %(css)s - %(javascript)s + %(js)s