main.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import http
  4. from odoo.http import request
  5. class WebsiteUrl(http.Controller):
  6. @http.route('/website_links/new', type='json', auth='user', methods=['POST'])
  7. def create_shorten_url(self, **post):
  8. if 'url' not in post or post['url'] == '':
  9. return {'error': 'empty_url'}
  10. return request.env['link.tracker'].search_or_create(post).read()
  11. @http.route('/r', type='http', auth='user', website=True)
  12. def shorten_url(self, **post):
  13. return request.render("website_links.page_shorten_url", post)
  14. @http.route('/website_links/add_code', type='json', auth='user')
  15. def add_code(self, **post):
  16. link_id = request.env['link.tracker.code'].search([('code', '=', post['init_code'])], limit=1).link_id.id
  17. new_code = request.env['link.tracker.code'].search_count([('code', '=', post['new_code']), ('link_id', '=', link_id)])
  18. if new_code > 0:
  19. return new_code.read()
  20. else:
  21. return request.env['link.tracker.code'].create({'code': post['new_code'], 'link_id': link_id})[0].read()
  22. @http.route('/website_links/recent_links', type='json', auth='user')
  23. def recent_links(self, **post):
  24. return request.env['link.tracker'].recent_links(post['filter'], post['limit'])
  25. @http.route('/r/<string:code>+', type='http', auth="user", website=True)
  26. def statistics_shorten_url(self, code, **post):
  27. code = request.env['link.tracker.code'].search([('code', '=', code)], limit=1)
  28. if code:
  29. return request.render("website_links.graphs", code.link_id.read()[0])
  30. else:
  31. return request.redirect('/', code=301)