Browse Source

Merge 3397ca6ae6 into dabb3bb7ff

pull/163/merge
Holger Brunn 5 years ago
committed by GitHub
parent
commit
9eca5a8456
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      website_mail_qweb/README.rst
  2. 4
      website_mail_qweb/__init__.py
  3. 20
      website_mail_qweb/__openerp__.py
  4. 4
      website_mail_qweb/controllers/__init__.py
  5. 55
      website_mail_qweb/controllers/main.py
  6. BIN
      website_mail_qweb/static/description/icon.png
  7. 4
      website_mail_qweb/tests/__init__.py
  8. 30
      website_mail_qweb/tests/test_website_mail_qweb.py
  9. 12
      website_mail_qweb/views/templates.xml

64
website_mail_qweb/README.rst

@ -0,0 +1,64 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=========================
Edit QWeb email templates
=========================
This module was written to make Odoo's WYSIWYG email template editor usable for email templates using the QWeb rendering engine.
Usage
=====
To use this module, you need to:
#. click the 'Edit template' button on an email template
#. note that the editor supports designing and translating your templates, but for variable substitutions et al, you'll need to edit the source code of the template
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/8.0
Known issues / Roadmap
======================
* the editor has problems with complex template inheritance, this seems rather a problem in Odoo generally than with this specific module
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

4
website_mail_qweb/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import controllers

20
website_mail_qweb/__openerp__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Edit QWeb email templates",
"version": "8.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Hidden",
"summary": "Glue module to enable the wysiwyg editor for qweb email "
"templates",
"depends": [
'website_mail',
'email_template_qweb',
],
"data": [
'views/templates.xml',
],
"auto_install": True,
}

4
website_mail_qweb/controllers/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import main

55
website_mail_qweb/controllers/main.py

@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.addons.website_mail.controllers.email_designer import\
WebsiteEmailDesigner
from openerp import http
from openerp.http import request
class UnquoteRecordset(object):
def __init__(self, recordset, name):
self.__recordset = recordset
self.__name = name
def __getitem__(self, key):
if isinstance(key, basestring) and key in self.__recordset._fields:
return self.__recordset[key]
return UnquoteRecordset(
self.__recordset[key], '%s[%s]' % (self.__name, key)
)
def __getattr__(self, name):
recordset = self.__recordset
if name in recordset._fields:
if recordset._fields[name].relational:
return UnquoteRecordset(
recordset[name], '%s.%s' % (self.__name, name)
)
elif recordset._fields[name].type in ('char', 'text'):
return '%s.%s' % (self.__name, name)
elif recordset._fields[name].type in ('integer', 'float'):
return 42
else:
return recordset[name]
return getattr(recordset, name)
class Main(WebsiteEmailDesigner):
@http.route()
def index(self, model, res_id, template_model=None, **kw):
result = super(Main, self).index(
model, res_id, template_model=template_model, **kw
)
env = request.env
qcontext = result.qcontext
record = qcontext.get('record', env['email.template'].new())
if record.body_type == 'qweb':
qcontext['body_field'] = 'body_view_id'
qcontext['mode'] = 'email_designer'
qcontext['object'] = UnquoteRecordset(
env[record.model_id.model].new(),
'object',
)
qcontext['email_template'] = record
return result

BIN
website_mail_qweb/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

4
website_mail_qweb/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_website_mail_qweb

30
website_mail_qweb/tests/test_website_mail_qweb.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import HttpCase
from ..controllers.main import UnquoteRecordset
class TestWebsiteMailQweb(HttpCase):
def test_website_mail_qweb(self):
self.authenticate('admin', 'admin')
result = self.url_open(
'/website_mail/email_designer?model=email.template&res_id=%s' %
self.env.ref('email_template_qweb.email_template_demo1').id
)
self.assertIn('Dear object.name,', result.read())
def test_unquote_recordset(self):
record = UnquoteRecordset(self.env['res.partner'].new(), 'object')
self.assertEqual(record.name, 'object.name')
self.assertEqual(record.parent_id.name, 'object.parent_id.name')
self.assertEqual(record.id, 42)
self.assertEqual(
record.create_date,
self.env['res.partner']._fields['create_date'].null(self.env)
)
self.assertEqual(
record[:1]['create_date'],
self.env['res.partner']._fields['create_date'].null(self.env)
)
self.assertEqual(record._fields, self.env['res.partner']._fields)

12
website_mail_qweb/views/templates.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="email_designer" inherit_id="website_mail.email_designer">
<xpath expr="//div[@t-field='record.body']/parent::div" position="after">
<div t-if="body_field == 'body_view_id'" class="col-sm-offset-2">
<t t-call="{{record.body_view_id.id}}" />
</div>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save