X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=mediagoblin%2Fapp.py;h=10fbf4a3e055bccfc6fce6a32f5dc636a646aee4;hb=45ab3e07ef26199572207f5d826e6d912eb5b336;hp=d1f4cab7cb5ede93f0a2aee4afe2664281ccf243;hpb=785b287fcb42ac9130b222006097e3f68cec3543;p=mediagoblin.git diff --git a/mediagoblin/app.py b/mediagoblin/app.py index d1f4cab7..10fbf4a3 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -17,10 +17,12 @@ import os import logging -from mediagoblin.routing import url_map, view_functions, add_route +from mediagoblin.routing import get_url_map +from mediagoblin.tools.routing import endpoint_to_controller from werkzeug.wrappers import Request from werkzeug.exceptions import HTTPException, NotFound +from werkzeug.routing import RequestRedirect from mediagoblin import meddleware, __version__ from mediagoblin.tools import common, translate, template @@ -77,7 +79,7 @@ class MediaGoblinApp(object): setup_plugins() # Set up the database - self.connection, self.db = setup_database() + self.db = setup_database() # Register themes self.theme_registry, self.current_theme = register_themes(app_config) @@ -93,10 +95,7 @@ class MediaGoblinApp(object): self.public_store, self.queue_store = setup_storage() # set up routing - self.url_map = url_map - - for route in PluginManager().get_routes(): - add_route(*route) + self.url_map = get_url_map() # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) @@ -186,26 +185,18 @@ class MediaGoblinApp(object): mg_request.setup_user_in_request(request) try: - endpoint, url_values = map_adapter.match() + found_rule, url_values = map_adapter.match(return_rule=True) request.matchdict = url_values + except RequestRedirect as response: + # Deal with 301 responses eg due to missing final slash + return response(environ, start_response) except HTTPException as exc: # Stop and render exception return render_http_exception( request, exc, exc.get_description(environ))(environ, start_response) - view_func = view_functions[endpoint] - - _log.debug('endpoint: {0} view_func: {1}'.format( - endpoint, - view_func)) - - # import the endpoint, or if it's already a callable, call that - if isinstance(view_func, unicode) \ - or isinstance(view_func, str): - controller = common.import_component(view_func) - else: - controller = view_func + controller = endpoint_to_controller(found_rule) # pass the request through our meddleware classes try: