From 3ec4ad320182432293c6d5f0b0dbb4448d6874b9 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 19 Jan 2012 09:52:13 +0100 Subject: [PATCH 1/2] =?UTF-8?q?[REF]=C2=A0code=20review.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bzr revid: florent.xicluna@gmail.com-20120119085213-94b2p3268q25bni2 --- addons/web/common/openerplib/main.py | 2 +- addons/web/controllers/main.py | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/web/common/openerplib/main.py b/addons/web/common/openerplib/main.py index 93c2d1da69d..fdcd392973d 100644 --- a/addons/web/common/openerplib/main.py +++ b/addons/web/common/openerplib/main.py @@ -249,7 +249,7 @@ class Model(object): method, args, kw) if method == "read": - if isinstance(result, list) and len(result) > 0 and "id" in result[0]: + if result and isinstance(result, list) and "id" in result[0]: index = {} for r in result: index[r['id']] = r diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 2af7ac115d8..4c7a9647b62 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -213,7 +213,7 @@ class WebClient(openerpweb.Controller): else: lang_obj = None - if lang.count("_") > 0: + if "_" in lang: separator = "_" else: separator = "@" @@ -224,15 +224,15 @@ class WebClient(openerpweb.Controller): for addon_name in mods: transl = {"messages":[]} transs[addon_name] = transl + addons_path = openerpweb.addons_manifest[addon_name]['addons_path'] for l in langs: - addons_path = openerpweb.addons_manifest[addon_name]['addons_path'] f_name = os.path.join(addons_path, addon_name, "po", l + ".po") if not os.path.exists(f_name): continue try: with open(f_name) as t_file: po = babel.messages.pofile.read_po(t_file) - except: + except Exception: continue for x in po: if x.id and x.string: @@ -399,7 +399,7 @@ class Session(openerpweb.Controller): if req.session.model('res.users').change_password( old_password, new_password): return {'new_password':new_password} - except: + except Exception: return {'error': 'Original password incorrect, your password was not changed.', 'title': 'Change Password'} return {'error': 'Error, password not changed !', 'title': 'Change Password'} @@ -508,7 +508,7 @@ class Session(openerpweb.Controller): req.httpsession['saved_actions'] = saved_actions # we don't allow more than 10 stored actions if len(saved_actions["actions"]) >= 10: - del saved_actions["actions"][min(saved_actions["actions"].keys())] + del saved_actions["actions"][min(saved_actions["actions"])] key = saved_actions["next"] saved_actions["actions"][key] = the_action saved_actions["next"] = key + 1 @@ -569,10 +569,9 @@ def clean_action(req, action, do_not_eval=False): if 'domain' in action: action['domain'] = parse_domain(action['domain'], req.session) - if 'type' not in action: - action['type'] = 'ir.actions.act_window_close' + action_type = action.setdefault('type', 'ir.actions.act_window_close') - if action['type'] == 'ir.actions.act_window': + if action_type == 'ir.actions.act_window': return fix_view_modes(action) return action @@ -691,7 +690,7 @@ class Menu(openerpweb.Controller): # sort by sequence a tree using parent_id for menu_item in menu_items: menu_item.setdefault('children', []).sort( - key=lambda x:x["sequence"]) + key=operator.itemgetter('sequence')) return menu_root @@ -744,7 +743,7 @@ class DataSet(openerpweb.Controller): # shortcut read if we only want the ids return { 'ids': ids, - 'records': map(lambda id: {'id': id}, paginated_ids) + 'records': [{'id': id} for id in paginated_ids] } records = Model.read(paginated_ids, fields or False, context) @@ -1015,7 +1014,7 @@ def parse_domain(domain, session): :param session: Current OpenERP session :type session: openerpweb.openerpweb.OpenERPSession """ - if not isinstance(domain, (str, unicode)): + if not isinstance(domain, basestring): return domain try: return ast.literal_eval(domain) @@ -1032,7 +1031,7 @@ def parse_context(context, session): :param session: Current OpenERP session :type session: openerpweb.openerpweb.OpenERPSession """ - if not isinstance(context, (str, unicode)): + if not isinstance(context, basestring): return context try: return ast.literal_eval(context) @@ -1500,7 +1499,7 @@ class CSVExport(Export): d = d.replace('\n',' ').replace('\t',' ') try: d = d.encode('utf-8') - except: + except UnicodeError: pass if d is False: d = None row.append(d) From b540f5ad3f34b4797b2c963205ed4beb6dcb9cc3 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 19 Jan 2012 10:35:20 +0100 Subject: [PATCH 2/2] [REF] the openerplib should be fixed upstream. bzr revid: florent.xicluna@gmail.com-20120119093520-92udlqrq8ufyw43s --- addons/web/common/openerplib/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/common/openerplib/main.py b/addons/web/common/openerplib/main.py index fdcd392973d..93c2d1da69d 100644 --- a/addons/web/common/openerplib/main.py +++ b/addons/web/common/openerplib/main.py @@ -249,7 +249,7 @@ class Model(object): method, args, kw) if method == "read": - if result and isinstance(result, list) and "id" in result[0]: + if isinstance(result, list) and len(result) > 0 and "id" in result[0]: index = {} for r in result: index[r['id']] = r