diff options
author | Jessica Tallon <jessica@megworld.co.uk> | 2014-12-12 13:55:14 +0000 |
---|---|---|
committer | Jessica Tallon <jessica@megworld.co.uk> | 2014-12-12 14:33:15 +0000 |
commit | c7c26b17406cdcb03de4d2579f4851d2513d11e1 (patch) | |
tree | 90aa7b01db97b7354ed2e032418fdb685b76caab /mediagoblin/tools/routing.py | |
parent | 058964bce7a7ececf500dfe17d39a497c4fb7148 (diff) | |
download | mediagoblin-c7c26b17406cdcb03de4d2579f4851d2513d11e1.tar.lz mediagoblin-c7c26b17406cdcb03de4d2579f4851d2513d11e1.tar.xz mediagoblin-c7c26b17406cdcb03de4d2579f4851d2513d11e1.zip |
Fix #1056 - Add flag to accept URLs without a trailing slash
Diffstat (limited to 'mediagoblin/tools/routing.py')
-rw-r--r-- | mediagoblin/tools/routing.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/mediagoblin/tools/routing.py b/mediagoblin/tools/routing.py index 2ff003b7..ae7c7154 100644 --- a/mediagoblin/tools/routing.py +++ b/mediagoblin/tools/routing.py @@ -28,15 +28,22 @@ url_map = Map() class MGRoute(Rule): - def __init__(self, endpoint, url, controller): + def __init__(self, endpoint, url, controller, match_slash=True): Rule.__init__(self, url, endpoint=endpoint) self.gmg_controller = controller + self.match_slash = match_slash def empty(self): new_rule = Rule.empty(self) new_rule.gmg_controller = self.gmg_controller return new_rule + def match(self, path, *args, **kwargs): + if not (self.match_slash or path.endswith("/")): + path = path + "/" + + return super(MGRoute, self).match(path, *args, **kwargs) + def endpoint_to_controller(rule): endpoint = rule.endpoint @@ -52,11 +59,11 @@ def endpoint_to_controller(rule): return view_func -def add_route(endpoint, url, controller): +def add_route(endpoint, url, controller, *args, **kwargs): """ Add a route to the url mapping """ - url_map.add(MGRoute(endpoint, url, controller)) + url_map.add(MGRoute(endpoint, url, controller, *args, **kwargs)) def mount(mountpoint, routes): |