Commits

Carl Meyer  committed 2925de9

Change the session key to 'django_language' to match Django's own locale support.

  • Participants
  • Parent commits 65da1f4

Comments (0)

Files changed (3)

File localeurl/middleware.py

     def process_request(self, request):
         locale, path = utils.strip_path(request.path_info)
         if localeurl_settings.USE_SESSION and not locale:
-            slocale = request.session.get('locale')
+            slocale = request.session.get('django_language')
             if slocale and utils.supported_language(slocale):
                 locale = slocale
         if localeurl_settings.USE_ACCEPT_LANGUAGE and not locale:
             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])
+            accept_langs = filter(
+                None,
+                [utils.supported_language(lang[0]) for lang in header_langs]
+                )
             if accept_langs:
                 locale = accept_langs[0]
         locale_path = utils.locale_path(path, locale)

File localeurl/tests/tests.py

         reload(localeurl_settings)
 
         r1 = self.request_factory.get('/test/')
-        r1.session = {'locale': 'fr'}
+        r1.session = {'django_language': 'fr'}
         r2 = self.middleware.process_request(r1)
         self.assertEqual(301, r2.status_code)
         self.assertEqual('/fr/test/', r2['Location'])
         self.settings_manager.set(LOCALEURL_USE_SESSION=True)
         reload(localeurl_settings)
         self.client.post('/change/', data={'locale': 'de', 'next': '/foo'})
-        self.assertEqual("de", self.client.session['locale'])
+        self.assertEqual("de", self.client.session['django_language'])
 
     def test_change_locale_check_session_disabled(self):
         self.settings_manager.set(LOCALEURL_USE_SESSION=False)
         reload(localeurl_settings)
         self.client.post('/change/', data={'locale': 'de', 'next': '/foo'})
-        self.assertNotEqual("de", self.client.session.get('locale'))
+        self.assertNotEqual("de", self.client.session.get('django_language'))

File localeurl/views.py

         locale = request.POST.get('locale', None)
         if locale and check_for_language(locale):
             if localeurl_settings.USE_SESSION:
-                request.session['locale'] = locale
+                request.session['django_language'] = locale
             path = utils.locale_path(path, locale)
 
     response = http.HttpResponseRedirect(path)