Odoo has way of route definition via decorators. That's almost fine, but.. we want to write module, that will allow us to do dynamic rewrites.
https://www.odoo.com/documentation/8.0/reference/http.html - here we can find standard way of adding route.
Looks like:
class MyController(openerp.http.Controller):
@route('/some_url', auth='public')
def handler(self):
return stuff()
Ideally we want to find where odoo stores RouteMap
for werkzeug
.
I've tried also to add decorated method to controller in way like:
def my_redirect(new_url):
t = lambda x: werkzeug.utils.redirect(new_url, 301)
return t
MyController.test = http.route('/old_url/')(my_redirect('/new_url/'))
But in this case we get error here.
The reference documentation for Odoo 9 routes is here, just in case.
Odoo computes and stores the web routes in the routing_map
(computed here in 8.0, and there in 9.0).
The map is lazily computed and exposed to extension modules in the ir.http
model, through the routing_map()
method, (8.0, 9.0). The ir.http._find_handler()
method is called by ir.http._dispatch()
during request handling to locate the matching route in the routing_map
.
You could override/extend any of these to implement your own dynamic routes, similarly to how the web
module does it.
Fallback routing: An interesting alternative for dynamically handling requests that do not match existing "static" rules is the _handle_exception()
method of ir.http
. It is called whenever an exception occurs during the request handling phase, including when no matching route is found. Anything it returns will be used as the response.
The web
module extends it to:
ir.attachment
) tables.