Пример #1
0
    def process_request(self, request):
        request.APP = amo.FIREFOX

        path_ = request.get_full_path()
        new_path = None
        new_qs = {}

        lang, app, rest = Prefixer(request).split_path(path_)

        if app:
            # Strip /<app> from URL.
            new_path = rest

        if lang:
            # Strip /<lang> from URL.
            if not new_path:
                new_path = rest
            new_qs['lang'] = lang.lower()

        region, _, rest = path_.lstrip('/').partition('/')
        region = region.lower()

        if region in mkt.regions.REGIONS_DICT:
            # Strip /<region> from URL.
            if not new_path:
                new_path = rest
            new_qs['region'] = region

        if new_path is not None:
            if not new_path or new_path[0] != '/':
                new_path = '/' + new_path
            # TODO: Make this a 301 when we enable region stores in prod.
            return http.HttpResponseRedirect(urlparams(new_path, **new_qs))
Пример #2
0
 def activate(self, locale=None, app=None):
     """Active an app or a locale."""
     prefixer = old_prefix = get_url_prefix()
     old_app = old_prefix.app
     old_locale = translation.get_language()
     if locale:
         rf = test_utils.RequestFactory()
         prefixer = Prefixer(rf.get('/%s/' % (locale,)))
         translation.activate(locale)
     if app:
         prefixer.app = app
     set_url_prefix(prefixer)
     yield
     old_prefix.app = old_app
     set_url_prefix(old_prefix)
     translation.activate(old_locale)
Пример #3
0
 def activate(self, locale=None, app=None):
     """Active an app or a locale."""
     prefixer = old_prefix = get_url_prefix()
     old_app = old_prefix.app
     old_locale = translation.get_language()
     if locale:
         rf = RequestFactory()
         prefixer = Prefixer(rf.get('/%s/' % (locale,)))
         tower.activate(locale)
     if app:
         prefixer.app = app
     set_url_prefix(prefixer)
     yield
     old_prefix.app = old_app
     set_url_prefix(old_prefix)
     tower.activate(old_locale)
Пример #4
0
    def process_request(self, request):
        a_l = get_accept_language(request)
        lang, ov_lang = a_l, ''
        stored_lang, stored_ov_lang = '', ''

        remembered = request.COOKIES.get('lang')
        if remembered:
            chunks = remembered.split(',')[:2]

            stored_lang = chunks[0]
            try:
                stored_ov_lang = chunks[1]
            except IndexError:
                pass

            if stored_lang.lower() in settings.LANGUAGE_URL_MAP:
                lang = stored_lang
            if stored_ov_lang.lower() in settings.LANGUAGE_URL_MAP:
                ov_lang = stored_ov_lang

        if 'lang' in request.REQUEST:
            # `get_language` uses request.GET['lang'] and does safety checks.
            ov_lang = a_l
            lang = Prefixer(request).get_language()
        elif a_l != ov_lang:
            # Change if Accept-Language differs from Overridden Language.
            lang = a_l
            ov_lang = ''

        # Update cookie if values have changed.
        if lang != stored_lang or ov_lang != stored_ov_lang:
            request.LANG_COOKIE = ','.join([lang, ov_lang])

        request.LANG = lang
        tower.activate(lang)
Пример #5
0
 def activate(self, locale):
     old_prefix = get_url_prefix()
     old_locale = translation.get_language()
     rf = test_utils.RequestFactory()
     set_url_prefix(Prefixer(rf.get('/%s/' % (locale, ))))
     translation.activate(locale)
     yield
     set_url_prefix(old_prefix)
     translation.activate(old_locale)
Пример #6
0
    def process_request(self, request):
        request.API = False
        request.APP = amo.FIREFOX

        path_ = request.get_full_path()
        new_path = None
        new_qs = {}

        lang, app, rest = Prefixer(request).split_path(path_)

        if app:
            # Strip /<app> from URL.
            new_path = rest

        if lang:
            # Strip /<lang> from URL.
            if not new_path:
                new_path = rest
            new_qs['lang'] = lang.lower()

        region, _, rest = path_.lstrip('/').partition('/')
        region = region.lower()

        if region == 'api':
            # API isn't a region, its a sign that you are using the api.
            request.API = True

        if region in mkt.regions.REGION_LOOKUP:
            # Strip /<region> from URL.
            if not new_path:
                new_path = rest
            new_qs['region'] = mkt.regions.REGION_LOOKUP[region].slug

        if new_path is not None:
            if not new_path or new_path[0] != '/':
                new_path = '/' + new_path
            # TODO: Make this a 301 when we enable region stores in prod.
            return http.HttpResponseRedirect(urlparams(new_path, **new_qs))
Пример #7
0
    def process_request(self, request):
        request.API = False
        request.APP = amo.FIREFOX

        path_ = request.get_full_path()
        new_path = None
        new_qs = {}

        lang, app, rest = Prefixer(request).split_path(path_)

        if app:
            # Strip /<app> from URL.
            new_path = rest

        if lang:
            # Strip /<lang> from URL.
            if not new_path:
                new_path = rest
            new_qs['lang'] = lang.lower()

        region, _, rest = path_.lstrip('/').partition('/')
        region = region.lower()

        if region == 'api':
            # API isn't a region, its a sign that you are using the api.
            request.API = True

        if region in mkt.regions.REGION_LOOKUP:
            # Strip /<region> from URL.
            if not new_path:
                new_path = rest
            new_qs['region'] = mkt.regions.REGION_LOOKUP[region].slug

        if new_path is not None:
            if not new_path or new_path[0] != '/':
                new_path = '/' + new_path
            # TODO: Make this a 301 when we enable region stores in prod.
            return http.HttpResponseRedirect(urlparams(new_path, **new_qs))