main.py 866 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from werkzeug.exceptions import NotFound
  4. from odoo import http
  5. from odoo.http import request
  6. class LinkTracker(http.Controller):
  7. @http.route('/r/<string:code>', type='http', auth='public', website=True)
  8. def full_url_redirect(self, code, **post):
  9. if not request.env['ir.http'].is_a_bot():
  10. country_code = request.geoip.get('country_code')
  11. request.env['link.tracker.click'].sudo().add_click(
  12. code,
  13. ip=request.httprequest.remote_addr,
  14. country_code=country_code,
  15. )
  16. redirect_url = request.env['link.tracker'].get_url_from_code(code)
  17. if not redirect_url:
  18. raise NotFound()
  19. return request.redirect(redirect_url, code=301, local=False)