Merge lp:~camptocamp/openerp-product-attributes/7.0-fix-translate-view-lep into lp:~product-core-editors/openerp-product-attributes/7.0

Proposed by Leonardo Pistone
Status: Merged
Approved by: Alexandre Fayolle - camptocamp
Approved revision: 235
Merged at revision: 238
Proposed branch: lp:~camptocamp/openerp-product-attributes/7.0-fix-translate-view-lep
Merge into: lp:~product-core-editors/openerp-product-attributes/7.0
Diff against target: 84 lines (+25/-6)
2 files modified
product_custom_attributes/product.py (+15/-3)
production_lot_custom_attributes/lot.py (+10/-3)
To merge this branch: bzr merge lp:~camptocamp/openerp-product-attributes/7.0-fix-translate-view-lep
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test Approve
Romain Deheele - Camptocamp (community) code review Approve
Pedro Manuel Baeza code review Approve
Review via email: mp+211792@code.launchpad.net
To post a comment you must log in.
235. By Leonardo Pistone

[fix] production_lot_custom_attributes: translations in views are of type 'view'. The method "_" only gets other translation types. I then define my local translation method to avoid the magic of "_"

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

LGTM.

Thanks for discovering a method to do it.

Regards.

review: Approve (code review)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

LGTM.

Maybe the (small) duplication could be avoided by using an intermediate class:

class Translator(object):
   def __init__(cr, context):
       self.cr = cr
       self.context = context

   def __call__(self, source):
       return translate(self.cr, None, 'view', self.context.get('lang'), source) or source

and then instantiate translate_view = Translator(cr, context), and call translate_view where needed.

review: Needs Information
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

add missing 'self' to __init__

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks Alexandre.

I like your proposal very much, but in that case I'd rather leave things as they are since I'm dealing with two different modules.

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Interesting, LGTM,

Romain

review: Approve (code review)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

ok then

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product_custom_attributes/product.py'
2--- product_custom_attributes/product.py 2013-09-30 11:55:27 +0000
3+++ product_custom_attributes/product.py 2014-03-19 17:54:31 +0000
4@@ -23,7 +23,7 @@
5 from openerp.osv import fields
6 from openerp.osv.osv import except_osv
7 from openerp.osv.orm import setup_modifiers
8-from tools.translate import _
9+from tools.translate import translate
10 from lxml import etree
11
12 class product_template(Model):
13@@ -91,6 +91,13 @@
14 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
15 if context is None:
16 context = {}
17+
18+ def translate_view(source):
19+ """Return a translation of type view of source."""
20+ return translate(
21+ cr, None, 'view', context.get('lang'), source
22+ ) or source
23+
24 result = super(product_product, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar, submenu=submenu)
25 if view_type == 'form' and context.get('attribute_group_ids'):
26 eview = etree.fromstring(result['arch'])
27@@ -105,9 +112,14 @@
28 placeholder = eview.xpath("//separator[@string='attributes_placeholder']")[0]
29 placeholder.getparent().replace(placeholder, attributes_notebook)
30 elif context.get('open_product_by_attribute_set'):
31- main_page = etree.Element('page', string=_('Custom Attributes'))
32+ main_page = etree.Element(
33+ 'page',
34+ string=translate_view('Custom Attributes')
35+ )
36 main_page.append(attributes_notebook)
37- info_page = eview.xpath("//page[@string='%s']" % (_('Information'),))[0]
38+ info_page = eview.xpath(
39+ "//page[@string='%s']" % (translate_view('Information'),)
40+ )[0]
41 info_page.addnext(main_page)
42 result['arch'] = etree.tostring(eview, pretty_print=True)
43 result = self._fix_size_bug(cr, uid, result, context=context)
44
45=== modified file 'production_lot_custom_attributes/lot.py'
46--- production_lot_custom_attributes/lot.py 2013-11-25 16:18:26 +0000
47+++ production_lot_custom_attributes/lot.py 2014-03-19 17:54:31 +0000
48@@ -24,7 +24,7 @@
49
50 from openerp.osv.orm import Model
51 from openerp.osv import fields
52-from tools.translate import _
53+from tools.translate import translate
54 from lxml import etree
55
56
57@@ -89,6 +89,13 @@
58 context=None, toolbar=False, submenu=False):
59 if context is None:
60 context = {}
61+
62+ def translate_view(source):
63+ """Return a translation of type view of source."""
64+ return translate(
65+ cr, None, 'view', context.get('lang'), source
66+ ) or source
67+
68 attr_pool = self.pool.get('attribute.attribute')
69 result = super(stock_production_lot, self).fields_view_get(
70 cr, uid, view_id, view_type, context, toolbar=toolbar,
71@@ -122,11 +129,11 @@
72 # in this case, we know the attribute set beforehand, and we
73 # add the attributes to the current view
74 main_page = etree.Element(
75- 'page', string=_('Custom Attributes')
76+ 'page', string=translate_view('Custom Attributes')
77 )
78 main_page.append(attributes_notebook)
79 info_page = eview.xpath(
80- "//page[@string='%s']" % (_('Stock Moves'),)
81+ "//page[@string='%s']" % (translate_view('Stock Moves'),)
82 )[0]
83 info_page.addnext(main_page)
84 result['arch'] = etree.tostring(eview, pretty_print=True)

Subscribers

People subscribed via source and target branches