diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_links/controller | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_links/controller')
| -rw-r--r-- | addons/website_links/controller/__init__.py | 2 | ||||
| -rw-r--r-- | addons/website_links/controller/main.py | 41 |
2 files changed, 43 insertions, 0 deletions
diff --git a/addons/website_links/controller/__init__.py b/addons/website_links/controller/__init__.py new file mode 100644 index 00000000..757b12a1 --- /dev/null +++ b/addons/website_links/controller/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import main diff --git a/addons/website_links/controller/main.py b/addons/website_links/controller/main.py new file mode 100644 index 00000000..b90c63a1 --- /dev/null +++ b/addons/website_links/controller/main.py @@ -0,0 +1,41 @@ +# -*- 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'].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) |
