X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=mediagoblin%2Frouting.py;h=defbc4ba80cf2cb8438cef8a8c43cdb62668cb67;hb=dc0b39b74741e7f4a7ba975c7ee98953bbf38816;hp=b854c85a5d3dcdf40393c095922011a257902f4d;hpb=2190ecde8d7ad77daf5e70c165bd36cc4d7e634d;p=mediagoblin.git diff --git a/mediagoblin/routing.py b/mediagoblin/routing.py index b854c85a..defbc4ba 100644 --- a/mediagoblin/routing.py +++ b/mediagoblin/routing.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 Free Software Foundation, Inc +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -14,24 +14,42 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from routes import Mapper +from werkzeug.routing import Map, Rule -from mediagoblin.auth.routing import auth_routes -from mediagoblin.submit.routing import submit_routes -from mediagoblin.user_pages.routing import user_routes -from mediagoblin.edit.routing import edit_routes +url_map = Map() + +view_functions = {} + +def add_route(endpoint, url, controller): + """ + Add a route to the url mapping + """ + # XXX: We cannot use this, since running tests means that the plugin + # routes will be populated over and over over the same session. + # + # assert endpoint not in view_functions.keys(), 'Trying to overwrite a rule' -def get_mapper(): - mapping = Mapper() - mapping.minimization = False + view_functions.update({endpoint: controller}) - mapping.connect( - "index", "/", - controller="mediagoblin.views:root_view") + url_map.add(Rule(url, endpoint=endpoint)) - mapping.extend(auth_routes, '/auth') - mapping.extend(submit_routes, '/submit') - mapping.extend(user_routes, '/u') - mapping.extend(edit_routes, '/edit') +def mount(mountpoint, routes): + """ + Mount a bunch of routes to this mountpoint + """ + for endpoint, url, controller in routes: + url = "%s/%s" % (mountpoint.rstrip('/'), url.lstrip('/')) + add_route(endpoint, url, controller) + +add_route('index', '/', 'mediagoblin.views:root_view') + +from mediagoblin.admin.routing import admin_routes +from mediagoblin.auth.routing import auth_routes +mount('/auth', auth_routes) +mount('/a', admin_routes) - return mapping +import mediagoblin.submit.routing +import mediagoblin.user_pages.routing +import mediagoblin.edit.routing +import mediagoblin.webfinger.routing +import mediagoblin.listings.routing