Here is the real server side patch
Please review this at http://codereview.appspot.com/4105052/
Affected files:
M trytond/convert.py
M trytond/ir/action.py
M trytond/ir/ui/__init__.py
M trytond/ir/ui/form.rnc
M trytond/ir/ui/form.rng
A trytond/ir/ui/icon.py
Index: trytond/convert.py
===================================================================
--- a/trytond/convert.py
+++ b/trytond/convert.py
@@ -62,7 +62,7 @@
# TODO maybe use a prefetch for this:
cursor.execute(cursor.limit_clause(
- "SELECT a.name, a.type, act.view_type, v.type " \
+ "SELECT a.name, a.type, act.view_type, v.type, icon.name " \
"FROM ir_action a " \
"LEFT JOIN ir_action_report report ON (a.id =
report.action) " \
"LEFT JOIN ir_action_act_window act ON (a.id =
act.action) " \
@@ -71,13 +71,14 @@
"LEFT JOIN ir_action_act_window_view wv ON " \
"(act.id = wv.act_window) " \
"LEFT JOIN ir_ui_view v on (v.id = wv.view) " \
+ "LEFT JOIN ir_ui_icon icon on (a.icon = icon.id) " \
"WHERE report.id = %s " \
"OR act.id = %s " \
"OR wizard.id = %s " \
"OR url.id = %s " \
"ORDER by wv.sequence", 1),
(action_id, action_id, action_id, action_id))
- action_name, action_type, view_type, view_mode = \
+ action_name, action_type, view_type, view_mode, icon_name = \
cursor.fetchone()
values['action'] = '%s,%s' % (action_type, action_id)
@@ -85,6 +86,8 @@
icon = attributes.get('icon', '')
if icon:
values['icon'] = icon
+ elif icon_name:
+ values['icon'] = icon_name
elif action_type == 'ir.action.wizard':
values['icon'] = 'tryton-executable'
elif action_type == 'ir.action.report':
@@ -126,7 +129,6 @@
self.values = values
-
def characters(self, data):
pass
Index: trytond/ir/action.py
===================================================================
--- a/trytond/ir/action.py
+++ b/trytond/ir/action.py
@@ -22,6 +22,7 @@
'Keywords')
groups = fields.Many2Many('ir.action-res.group', 'action_id', 'gid',
'Groups')
+ icon = fields.Many2One('ir.ui.icon', 'Icon')
active = fields.Boolean('Active', select=2)
def __init__(self):
@@ -183,15 +184,18 @@
('action', '=', action_keyword.action.id),
])
if action_id:
- res.append(action_obj.read(action_id[0]))
+ columns = set(action_obj._columns.keys()
+ + action_obj._inherit_fields.keys())
+ columns.add('icon.rec_name')
if action_keyword.action.type == 'ir.action.report':
- del res[-1]['report_content_data']
- del res[-1]['report_content']
- del res[-1]['style_content']
- res[-1]['email'] = encoder.encode(res[-1]['email'])
+ to_remove = ('report_content_data', 'report_content',
+ 'style_content')
elif action_keyword.action.type == 'ir.action.act_window':
- for field in ('domain', 'context', 'search_value'):
- del res[-1][field]
+ to_remove = ('domain', 'context', 'search_value')
+ else:
+ to_remove = set()
+ columns.difference_update(to_remove)
+ res.append(action_obj.read(action_id[0], list(columns)))
return res
ActionKeyword()
Index: trytond/ir/ui/__init__.py
===================================================================
--- a/trytond/ir/ui/__init__.py
+++ b/trytond/ir/ui/__init__.py
@@ -2,3 +2,4 @@
#this repository contains the full copyright notices and license terms.
from menu import *
from view import *
+from icon import *
Index: trytond/ir/ui/form.rnc
===================================================================
--- a/trytond/ir/ui/form.rnc
+++ b/trytond/ir/ui/form.rnc
@@ -179,6 +179,7 @@
| vpaned)*
}
attlist.page &= attribute angle { text }?
+attlist.page &= attribute icon { text }?
attlist.page &=
[ a:defaultValue = "Unknown" ] attribute string { text }?
attlist.page &= [ a:defaultValue = "4" ] attribute col { text }?
Index: trytond/ir/ui/form.rng
===================================================================
--- a/trytond/ir/ui/form.rng
+++ b/trytond/ir/ui/form.rng
@@ -663,6 +663,11 @@
</define>
<define name="attlist.page" combine="interleave">
<optional>
+ <attribute name="icon"/>
+ </optional>
+ </define>
+ <define name="attlist.page" combine="interleave">
+ <optional>
<attribute name="string" a:defaultValue="Unknown"/>
</optional>
</define>
Index: trytond/ir/ui/icon.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/trytond/ir/ui/icon.py
@@ -0,0 +1,39 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of this
+# repository contains the full copyright notices and license terms.
+
+import os
+
+from trytond.model import ModelView, ModelSQL, fields
+from trytond.tools import file_open
+from trytond.transaction import Transaction
+
+
+class Icon(ModelSQL, ModelView):
+ 'Icon'
+ _name = 'ir.ui.icon'
+ _description = __doc__
+
+ name = fields.Char('Name', required=True, select=1)
+ module = fields.Char('Module', readonly=True)
+ path = fields.Char('SVG Path', readonly=True)
+ icon = fields.Function(fields.Char('Icon',
depends=['path']), 'get_icon')
+
+ def __init__(self):
+ super(Icon, self).__init__()
+ self._order.insert(0, ('id', 'ASC'))
+ self._sql_constraints += [('iconname_uniq', 'UNIQUE(name)',
+ 'The icon name must be unique!')]
+
+ def default_module(self):
+ return Transaction().context.get('module') or ''
+
+ def get_icon(self, ids, name):
+ print ids
+ result = {}
+ for icon in self.browse(ids):
+ path = os.path.join(icon.module, icon.path.replace('/',
os.sep))
+ with file_open(path, subdir='modules') as fp:
+ result[icon.id] = fp.read()
+ return result
+
+Icon()
--
[email protected] mailing list