当前位置: 首页>>代码示例>>Python>>正文


Python tower.activate函数代码示例

本文整理汇总了Python中tower.activate函数的典型用法代码示例。如果您正苦于以下问题:Python activate函数的具体用法?Python activate怎么用?Python activate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了activate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _pre_setup

    def _pre_setup(self):
        # Add the models to the db.
        self._original_installed_apps = list(settings.INSTALLED_APPS)
        for app in self.apps:
            settings.INSTALLED_APPS.append(app)
        loading.cache.loaded = False
        call_command('syncdb', interactive=False, verbosity=0)
        call_command('update_badges', verbosity=0)
        badger.autodiscover()

        if get_url_prefix:
            # If we're in funfactoryland, make sure a locale prefix is 
            # set for urlresolvers
            locale = 'en-US'
            self.old_prefix = get_url_prefix()
            self.old_locale = get_language()
            rf = RequestFactory()
            set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))
            activate(locale)

        # Create a default user for tests
        self.user_1 = self._get_user(username="user_1",
                                     email="[email protected]",
                                     password="user_1_pass")

        # Call the original method that does the fixtures etc.
        super(test.TestCase, self)._pre_setup()
开发者ID:ashanan,项目名称:django-badger,代码行数:27,代码来源:__init__.py

示例2: _switch_locale

 def _switch_locale(self):
     if self.source_locale:
         lang = self.source_locale
     else:
         lang = self.addon.default_locale
     tower.activate(lang)
     return Locale(translation.to_locale(lang))
开发者ID:atsay,项目名称:zamboni,代码行数:7,代码来源:models.py

示例3: process_request

    def process_request(self, request):
        prefixer = Prefixer(request)
        set_url_prefixer(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        if "lang" in request.GET:
            # Blank out the locale so that we can set a new one. Remove lang
            # from the query params so we don't have an infinite loop.
            prefixer.locale = ""
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), v) for k, v in request.GET.iteritems() if k != "lang")
            return HttpResponseRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get("QUERY_STRING", "")
            full_path = urllib.quote(full_path.encode("utf-8"))

            if query_string:
                full_path = "%s?%s" % (full_path, query_string)

            response = HttpResponseRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = split_path(full_path)
            if old_locale != new_locale:
                response["Vary"] = "Accept-Language"

            return response

        request.path_info = "/" + prefixer.shortened_path
        request.LANGUAGE_CODE = prefixer.locale
        tower.activate(prefixer.locale)
开发者ID:jasdeepdhillon13,项目名称:kitsune,代码行数:33,代码来源:middleware.py

示例4: process_request

    def process_request(self, request):
        # Find locale, app
        prefixer = urlresolvers.Prefixer(request)
        urlresolvers.set_url_prefix(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        if "lang" in request.GET:
            # Blank out the locale so that we can set a new one.  Remove lang
            # from query params so we don't have an infinite loop.
            prefixer.locale = ""
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), request.GET[k]) for k in request.GET)
            query.pop("lang")
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get("QUERY_STRING", "")
            full_path = urllib.quote(full_path.encode("utf-8"))

            if query_string:
                full_path = "%s?%s" % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale.
            old_locale = prefixer.locale
            new_locale, _, _ = prefixer.split_path(full_path)
            if old_locale != new_locale:
                response["Vary"] = "Accept-Language"
            return response

        request.path_info = "/" + prefixer.shortened_path
        tower.activate(prefixer.locale)
        request.APP = amo.APPS.get(prefixer.app)
        request.LANG = prefixer.locale
开发者ID:sgarrity,项目名称:zamboni,代码行数:35,代码来源:middleware.py

示例5: process_request

    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)
开发者ID:chenzihui,项目名称:zamboni,代码行数:35,代码来源:middleware.py

示例6: test_activation_locale_detect

    def test_activation_locale_detect(self):
        p = self._profile()

        # Activate french and check if the locale was set correctly
        tower.activate('fr')
        u = RegisterProfile.objects.activate_profile(p.activation_key)
        eq_(u.get_profile().locale, 'fr')
开发者ID:stephendonner,项目名称:affiliates,代码行数:7,代码来源:test_models.py

示例7: process_request

    def process_request(self, request):
        prefixer = Prefixer(request)
        set_url_prefixer(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        if 'lang' in request.GET:
            # Blank out the locale so that we can set a new one. Remove lang
            # from the query params so we don't have an infinite loop.
            prefixer.locale = ''
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), v) for
                         k, v in request.GET.iteritems() if k != 'lang')
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '%s?%s' % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        tower.activate(prefixer.locale)
开发者ID:FrankBian,项目名称:kuma,代码行数:34,代码来源:middleware.py

示例8: send_group_email

def send_group_email(announcement_id):
    """Build and send the announcement emails to a group."""
    try:
        announcement = Announcement.objects.get(pk=announcement_id)
    except Announcement.DoesNotExist:
        return
    connection = get_connection(fail_silently=True)
    connection.open()
    group = announcement.group
    users = User.objects.filter(groups__in=[group])
    plain_content = bleach.clean(announcement.content_parsed,
                                 tags=[], strip=True).strip()
    email_kwargs = {'content': plain_content,
                    'domain': Site.objects.get_current().domain}
    template = 'announcements/email/announcement.ltxt'
    try:
        for u in users:
            # Localize email each time.
            activate(u.profile.locale or settings.LANGUAGE_CODE)
            subject = _('New announcement for {group}').format(
                group=group.name)
            message = loader.render_to_string(template, email_kwargs)
            m = EmailMessage(subject, message,
                             settings.NOTIFICATIONS_FROM_ADDRESS,
                             [u.email])
            connection.send_messages([m])
    finally:
        activate(settings.LANGUAGE_CODE)
        connection.close()
开发者ID:Akamad007,项目名称:kitsune,代码行数:29,代码来源:tasks.py

示例9: process_request

    def process_request(self, request):
        prefixer = urlresolvers.Prefixer(request)
        urlresolvers.set_url_prefix(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        if self._is_lang_change(request):
            # Blank out the locale so that we can set a new one. Remove lang
            # from the query params so we don't have an infinite loop.
            prefixer.locale = ''
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), request.GET[k]) for k in request.GET)
            query.pop('lang')
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '?'.join(
                    [full_path, force_text(query_string, errors='ignore')])

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = urlresolvers.split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        tower.activate(prefixer.locale)
开发者ID:JosephBywater,项目名称:bedrock,代码行数:35,代码来源:middleware.py

示例10: test_unknown

 def test_unknown(self):
     """
     Test that when the current locale is not supported by Babel, it
     defaults to en-US.
     """
     activate('fy')
     eq_(Locale('en', 'US'), current_locale())
开发者ID:15776950506,项目名称:affiliates,代码行数:7,代码来源:test__utils.py

示例11: ugettext_locale

def ugettext_locale(message, locale):
    """Translate a message in a specific locale."""
    old_locale = get_language()
    tower.activate(locale)
    text = tower.ugettext(message)
    tower.activate(old_locale)

    return text
开发者ID:LucianU,项目名称:affiliates,代码行数:8,代码来源:utils.py

示例12: test_babel_number

    def test_babel_number(self):
        number = 1000000
        activate('en-US')
        eq_(babel_number(number), u'1,000,000')

        activate('fr')
        # \xa0 is a non-breaking space
        eq_(babel_number(number), u'1\xa0000\xa0000')
开发者ID:15776950506,项目名称:affiliates,代码行数:8,代码来源:test_helpers.py

示例13: test_no_activate

 def test_no_activate(self, mock_activate):
     """If lang is Falsy, do not call activate."""
     activate('fr')
     eq_(get_language(), 'fr')
     with use_lang(None):
         eq_(get_language(), 'fr')
     eq_(get_language(), 'fr')
     ok_(not mock_activate.called)
开发者ID:Acidburn0zzz,项目名称:firefox-flicks,代码行数:8,代码来源:test_util.py

示例14: test_no_install_jinja_translations

def test_no_install_jinja_translations():
    """
    Setting `TOWER_INSTALL_JINJA_TRANSLATIONS` to False should skip setting
    the gettext and ngettext functions in the Jinja2 environment.
    """
    jingo.env.install_null_translations()
    tower.activate('xx')
    ok_(jingo.env.globals['gettext'] != _)
开发者ID:thijstriemstra,项目名称:tower,代码行数:8,代码来源:test_l10n.py

示例15: test_basic

 def test_basic(self):
     """
     Test that translating a string works and doesn't change the current
     locale.
     """
     activate('fr')
     eq_(_locale('message', 'xxx'), 'translated')
     eq_(get_language(), 'fr')
开发者ID:LucianU,项目名称:affiliates,代码行数:8,代码来源:test__utils.py


注:本文中的tower.activate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。