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.

73 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Authors: Laurent Mignon
  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 import models, exceptions
  30. from openerp.tools.translate import _
  31. class HelpOnline(models.TransientModel):
  32. _name = 'help.online'
  33. def _get_view_name(self, model, view_type, domain=None, context=None):
  34. parameter_model = self.env['ir.config_parameter']
  35. page_prefix = parameter_model.get_param('help_online_page_prefix',
  36. False)
  37. if not page_prefix:
  38. raise exceptions.Warning(_('No page prefix parameter specified !'))
  39. name = '%s-%s' % (page_prefix, model.replace('.', '-'))
  40. return name
  41. def page_exists(self, name):
  42. website_model = self.env['website']
  43. return website_model.page_exists(name)
  44. def get_page_url(self, model, view_type, domain=None, context=None):
  45. user_model = self.env['res.users']
  46. if not user_model.has_group('help_online.help_online_group_reader'):
  47. return {}
  48. ir_model = self.env['ir.model']
  49. description = self.env[model]._description
  50. res = ir_model.name_search(model, operator='=')
  51. if(res):
  52. description = res[0][1]
  53. name = self._get_view_name(model, view_type, domain, context)
  54. if self.page_exists(name):
  55. url = '/page/%s' % name
  56. if view_type:
  57. url = url + '#' + view_type
  58. title = _('Help on %s') % description
  59. return {'url': url,
  60. 'title': title,
  61. 'exists': True}
  62. elif user_model.has_group('help_online.help_online_group_writer'):
  63. title = _('Create Help page for %s') % description
  64. return {'url': 'website/add/%s' % name,
  65. 'title': title,
  66. 'exists': False}
  67. else:
  68. return {}