1 from django.utils import translation
2 from django.conf import settings
3 from django.http import Http404
4 from . import app_settings
7 class SetRemoteAddrFromXRealIP(object):
8 """Sets REMOTE_ADDR from the X-Real-IP header, as set by Nginx."""
9 def process_request(self, request):
10 if app_settings.REALIP:
12 request.META['REMOTE_ADDR'] = request.META['HTTP_X_REAL_IP']
18 class URLLocaleMiddleware(object):
19 """Decides which translation to use, based on path only."""
21 def process_request(self, request):
22 language = translation.get_language_from_path(request.path_info)
24 translation.activate(language)
25 request.LANGUAGE_CODE = translation.get_language()
26 if language == settings.LANGUAGE_CODE:
29 def process_response(self, request, response):
30 language = translation.get_language()
31 translation.deactivate()
32 if 'Content-Language' not in response:
33 response['Content-Language'] = language