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.

50 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, exceptions
  5. from openerp.tools.translate import _
  6. class HelpOnline(models.TransientModel):
  7. _name = 'help.online'
  8. def _get_view_name(self, model, view_type, domain=None, context=None):
  9. parameter_model = self.env['ir.config_parameter']
  10. page_prefix = parameter_model.get_param('help_online_page_prefix',
  11. False)
  12. if not page_prefix:
  13. raise exceptions.Warning(_('No page prefix parameter specified !'))
  14. name = '%s-%s' % (page_prefix, model.replace('.', '-'))
  15. return name
  16. def get_existing_pages(self, name, limit=None):
  17. website = self.env['website']
  18. return website.search_pages(needle=name, limit=limit)
  19. def get_page_url(self, model, view_type, domain=None, context=None):
  20. user_model = self.env['res.users']
  21. if not user_model.has_group('help_online.help_online_group_reader'):
  22. return {}
  23. ir_model = self.env['ir.model']
  24. description = self.env[model]._description
  25. res = ir_model.name_search(model, operator='=')
  26. if res:
  27. description = res[0][1]
  28. name = self._get_view_name(model, view_type, domain, context)
  29. pages = self.get_existing_pages(name, limit=1)
  30. if pages:
  31. url = pages[0]['loc']
  32. if view_type:
  33. url = url + '#' + view_type
  34. title = _('Help on %s') % description
  35. return {'url': url,
  36. 'title': title,
  37. 'exists': True}
  38. elif user_model.has_group('help_online.help_online_group_writer'):
  39. title = _('Create Help page for %s') % description
  40. return {'url': 'website/add/%s' % name,
  41. 'title': title,
  42. 'exists': False}
  43. else:
  44. return {}