Alex Marandon avatar Alex Marandon committed ad27684

Check session locale in middleware

Comments (0)

Files changed (1)


     def process_request(self, request):
         locale, path = utils.strip_path(request.path_info)
-        if localeurl_settings.USE_ACCEPT_LANGUAGE and not locale:
-            accept_langs = filter(lambda x: x, [utils.supported_language(lang[0])
-                                                for lang in
-                                                parse_accept_lang_header(
-                        request.META.get('HTTP_ACCEPT_LANGUAGE', ''))])
-            if accept_langs:
-                locale = accept_langs[0]
+        if not locale:
+            if localeurl_settings.USE_SESSION:
+                slocale = request.session.get('locale')
+                if slocale and utils.supported_language(slocale):
+                    locale = slocale
+            elif localeurl_settings.USE_ACCEPT_LANGUAGE:
+                accept_lang_header = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
+                header_langs = parse_accept_lang_header(accept_lang_header)
+                accept_langs = filter(lambda x: x, 
+                                            [utils.supported_language(lang[0])
+                                            for lang in header_langs])
+                if accept_langs:
+                    locale = accept_langs[0]
         locale_path = utils.locale_path(path, locale)
         if locale_path != request.path_info:
             locale_url = utils.add_script_prefix(locale_path)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.