summaryrefslogtreecommitdiff
path: root/addons/website_mail/controllers/main.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2014-05-26 15:43:57 +0200
committerThibault Delavallée <tde@openerp.com>2014-05-27 08:54:37 +0200
commitef2c068ec312427a2527afad52f28a3817122a5a (patch)
treef4828a404d369728058100803c26d4c49dbee0ad /addons/website_mail/controllers/main.py
parenta37bad205b13cec4f19f8e84e28801278e3e36ca (diff)
[IMP] website_mail: improved snippet to subscribe to a mail.group.
Main modifications : - layout: input - button when not following, links (email - archives - unsubscribe) when following - when adding your email, update all other subscribe snippets input in the page to avoid havign to re-type it - management of fields of the record to subscribe to, used to have access to the alias of the group
Diffstat (limited to 'addons/website_mail/controllers/main.py')
-rw-r--r--addons/website_mail/controllers/main.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/addons/website_mail/controllers/main.py b/addons/website_mail/controllers/main.py
index a6b400ec4a1..49caf20f7ff 100644
--- a/addons/website_mail/controllers/main.py
+++ b/addons/website_mail/controllers/main.py
@@ -63,6 +63,7 @@ class WebsiteMail(http.Controller):
@http.route(['/website_mail/is_follower'], type='json', auth="public", website=True)
def call(self, model, id, **post):
+ id = int(id)
cr, uid, context = request.cr, request.uid, request.context
partner_obj = request.registry.get('res.partner')
@@ -76,17 +77,28 @@ class WebsiteMail(http.Controller):
partner_id = users_obj.browse(cr, SUPERUSER_ID, uid, context).partner_id
elif request.session.get('partner_id'):
partner_id = partner_obj.browse(cr, SUPERUSER_ID, request.session.get('partner_id'), context)
-
- email = ""
- is_follower = False
- if partner_id:
- email = partner_id and partner_id.email
- is_follower = partner_id.id in [
- fol.id for fol in obj.browse(cr, SUPERUSER_ID, id, context).message_follower_ids]
+ email = partner_id and partner_id.email or ""
- return {
+ values = {
'is_user': uid != public_id,
'email': email,
- 'is_follower': is_follower
+ 'is_follower': False,
}
+ if not obj:
+ return values
+ obj_ids = obj.exists(cr, SUPERUSER_ID, [id], context=context)
+ if obj_ids:
+ if partner_id:
+ values['is_follower'] = len(
+ request.registry['mail.followers'].search(
+ cr, SUPERUSER_ID, [
+ ('res_model', '=', 'mail.group'),
+ ('res_id', '=', obj_ids[0]),
+ ('partner_id', '=', partner_id.id)
+ ], context=context)) == 1
+ if post.get('fields'):
+ record = obj.read(cr, SUPERUSER_ID, obj_ids[0], fields=post.get('fields'), context=context)
+ values.update(record)
+
+ return values