From 1ec7ff2adbb1821c5318b4e0a18194f441d7a87e Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 14 Oct 2012 20:05:44 +0200 Subject: [PATCH] Fixed 404 page under werkzeug.routing - Removed ?lang= feature due to incompatibility with werkzeug routes in the current state of the architecture. --- mediagoblin/app.py | 35 ++++++++++++++++--------------- mediagoblin/auth/routing.py | 4 ++-- mediagoblin/tools/translate.py | 7 +------ mediagoblin/user_pages/routing.py | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 5758dbbb..8a19b3e0 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -15,7 +15,6 @@ # along with this program. If not, see . import os -import urllib import logging from mediagoblin.routing import url_map, view_functions, add_route @@ -138,7 +137,6 @@ class MediaGoblinApp(object): request.accept = request.accept_mimetypes ## Routing / controller loading stuff - path_info = request.path map_adapter = self.url_map.bind_to_environ(request.environ) # By using fcgi, mediagoblin can run under a base path @@ -167,21 +165,9 @@ class MediaGoblinApp(object): request.db = self.db request.staticdirect = self.staticdirector - mg_request.setup_user_in_request(request) - - try: - endpoint, url_values = map_adapter.match() - request.matchdict = url_values - - request.locale = translate.get_locale_from_request(request) - request.template_env = template.get_jinja_env( - self.template_loader, request.locale) - except NotFound as exc: - return NotImplemented - return render_404(request)(environ, start_response) - except HTTPException as exc: - # Support legacy webob.exc responses - return exc(environ, start_response) + request.locale = translate.get_locale_from_request(request) + request.template_env = template.get_jinja_env( + self.template_loader, request.locale) def build_proxy(endpoint, **kw): try: @@ -196,8 +182,23 @@ class MediaGoblinApp(object): request.urlgen = build_proxy + mg_request.setup_user_in_request(request) + + try: + endpoint, url_values = map_adapter.match() + request.matchdict = url_values + except NotFound as exc: + return render_404(request)(environ, start_response) + except HTTPException as exc: + # Support legacy webob.exc responses + return exc(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): diff --git a/mediagoblin/auth/routing.py b/mediagoblin/auth/routing.py index 58faa5a3..ee4b957a 100644 --- a/mediagoblin/auth/routing.py +++ b/mediagoblin/auth/routing.py @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from routes.route import add_route from mediagoblin.routing import add_route add_route('mediagoblin.auth.logout', @@ -36,9 +35,10 @@ add_route('mediagoblin.auth.verify_email', '/verify_email/', add_route('mediagoblin.auth.resend_verification', '/resend_verification/', 'mediagoblin.auth.views:resend_activation') +# XXX: Does this work? add_route('mediagoblin.auth.resend_verification_success', '/resend_verification_success/', - template='mediagoblin/auth/resent_verification_email.html', + # template='mediagoblin/auth/resent_verification_email.html', 'mediagoblin.views:simple_template_render') add_route('mediagoblin.auth.forgot_password', '/forgot_password/', diff --git a/mediagoblin/tools/translate.py b/mediagoblin/tools/translate.py index cdc827a0..01cabe6a 100644 --- a/mediagoblin/tools/translate.py +++ b/mediagoblin/tools/translate.py @@ -65,12 +65,7 @@ def get_locale_from_request(request): if request_form.has_key('lang'): return locale_to_lower_upper(request_form['lang']) - # Your routing can explicitly specify a target language - matchdict = request.matchdict or {} - - if 'locale' in matchdict: - target_lang = matchdict['locale'] - elif 'target_lang' in request.session: + if 'target_lang' in request.session: target_lang = request.session['target_lang'] # Pull the first acceptable language or English else: diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py index 678f18f9..35e1bd6e 100644 --- a/mediagoblin/user_pages/routing.py +++ b/mediagoblin/user_pages/routing.py @@ -74,7 +74,7 @@ add_route('mediagoblin.user_pages.processing_panel', # Stray edit routes add_route('mediagoblin.edit.edit_media', '/u//m//edit/', - 'mediagoblin.user_pages.views:edit_media') + 'mediagoblin.edit.views:edit_media') add_route('mediagoblin.edit.attachments', '/u//m//attachments/', -- 2.25.1