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.

55 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.addons.website_mail.controllers.email_designer import\
  5. WebsiteEmailDesigner
  6. from openerp import http
  7. from openerp.http import request
  8. class UnquoteRecordset(object):
  9. def __init__(self, recordset, name):
  10. self.__recordset = recordset
  11. self.__name = name
  12. def __getitem__(self, key):
  13. if isinstance(key, basestring) and key in self.__recordset._fields:
  14. return self.__recordset[key]
  15. return UnquoteRecordset(
  16. self.__recordset[key], '%s[%s]' % (self.__name, key)
  17. )
  18. def __getattr__(self, name):
  19. recordset = self.__recordset
  20. if name in recordset._fields:
  21. if recordset._fields[name].relational:
  22. return UnquoteRecordset(
  23. recordset[name], '%s.%s' % (self.__name, name)
  24. )
  25. elif recordset._fields[name].type in ('char', 'text'):
  26. return '%s.%s' % (self.__name, name)
  27. elif recordset._fields[name].type in ('integer', 'float'):
  28. return 42
  29. else:
  30. return recordset[name]
  31. return getattr(recordset, name)
  32. class Main(WebsiteEmailDesigner):
  33. @http.route()
  34. def index(self, model, res_id, template_model=None, **kw):
  35. result = super(Main, self).index(
  36. model, res_id, template_model=template_model, **kw
  37. )
  38. env = request.env
  39. qcontext = result.qcontext
  40. record = qcontext.get('record', env['email.template'].new())
  41. if record.body_type == 'qweb':
  42. qcontext['body_field'] = 'body_view_id'
  43. qcontext['mode'] = 'email_designer'
  44. qcontext['object'] = UnquoteRecordset(
  45. env[record.model_id.model].new(),
  46. 'object',
  47. )
  48. qcontext['email_template'] = record
  49. return result