Created
September 11, 2013 20:54
-
-
Save jgmize/6529655 to your computer and use it in GitHub Desktop.
Proposal of how to deal with legacy PHP lang param usage conflict with funfactory.middleware.LocaleURLMiddleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from funfactory.middleware import LocaleURLMiddleware | |
from django.conf import settings | |
class ExceptionalLocaleURLMiddleware(LocalURLMiddleware): | |
""" | |
Replacement for funfactory.middleware.LocaleURLMiddleware that supports excluding | |
specific paths from getting redirected if a lang param is present in the request. | |
""" | |
def process_request(self, request): | |
if 'lang' in request.GET and request.path in getattr( | |
settings, 'LOCALE_URL_MIDDLEWARE_NO_LANG_REDIRECT_PATHS', []): | |
pass # if lang is in request.GET, the super call will always redirect regardless of the Accept-Lang header | |
else: | |
return super(ExceptionalLocaleURLMiddleware, self).process_request(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment