Beispiel #1
0
def override_url_prefix(*, app_name=None, locale=None):
    from olympia.amo.urlresolvers import Prefixer

    old_prefixer = get_url_prefix()
    request = HttpRequest()
    request.META['SCRIPT_NAME'] = ''
    new_prefixer = Prefixer(request)
    new_prefixer.app = app_name or (old_prefixer or new_prefixer).app
    new_prefixer.locale = locale or (old_prefixer or new_prefixer).locale
    try:
        set_url_prefix(new_prefixer)
        yield
    finally:
        set_url_prefix(old_prefixer)
Beispiel #2
0
def activate_locale(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, )))
        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)
Beispiel #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,)))
         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)