예제 #1
0
    def test_get_language_key(self):
        """Checks that the correct language is set in the request context.


        The test covers cases where the user is both anonymous and authenticated.
        """
        for site in self.sites:
            this_subdomain = random.choice(list(self.subdomains))
            response = self.client.get("/")
            user = response.context['user']
            domain = site.domain

            if this_subdomain not in self.languages[0]:
                host = site.domain
                this_subdomain_lang = self.language_code

            else:
                host = this_subdomain + '.' + site.domain
                this_subdomain_lang = this_subdomain

            lang = get_language_key(host, domain, user)

            self.assertEqual(lang, this_subdomain_lang)

            for user in self.users:
                self.client.login(
                    username=user.username,
                    password='******'
                )

                self.assertEqual(
                    lang,
                    user.language
                )
예제 #2
0
 def process_request(self, request):
     domain = get_domain()
     host = request.get_host()
     user = request.user
     lang = get_language_key(host, domain, user)
     translation.activate(lang)
     request.LANGUAGE_CODE = translation.get_language()