diff --git a/INSTALL b/INSTALL index eabdbf4f0b..63a221bde7 100644 --- a/INSTALL +++ b/INSTALL @@ -4,7 +4,7 @@ Installing trytond_dashboard Prerequisites ------------- - * Python 2.4 or later (http://www.python.org/) + * Python 2.5 or later (http://www.python.org/) * lxml (http://codespeak.net/lxml/) * trytond (http://www.tryton.org/) diff --git a/ir.py b/ir.py index ddd8e02deb..8fa4960a34 100644 --- a/ir.py +++ b/ir.py @@ -1,78 +1,67 @@ #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 math +from lxml import etree from trytond.model import Model, fields from trytond.tools import Cache -from lxml import etree -import math +from trytond.transaction import Transaction class View(Model): _name = 'ir.ui.view' - def dashboard_id(self, cursor, user, context=None): + def dashboard_id(self): ''' Return the database id of view_dashboard - :param cursor: the database cursor :param user: the user id - :param context: the context :return: an integer ''' model_data_obj = self.pool.get('ir.model.data') - model_data_ids = model_data_obj.search(cursor, user, [ + model_data_ids = model_data_obj.search([ ('fs_id', '=', 'view_dashboard'), ('module', '=', 'dashboard'), ('inherit', '=', False), - ], limit=1, context=context) + ], limit=1) if not model_data_ids: return 0 - model_data = model_data_obj.browse(cursor, user, model_data_ids[0], - context=context) + model_data = model_data_obj.browse(model_data_ids[0]) return model_data.db_id dashboard_id = Cache('ir.ui.view.dashboard_id')(dashboard_id) - def _dashboard_element_action(self, cursor, user, action, - context=None): + def _dashboard_element_action(self, action): ''' Return etree Element for the given dashboard action. - :param cursor: the database cursor - :param user: the user id :param action: a BrowseRecord of dashboard.action - :param context: the context :return: an etree Element ''' return etree.Element('action', { 'name': str(action.act_window.id), }) - def dashboard_view(self, cursor, user_id, arch, context=None): + def dashboard_view(self, arch): ''' Add action to view arch of dashboard - :param cursor: the database cursor - :param user_id: the user id :param arch: a string with the xml arch of dashboard - :param context: the context :return: a string with the new xml arch ''' user_obj = self.pool.get('res.user') tree = etree.fromstring(arch) root = tree.getroottree().getroot() - user = user_obj.browse(cursor, user_id, user_id, context=context) + user = user_obj.browse(Transaction().user) if user.dashboard_layout == 'square': root.set('col', str(int(math.ceil(math.sqrt( len(user.dashboard_actions)))))) for action in user.dashboard_actions: - root.append(self._dashboard_element_action(cursor, - user_id, action, context=context)) + root.append(self._dashboard_element_action(action)) elif user.dashboard_layout == 'stack_right': group = None root.set('col', '2') for action in user.dashboard_actions: - element = self._dashboard_element_action(cursor, - user_id, action, context=context) + element = self._dashboard_element_action(action) if group is None: root.append(element) group = etree.Element('group', { @@ -89,8 +78,7 @@ class View(Model): root.append(group) first = True for action in user.dashboard_actions: - element = self._dashboard_element_action(cursor, - user_id, action, context=context) + element = self._dashboard_element_action(action) if first: first = False root.append(element) @@ -105,8 +93,7 @@ class View(Model): root.append(group) first = True for action in user.dashboard_actions: - element = self._dashboard_element_action(cursor, - user_id, action, context=context) + element = self._dashboard_element_action(action) if first: first = False root.append(element) @@ -120,8 +107,7 @@ class View(Model): }) first = True for action in user.dashboard_actions: - element = self._dashboard_element_action(cursor, - user_id, action, context=context) + element = self._dashboard_element_action(action) if first: first = False root.append(element) @@ -131,26 +117,23 @@ class View(Model): arch = etree.tostring(tree, encoding='utf-8') return arch - def read(self, cursor, user, ids, fields_names=None, context=None): - res = super(View, self).read(cursor, user, ids, - fields_names=fields_names, context=context) - if user == 0: + def read(self, ids, fields_names=None): + res = super(View, self).read(ids, fields_names=fields_names) + if Transaction().user == 0: return res - dashboard_id = self.dashboard_id(cursor, user, context=context) + dashboard_id = self.dashboard_id() if not dashboard_id: # Restart the cache - self.dashboard_id(cursor.dbname) + self.dashboard_id.reset() if fields_names is None \ or 'arch' in fields_names: if isinstance(ids, (int, long)): if dashboard_id == ids: - res['arch'] = self.dashboard_view(cursor, user, - res['arch'], context=context) + res['arch'] = self.dashboard_view(res['arch']) elif dashboard_id in ids: for res2 in res: if res2['id'] == dashboard_id: - res2['arch'] = self.dashboard_view(cursor, user, - res2['arch'], context=context) + res2['arch'] = self.dashboard_view(res2['arch']) return res View() diff --git a/res.py b/res.py index af26ed0543..d16899b0d3 100644 --- a/res.py +++ b/res.py @@ -2,6 +2,7 @@ #this repository contains the full copyright notices and license terms. from trytond.model import Model, fields from trytond.backend import TableHandler +from trytond.transaction import Transaction class User(Model): @@ -24,14 +25,15 @@ class User(Model): 'dashboard_actions', ] - def init(self, cursor, module_name): - super(User, self).init(cursor, module_name) + def init(self, module_name): + super(User, self).init(module_name) + cursor = Transaction().cursor table = TableHandler(cursor, self, module_name) # Migration from 1.6 table.not_null_action('dashboard_layout', action='remove') - def default_dashboard_layout(self, cursor, user, context=None): + def default_dashboard_layout(self): return 'square' User()