Purpose ======= Add a unicity constraint (on the url, UTM campaign, medium and source). As we must care about null values, we can not implement it in SQL (possible in pure SQL, but we will need to create an index on the columns, which is not possible in Odoo if we want to customize the error message). Clean the code, before the "search or create" behavior was implemented in the create, causing strange behavior (creating a link tracker with the same values as an existing one didn't raise an error, but open the form view of the existing link tracker). Task-2090344 closes odoo/odoo#48845 Related: odoo/enterprise#9608 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import werkzeug
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class WebsiteUrl(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['link.tracker'].search_or_create(post).read()
|
|
|
|
@http.route('/r', type='http', auth='user', website=True)
|
|
def shorten_url(self, **post):
|
|
return request.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['link.tracker.code'].search([('code', '=', post['init_code'])], limit=1).link_id.id
|
|
new_code = request.env['link.tracker.code'].search_count([('code', '=', post['new_code']), ('link_id', '=', link_id)])
|
|
if new_code > 0:
|
|
return new_code.read()
|
|
else:
|
|
return request.env['link.tracker.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['link.tracker'].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['link.tracker.code'].search([('code', '=', code)], limit=1)
|
|
|
|
if code:
|
|
return request.render("website_links.graphs", code.link_id.read()[0])
|
|
else:
|
|
return werkzeug.utils.redirect('/', 301)
|