Files
tryton/modules/web_shortener/routes.py
T

21 lines
642 B
Python
Raw Normal View History

2019-03-30 17:35:04 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2022-12-31 00:05:40 +01:00
from trytond.protocols.wrappers import (
HTTPStatus, abort, redirect, with_pool, with_transaction)
2019-03-30 17:35:04 +01:00
from trytond.wsgi import app
@app.route('/s/<base64:database_name>$<shortened>')
@with_pool
@with_transaction(readonly=False)
def shortened(request, pool, shortened):
ShortenedURL = pool.get('web.shortened_url')
try:
shortened_url = ShortenedURL.get(shortened)
except IndexError:
abort(HTTPStatus.NOT_FOUND)
return redirect(shortened_url.access(), code=301)