コード例 #1
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()
コード例 #2
0
ファイル: tests.py プロジェクト: AmirKremer/openmuni-budgets
    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(email=user.email, password='******')

                self.assertEqual(lang, user.language)