コード例 #1
0
ファイル: test__utils.py プロジェクト: 15776950506/affiliates
 def test_not_in_whitelist(self):
     """
     If the given locale is not in the whitelist, default back to en-us.
     """
     request = self.factory.get('/')
     activate_locale(request, 'de')
     eq_(request.locale, 'en-us')
コード例 #2
0
 def test_not_in_whitelist(self):
     """
     If the given locale is not in the whitelist, default back to en-us.
     """
     request = self.factory.get('/')
     activate_locale(request, 'de')
     eq_(request.locale, 'en-us')
コード例 #3
0
 def test_dev_dont_limit_locales(self):
     """
     If settings.DEV is True, do not verify that a locale is in the
     FACEBOOK_LOCALES list.
     """
     request = self.factory.get('/')
     activate_locale(request, 'es')
     eq_(request.locale, 'es')
コード例 #4
0
ファイル: test__utils.py プロジェクト: 15776950506/affiliates
 def test_dev_dont_limit_locales(self):
     """
     If settings.DEV is True, do not verify that a locale is in the
     FACEBOOK_LOCALES list.
     """
     request = self.factory.get('/')
     activate_locale(request, 'es')
     eq_(request.locale, 'es')
コード例 #5
0
    def _app_context(self, in_facebook_app, path='/', user=None, in_app=True,
                     locale='en-US'):
        in_facebook_app.return_value = in_app
        request = self.factory.get(path)
        request.user = user
        activate_locale(request, locale)
        if request.user is None:
            request.user = AnonymousFacebookUser()

        return app_context(request)
コード例 #6
0
    def _app_context(self,
                     in_facebook_app,
                     path='/',
                     user=None,
                     in_app=True,
                     locale='en-US'):
        in_facebook_app.return_value = in_app
        request = self.factory.get(path)
        request.user = user
        activate_locale(request, locale)
        if request.user is None:
            request.user = AnonymousFacebookUser()

        return app_context(request)
コード例 #7
0
ファイル: middleware.py プロジェクト: tyler46/affiliates
    def process_request(self, request):
        # Exit early if we are not in the Facebook app section of the site to
        # avoid clashing with the Django auth middleware.
        if not in_facebook_app(request):
            return None

        # Default to an anonymous user.
        request.user = AnonymousFacebookUser()
        locale = None
        try:
            user = FacebookUser.objects.get(id=request.session[SESSION_KEY])
            request.user = user
            locale = user.locale
        except (FacebookUser.DoesNotExist, KeyError):
            pass

        if locale is None:
            # Since we can't get their locale from their user data, we'll use
            # funfactory's prefixer instead.
            prefixer = Prefixer(request)
            locale = prefixer.get_language()

        activate_locale(request, locale)
コード例 #8
0
ファイル: middleware.py プロジェクト: 15776950506/affiliates
    def process_request(self, request):
        # Exit early if we are not in the Facebook app section of the site to
        # avoid clashing with the Django auth middleware.
        if not in_facebook_app(request):
            return None

        # Default to an anonymous user.
        request.user = AnonymousFacebookUser()
        locale = None
        try:
            user = FacebookUser.objects.get(id=request.session[SESSION_KEY])
            request.user = user
            locale = user.locale
        except (FacebookUser.DoesNotExist, KeyError):
            pass

        if locale is None:
            # Since we can't get their locale from their user data, we'll use
            # funfactory's prefixer instead.
            prefixer = Prefixer(request)
            locale = prefixer.get_language()

        activate_locale(request, locale)
コード例 #9
0
 def test_language_code_in_whitelist(self):
     """If only a locale's language code is in the whitelist, use it."""
     request = self.factory.get('/')
     activate_locale(request, 'de-de')
     eq_(get_language(), 'de')
     eq_(request.locale, 'de')
コード例 #10
0
 def test_locale_in_whitelist(self):
     """If a locale is in the whitelist, use it."""
     request = self.factory.get('/')
     activate_locale(request, 'en-us')
     eq_(request.locale, 'en-us')
コード例 #11
0
ファイル: test__utils.py プロジェクト: 15776950506/affiliates
 def test_language_code_in_whitelist(self):
     """If only a locale's language code is in the whitelist, use it."""
     request = self.factory.get('/')
     activate_locale(request, 'de-de')
     eq_(get_language(), 'de')
     eq_(request.locale, 'de')
コード例 #12
0
ファイル: test__utils.py プロジェクト: 15776950506/affiliates
 def test_locale_in_whitelist(self):
     """If a locale is in the whitelist, use it."""
     request = self.factory.get('/')
     activate_locale(request, 'en-us')
     eq_(request.locale, 'en-us')