This branch adds request.redirect on all requests. In case of a front end request, we do an url_for to the location. We removed redirect_with_hash that was only for retro compatibility local_redirect has been renamed to redirect_query, and param keep_hash has been removed and moved. Default code for redirect is 303 now instead of 302. Now redirect and redirect_query make local redirect by default, you need to pass local=False to make external redirect. All werkeug.utils.redirect has been replaced by request.redirect. Http.redirect now use an http.Response type, and it become easy to add an override like 'set_cookies' e.g. Dispatch of a website.page return an http.response too, so we first need to check if it is a cached version before to check if it is an Odoo Response. Migrate your code: http.redirect -> request.redirect(location, code, local) http.local_redirect -> request.redirect_query(location, query, code, local) http.redirect_with_hash -> request.redirect Courtesy of odony for help and review ;) closes odoo/odoo#72599 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
40 lines
1.7 KiB
Python
40 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
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 request.redirect('/', code=301)
|