summaryrefslogtreecommitdiff
path: root/addons/website_links/controller
diff options
context:
space:
mode:
authorJulien De Coster <jdc@odoo.com>2014-08-12 14:54:26 +0530
committerJulien De Coster <jdc@odoo.com>2014-12-17 17:14:33 +0100
commitddac26cdbb3535239f5dbb41f5b464366065f3ba (patch)
treeb54e4d34060f1c7f80a8c6404f7f4fd56d914e52 /addons/website_links/controller
parent7f97bf4ec07329e58c818632bf23017b390bb099 (diff)
[ADD] Add the website_links module.
This module tracks clicks in mass mailing mails and allow the generation of trackable links in a website interface. Modules modifications --------------------- Refractoring of the crm_tracking_* classes in a new module. * Extract the crm_tracking_* from the crm module into a new module "utm" * Remove the crm_mass_mailing bridge module * New dependencies of mass_mailing and website_links to utm.
Diffstat (limited to 'addons/website_links/controller')
-rw-r--r--addons/website_links/controller/__init__.py2
-rw-r--r--addons/website_links/controller/main.py45
2 files changed, 47 insertions, 0 deletions
diff --git a/addons/website_links/controller/__init__.py b/addons/website_links/controller/__init__.py
new file mode 100644
index 00000000000..a84d81a791b
--- /dev/null
+++ b/addons/website_links/controller/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import main
diff --git a/addons/website_links/controller/main.py b/addons/website_links/controller/main.py
new file mode 100644
index 00000000000..46da968a5c4
--- /dev/null
+++ b/addons/website_links/controller/main.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+import werkzeug
+
+from openerp.addons.web import http
+from openerp.http import request
+
+
+class Website_Url(http.Controller):
+ @http.route('/website_links/new', type='json', auth='user', methods=['POST'])
+ def create_shorten_url(self, **post):
+ if 'url' not in post or post['url'] == '':
+ return {'error': 'empty_url'}
+ return request.env['website.links'].create(post).read()
+
+ @http.route('/r', type='http', auth='user', website=True)
+ def shorten_url(self, **post):
+ return request.website.render("website_links.page_shorten_url", post)
+
+ @http.route('/website_links/add_code', type='json', auth='user')
+ def add_code(self, **post):
+ link_id = request.env['website.links.code'].search([('code', '=', post['init_code'])], limit=1).link_id.id
+ new_code = request.env['website.links.code'].search_count([('code', '=', post['new_code']), ('link_id', '=', link_id)])
+ if new_code > 0:
+ return new_code.read()
+ else:
+ return request.env['website.links.code'].create({'code': post['new_code'], 'link_id': link_id})[0].read()
+
+ @http.route('/website_links/recent_links', type='json', auth='user')
+ def recent_links(self, **post):
+ return request.env['website.links'].recent_links(post['filter'], post['limit'])
+
+ @http.route('/r/<string:code>+', type='http', auth="user", website=True)
+ def statistics_shorten_url(self, code, **post):
+ code = request.env['website.links.code'].search([('code', '=', code)], limit=1)
+
+ if code:
+ return request.website.render("website_links.graphs", code.link_id.read()[0])
+ else:
+ return werkzeug.utils.redirect('', 301)
+
+ @http.route('/r/<string:code>', type='http', auth='none', website=True)
+ def full_url_redirect(self, code, **post):
+ request.env['website.links.click'].add_click(code, request.httprequest.remote_addr, request.session['geoip'].get('country_code'), stat_id=False)
+ redirect_url = request.env['website.links'].get_url_from_code(code)
+ return werkzeug.utils.redirect(redirect_url or '', 301)