Skip to content

Instantly share code, notes, and snippets.

@jgmize
Created September 11, 2013 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgmize/6529655 to your computer and use it in GitHub Desktop.
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
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