You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Adrien Peiffer
  5. # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
  6. # All Rights Reserved
  7. #
  8. # WARNING: This program as such is intended to be used by professional
  9. # programmers who take the whole responsibility of assessing all potential
  10. # consequences resulting from its eventual inadequacies and bugs.
  11. # End users who are looking for a ready-to-use solution with commercial
  12. # guarantees and support are strongly advised to contact a Free Software
  13. # Service Company.
  14. #
  15. # This program is free software: you can redistribute it and/or modify
  16. # it under the terms of the GNU Affero General Public License as
  17. # published by the Free Software Foundation, either version 3 of the
  18. # License, or (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU Affero General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU Affero General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. #
  28. #
  29. from openerp.osv import orm, fields
  30. class web_shortcut(orm.Model):
  31. _name = 'web.shortcut'
  32. _columns = {
  33. 'name': fields.char('Shortcut Name', size=64),
  34. 'menu_id': fields.many2one('ir.ui.menu'),
  35. 'user_id': fields.many2one('res.users', 'User Ref.', required=True,
  36. ondelete='cascade', select=True),
  37. }
  38. def get_user_shortcuts(self, cr, uid, user_id, context=None):
  39. ids = self.search(cr, uid, [('user_id', '=', user_id)],
  40. context=context)
  41. results = self.read(cr, uid, ids, ['menu_id'], context=context)
  42. name_map = dict(self.pool.get('ir.ui.menu')
  43. .name_get(cr, uid, [x['menu_id'][0] for x in results],
  44. context=context))
  45. # Make sure to return only shortcuts pointing to exisintg menu items.
  46. filtered_results = filter(lambda result: result['menu_id'][0] in
  47. name_map, results)
  48. for result in filtered_results:
  49. result.update(name=name_map[result['menu_id'][0]])
  50. return filtered_results
  51. _order = 'name'
  52. _defaults = {
  53. 'user_id': lambda obj, cr, uid, context: uid,
  54. }
  55. _sql_constraints = [
  56. ('shortcut_unique', 'unique(menu_id,user_id)',
  57. 'Shortcut for this menu already exists!'),
  58. ]
  59. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: