[Merge] website_mass_mailing: Migrate to new API
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import controllers
|
||||
from . import controllers
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Website Mass Mailing Campaigns',
|
||||
'description': """
|
||||
@@ -7,9 +10,9 @@ Add a snippet in the website builder to subscribe a mass_mailing list
|
||||
'category': 'Marketing',
|
||||
'depends': ['website', 'mass_mailing'],
|
||||
'data': [
|
||||
'views/website_mass_mailing.xml',
|
||||
'views/unsubscribe.xml',
|
||||
'views/snippets.xml',
|
||||
'views/website_mass_mailing_templates.xml',
|
||||
'views/unsubscribe_templates.xml',
|
||||
'views/snippets_templates.xml',
|
||||
],
|
||||
'auto_install': True,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import main
|
||||
from . import main
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp import http, SUPERUSER_ID
|
||||
from openerp.addons.mass_mailing.controllers.main import MassMailController
|
||||
from openerp.http import request
|
||||
from odoo.http import route, request
|
||||
from odoo.addons.mass_mailing.controllers.main import MassMailController
|
||||
|
||||
|
||||
class MassMailController(MassMailController):
|
||||
|
||||
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', website=True, auth='public')
|
||||
@route('/mail/mailing/<int:mailing_id>/unsubscribe', type='http', website=True, auth='public')
|
||||
def mailing(self, mailing_id, email=None, res_id=None, **post):
|
||||
mailing = request.env['mail.mass_mailing'].sudo().browse(mailing_id)
|
||||
if mailing.exists():
|
||||
@@ -21,55 +21,50 @@ class MassMailController(MassMailController):
|
||||
super(MassMailController, self).mailing(mailing_id, email=email, res_id=res_id, **post)
|
||||
return request.render('website_mass_mailing.page_unsubscribed')
|
||||
|
||||
@http.route(['/mail/mailing/unsubscribe'], type='json', auth='none')
|
||||
@route('/mail/mailing/unsubscribe', type='json', auth='none')
|
||||
def unsubscribe(self, mailing_id, opt_in_ids, opt_out_ids, email):
|
||||
mailing = request.env['mail.mass_mailing'].sudo().browse(mailing_id)
|
||||
if mailing.exists():
|
||||
mailing.update_opt_out(email, opt_in_ids, False)
|
||||
mailing.update_opt_out(email, opt_out_ids, True)
|
||||
|
||||
@http.route('/website_mass_mailing/is_subscriber', type='json', website=True, auth="public")
|
||||
@route('/website_mass_mailing/is_subscriber', type='json', website=True, auth="public")
|
||||
def is_subscriber(self, list_id, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
Contacts = request.registry['mail.mass_mailing.contact']
|
||||
Users = request.registry['res.users']
|
||||
|
||||
is_subscriber = False
|
||||
email = None
|
||||
if uid != request.website.user_id.id:
|
||||
email = Users.browse(cr, SUPERUSER_ID, uid, context).email
|
||||
if request.uid != request.website.user_id.id:
|
||||
email = request.env.user.email
|
||||
elif request.session.get('mass_mailing_email'):
|
||||
email = request.session['mass_mailing_email']
|
||||
|
||||
is_subscriber = False
|
||||
if email:
|
||||
contact_ids = Contacts.search(cr, SUPERUSER_ID, [('list_id', '=', int(list_id)), ('email', '=', email), ('opt_out', '=', False)], context=context)
|
||||
is_subscriber = len(contact_ids) > 0
|
||||
contacts_count = request.env['mail.mass_mailing.contact'].sudo().search_count([('list_id', '=', int(list_id)), ('email', '=', email), ('opt_out', '=', False)])
|
||||
is_subscriber = contacts_count > 0
|
||||
|
||||
return {'is_subscriber': is_subscriber, 'email': email}
|
||||
|
||||
@http.route('/website_mass_mailing/subscribe', type='json', website=True, auth="public")
|
||||
@route('/website_mass_mailing/subscribe', type='json', website=True, auth="public")
|
||||
def subscribe(self, list_id, email, **post):
|
||||
Contacts = request.env['mail.mass_mailing.contact'].sudo()
|
||||
parsed_email = Contacts.get_name_email(email)[1]
|
||||
name, email = Contacts.get_name_email(email)
|
||||
|
||||
contact_ids = Contacts.search_read(
|
||||
[('list_id', '=', int(list_id)), ('email', '=', parsed_email)],
|
||||
['opt_out'])
|
||||
contact_ids = Contacts.search([
|
||||
('list_id', '=', int(list_id)),
|
||||
('email', '=', email),
|
||||
], limit=1)
|
||||
if not contact_ids:
|
||||
Contacts.add_to_list(email, int(list_id))
|
||||
else:
|
||||
if contact_ids[0]['opt_out']:
|
||||
contact_ids[0].write({'opt_out': False})
|
||||
# inline add_to_list as we've already called half of it
|
||||
Contacts.create({'name': name, 'email': email, 'list_id': int(list_id)})
|
||||
elif contact_ids.opt_out:
|
||||
contact_ids.opt_out = False
|
||||
# add email to session
|
||||
request.session['mass_mailing_email'] = email
|
||||
return True
|
||||
|
||||
@http.route(['/website_mass_mailing/get_content'], type='json', website=True, auth="public")
|
||||
@route(['/website_mass_mailing/get_content'], type='json', website=True, auth="public")
|
||||
def get_mass_mailing_content(self, newsletter_id, **post):
|
||||
data = self.is_subscriber(newsletter_id, **post)
|
||||
mass_mailing_list = request.registry['mail.mass_mailing.list'].browse(request.cr, SUPERUSER_ID, int(newsletter_id), request.context)
|
||||
data.update({
|
||||
'content': mass_mailing_list.popup_content,
|
||||
'redirect_url': mass_mailing_list.popup_redirect_url
|
||||
})
|
||||
mass_mailing_list = request.env['mail.mass_mailing.list'].sudo().browse(int(newsletter_id))
|
||||
data['content'] = mass_mailing_list.popup_content,
|
||||
data['redirect_url'] = mass_mailing_list.popup_redirect_url
|
||||
return data
|
||||
|
||||
+2
-6
@@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<odoo>
|
||||
<template id="mailing_list_subscribe" inherit_id="website.snippets" name="Subscribe to Newsletter">
|
||||
|
||||
<xpath expr="//div[@id='snippet_content']/div[@class='o_panel_body']" position="inside">
|
||||
@@ -79,6 +77,4 @@
|
||||
</div>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="unsubscribe">
|
||||
<div class="container o_unsubscribe_form">
|
||||
<div class="row">
|
||||
<form action="/mail/mailing/unsubscribe" method="POST" id="unsubscribe_form">
|
||||
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
|
||||
<input type="hidden" name="email" t-att-value="email"/>
|
||||
<input type="hidden" name="mailing_id" t-att-value="mailing_id"/>
|
||||
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
|
||||
<h1 class="page-header">Mailing Subscriptions</h1>
|
||||
|
||||
<t t-if="contacts">
|
||||
<div class="alert alert-info text-center">
|
||||
<p>Choose your mailing subscriptions.</p>
|
||||
</div>
|
||||
|
||||
<ul class="list-group">
|
||||
<t t-foreach="contacts" t-as="contact">
|
||||
<li class="list-group-item">
|
||||
<input type="checkbox" class="mail_list_checkbox" name="contact_ids"
|
||||
t-att-value="contact['id']" t-att-checked="'checked' if contact['opt_out'] == False else None"/>
|
||||
<t t-esc="contact.list_id.name"/>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
|
||||
<div class="text-center mb16">
|
||||
<input type="submit" id="send_form" class="btn btn-primary" value="Update my subscriptions"/>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-if="contacts == False">
|
||||
<div class="alert alert-info text-center">
|
||||
<p>You are not subscribed to any of our mailing list.</p>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="unsubscribed">
|
||||
<div class="container mt8">
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h1 class="page-header">Mailing Subscriptions</h1>
|
||||
|
||||
<div class="alert alert-success text-center">
|
||||
<p>Your changes have been saved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="page_unsubscribe" name="Unsubscribe">
|
||||
<t t-call="website.layout">
|
||||
<t t-call="website_mass_mailing.unsubscribe"/>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="page_unsubscribed" name="Unsubscribed">
|
||||
<t t-call="website.layout">
|
||||
<t t-call="website_mass_mailing.unsubscribed"/>
|
||||
</t>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="unsubscribe">
|
||||
<div class="container o_unsubscribe_form">
|
||||
<div class="row">
|
||||
<form action="/mail/mailing/unsubscribe" method="POST" id="unsubscribe_form">
|
||||
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
|
||||
<input type="hidden" name="email" t-att-value="email"/>
|
||||
<input type="hidden" name="mailing_id" t-att-value="mailing_id"/>
|
||||
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
|
||||
<h1 class="page-header">Mailing Subscriptions</h1>
|
||||
|
||||
<t t-if="contacts">
|
||||
<div class="alert alert-info text-center">
|
||||
<p>Choose your mailing subscriptions.</p>
|
||||
</div>
|
||||
|
||||
<ul class="list-group">
|
||||
<t t-foreach="contacts" t-as="contact">
|
||||
<li class="list-group-item">
|
||||
<input type="checkbox" class="mail_list_checkbox" name="contact_ids"
|
||||
t-att-value="contact['id']" t-att-checked="'checked' if contact['opt_out'] == False else None"/>
|
||||
<t t-esc="contact.list_id.name"/>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
|
||||
<div class="text-center mb16">
|
||||
<input type="submit" id="send_form" class="btn btn-primary" value="Update my subscriptions"/>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-if="contacts == False">
|
||||
<div class="alert alert-info text-center">
|
||||
<p>You are not subscribed to any of our mailing list.</p>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="unsubscribed">
|
||||
<div class="container mt8">
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h1 class="page-header">Mailing Subscriptions</h1>
|
||||
|
||||
<div class="alert alert-success text-center">
|
||||
<p>Your changes have been saved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="page_unsubscribe" name="Unsubscribe">
|
||||
<t t-call="website.layout">
|
||||
<t t-call="website_mass_mailing.unsubscribe"/>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="page_unsubscribed" name="Unsubscribed">
|
||||
<t t-call="website.layout">
|
||||
<t t-call="website_mass_mailing.unsubscribed"/>
|
||||
</t>
|
||||
</template>
|
||||
</odoo>
|
||||
+4
-6
@@ -1,19 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<template id="assets_frontend" inherit_id="website.assets_frontend" name="Mail Frontend Assets">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/website_mass_mailing/static/src/js/website_mass_mailing.js"></script>
|
||||
<script type="text/javascript" src="/website_mass_mailing/static/src/js/website_mass_mailing.js"/>
|
||||
<link rel="stylesheet" href="/mass_mailing/static/src/css/mass_mailing_popup.css" type="text/css"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="assets_editor" inherit_id="website.assets_editor" name="wesbite_mass_mailing Editor assets">
|
||||
<xpath expr="/t" position="inside">
|
||||
<script type="text/javascript" src="/website_mass_mailing/static/src/js/website_mass_mailing.editor.js" groups="base.group_website_publisher"></script>
|
||||
<script type="text/javascript" src="/website_mass_mailing/static/src/js/website_mass_mailing.editor.js" groups="base.group_website_publisher"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user