diff options
Diffstat (limited to 'mediagoblin/tools')
-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): |