summaryrefslogtreecommitdiff
path: root/addons/website_mail/controllers
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2014-04-16 12:59:01 +0200
committerThibault Delavallée <tde@openerp.com>2014-04-16 12:59:01 +0200
commitd264cd164017795cee3a8b463eee318c7dc61552 (patch)
tree6c9bc66bc3c29e41d0c9d1bc4ecf5d2fd3878a7f /addons/website_mail/controllers
parentf9b2b667a0e3ac63aff55f48a98e5b47938c187a (diff)
[IMP] website_mail: make the template / mail editor work. We now have a limited
set of fields that we try to edit (body_html and body for body, email_from and email for email-from, name and subject for subject), because t-field is not dynamic. If the model that should be edited does not hold those fields, the mail editor won't work. Also fixed editor not being actiated when going into the body edition. bzr revid: tde@openerp.com-20140416105901-vavkh9erjsq4mof9
Diffstat (limited to 'addons/website_mail/controllers')
-rw-r--r--addons/website_mail/controllers/email_designer.py63
1 files changed, 47 insertions, 16 deletions
diff --git a/addons/website_mail/controllers/email_designer.py b/addons/website_mail/controllers/email_designer.py
index 8b343913399..447474ced36 100644
--- a/addons/website_mail/controllers/email_designer.py
+++ b/addons/website_mail/controllers/email_designer.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-# from openerp import SUPERUSER_ID
+from urllib import urlencode
+
from openerp.addons.web import http
from openerp.addons.web.http import request
@@ -8,33 +9,63 @@ from openerp.addons.web.http import request
class WebsiteEmailDesigner(http.Controller):
@http.route('/website_mail/email_designer', type='http', auth="user", website=True, multilang=True)
- def index(self, model, res_id, template_model, field_body='body', field_from='email_from', field_subject='name', **kw):
+ def index(self, model, res_id, template_model=None, **kw):
if not model or not model in request.registry or not res_id:
return request.redirect('/')
-# if not 'body' in request.registry[model]._all_columns and not 'body_html' in request.registry[model]._all_columns:
-# return request.redirect('/')
+ model_cols = request.registry[model]._all_columns
+ if 'body' not in model_cols and 'body_html' not in model_cols or \
+ 'email' not in model_cols and 'email_from' not in model_cols or \
+ 'name' not in model_cols and 'subject' not in model_cols:
+ return request.redirect('/')
obj_ids = request.registry[model].exists(request.cr, request.uid, [res_id], context=request.context)
if not obj_ids:
return request.redirect('/')
+ # try to find fields to display / edit -> as t-field is static, we have to limit
+ # the available fields to a given subset
+ email_from_field = 'email'
+ if 'email_from' in model_cols:
+ email_from_field = 'email_from'
+ subject_field = 'name'
+ if 'subject' in model_cols:
+ subject_field = 'subject'
+ body_field = 'body'
+ if 'body_html' in model_cols:
+ body_field = 'body_html'
+
cr, uid, context = request.cr, request.uid, request.context
- tmpl_obj = request.registry['email.template']
res_id = int(res_id)
+ record = request.registry[model].browse(cr, uid, res_id, context=context)
- tids = tmpl_obj.search(cr, uid, [('model','=',template_model)], context=context)
- templates = tmpl_obj.browse(cr, uid, tids, context=context)
-
- print templates
values = {
- 'object': request.registry[model].browse(cr, uid, res_id, context=context),
- 'templates': templates,
+ 'record': record,
+ 'templates': None,
'model': model,
'res_id': res_id,
- 'field_body': field_body,
- 'field_from': field_from,
- 'field_subject': field_subject,
+ 'email_from_field': email_from_field,
+ 'subject_field': subject_field,
+ 'body_field': body_field,
}
- print '*', values
- return request.website.render("website_mail.designer_index", values)
+
+ if getattr(record, body_field):
+ values['mode'] = 'email_designer'
+ else:
+ if kw.get('enable_editor'):
+ kw.pop('enable_editor')
+ fragments = dict(model=model, res_id=res_id, **kw)
+ if template_model:
+ fragments['template_model'] = template_model
+ return request.redirect('/website_mail/email_designer?%s' % urlencode(fragments))
+ values['mode'] = 'email_template'
+
+ tmpl_obj = request.registry['email.template']
+ if template_model:
+ tids = tmpl_obj.search(cr, uid, [('model', '=', template_model)], context=context)
+ else:
+ tids = tmpl_obj.search(cr, uid, [], context=context)
+ templates = tmpl_obj.browse(cr, uid, tids, context=context)
+ values['templates'] = templates
+
+ return request.website.render("website_mail.email_designer", values)
@http.route(['/website_mail/snippets'], type='json', auth="user", website=True)
def snippets(self):