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


Python translation.deactivate方法代码示例

本文整理汇总了Python中django.utils.translation.deactivate方法的典型用法代码示例。如果您正苦于以下问题:Python translation.deactivate方法的具体用法?Python translation.deactivate怎么用?Python translation.deactivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.translation的用法示例。


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

示例1: forward_to_backends

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def forward_to_backends(self, method, *args, **kwargs):
        # forwards the desired backend method to all the language backends
        initial_language = translation.get_language()
        # retrieve unique backend name
        backends = []
        for language, _ in settings.LANGUAGES:
            using = '%s-%s' % (self.connection_alias, language)
            # Ensure each backend is called only once
            if using in backends:
                continue
            else:
                backends.append(using)
            translation.activate(language)
            backend = connections[using].get_backend()
            getattr(backend.parent_class, method)(backend, *args, **kwargs)

        if initial_language is not None:
            translation.activate(initial_language)
        else:
            translation.deactivate() 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:22,代码来源:backends.py

示例2: process_response

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def process_response(self, request, response):
        language = translation.get_language()
        if (response.status_code == 404 and
                not translation.get_language_from_path(request.path_info)
                    and self.is_language_prefix_patterns_used()):
            urlconf = getattr(request, 'urlconf', None)
            language_path = '/%s%s' % (language, request.path_info)
            path_valid = is_valid_path(language_path, urlconf)
            if (not path_valid and settings.APPEND_SLASH
                    and not language_path.endswith('/')):
                path_valid = is_valid_path("%s/" % language_path, urlconf)

            if path_valid:
                language_url = "%s://%s/%s%s" % (
                    request.is_secure() and 'https' or 'http',
                    request.get_host(), language, request.get_full_path())
                return HttpResponseRedirect(language_url)
        translation.deactivate()

        patch_vary_headers(response, ('Accept-Language',))
        if 'Content-Language' not in response:
            response['Content-Language'] = language
        return response 
开发者ID:blackye,项目名称:luscan-devel,代码行数:25,代码来源:locale.py

示例3: test_export_inventory_should_be_ok_in_arabic

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def test_export_inventory_should_be_ok_in_arabic(staffapp, settings):
    translation.activate('ar')
    inventory = InventoryFactory()
    specimen = SpecimenFactory(item__name="an item", comments=u"النبي (كتاب)")
    InventorySpecimen.objects.create(inventory=inventory, specimen=specimen)
    url = reverse('monitoring:inventory_export', kwargs={'pk': inventory.pk})
    resp = staffapp.get(url, status=200)
    resp.mustcontain(specimen.comments)
    translation.deactivate() 
开发者ID:ideascube,项目名称:ideascube,代码行数:11,代码来源:test_views.py

示例4: test_export_loan_should_be_ok_in_arabic

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def test_export_loan_should_be_ok_in_arabic(staffapp):
    translation.activate('ar')
    specimen = SpecimenFactory(item__name="an item", barcode="123")
    loan = LoanFactory(specimen=specimen, comments=u"النبي (كتاب)")
    url = reverse('monitoring:export_loan')
    resp = staffapp.get(url, status=200)
    assert resp.content.decode().startswith("item,barcode,serial,user,loaned at,due date,returned at,comments\r\nan item,123")  # noqa
    resp.mustcontain(loan.comments)
    translation.deactivate() 
开发者ID:ideascube,项目名称:ideascube,代码行数:11,代码来源:test_views.py

示例5: test_published_at_is_YMD_formatted_even_in_other_locale

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def test_published_at_is_YMD_formatted_even_in_other_locale(staffapp,
                                                            published):
    published.published_at = datetime(2015, 1, 7, tzinfo=timezone.utc)
    published.save()
    translation.activate('fr')
    url = reverse('blog:content_update', kwargs={'pk': published.pk})
    form = staffapp.get(url).forms['model_form']
    assert form['published_at'].value == '2015-01-07'
    translation.deactivate() 
开发者ID:ideascube,项目名称:ideascube,代码行数:11,代码来源:test_views.py

示例6: test_published_at_can_be_still_set_the_French_way

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def test_published_at_can_be_still_set_the_French_way(staffapp, published):
    # We force the input at load time, but we should still accept other format
    # at save.
    translation.activate('fr')
    url = reverse('blog:content_update', kwargs={'pk': published.pk})
    form = staffapp.get(url).forms['model_form']
    form['published_at'] = '11/01/2015'
    form.submit().follow()
    assert Content.objects.count()
    assert Content.objects.first().published_at.date() == date(2015, 1, 11)
    translation.deactivate() 
开发者ID:ideascube,项目名称:ideascube,代码行数:13,代码来源:test_views.py

示例7: test_create_content_with_default_language

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def test_create_content_with_default_language(staffapp):
    translation.activate('fr')

    url = reverse('blog:content_create')
    form = staffapp.get(url).forms['model_form']
    form['title'] = 'my content title'
    form['text'] = 'my content text'
    assert form['lang'].value == 'fr'
    form.submit().follow()

    content = Content.objects.last()
    assert content.lang == 'fr'

    translation.deactivate() 
开发者ID:ideascube,项目名称:ideascube,代码行数:16,代码来源:test_views.py

示例8: test_export_users_should_be_ok_in_arabic

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def test_export_users_should_be_ok_in_arabic(staffapp, settings):
    translation.activate('ar')
    user1 = UserFactory(serial="جبران خليل جبران")
    user2 = UserFactory(serial="النبي (كتاب)")
    resp = staffapp.get(reverse('user_export'), status=200)
    resp.mustcontain('serial')
    resp.mustcontain(user1.serial)
    resp.mustcontain(user2.serial)
    translation.deactivate() 
开发者ID:ideascube,项目名称:ideascube,代码行数:11,代码来源:test_views.py

示例9: get_message

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def get_message(user, user_type, issue, events, from_email, domain):
    user_profile = user.profile

    if not user_profile.send_my_own_events:
        events = events.exclude(author_id=user.id)

    if not events:
        return ()

    lang = user_profile.language
    translation.activate(lang)
    timezone.activate(user_profile.time_zone)

    subject = (_(u'kurs') + u': {0} | ' + _(u'zadacha') + u': {1} | ' + _(u'student') + u': {2} {3}'). \
        format(issue.task.course.name, issue.task.get_title(lang), issue.student.last_name, issue.student.first_name)

    context = {
        "user": user,
        "domain": domain,
        "title": subject,
        "user_type": user_type,
        "issue": issue,
        "events": events,
        "STATIC_URL": settings.STATIC_URL,
    }

    plain_text = render_to_string('email_issue_notification.txt', context)
    html = render_to_string('email_issue_notification.html', context)
    translation.deactivate()
    timezone.deactivate()

    return subject, plain_text, html, from_email, [user.email] 
开发者ID:znick,项目名称:anytask,代码行数:34,代码来源:send_notifications.py

示例10: send_only_notify

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def send_only_notify(domain, from_email):
    notify_messages = []

    for user_profile in UserProfile.objects.exclude(send_notify_messages__isnull=True).select_related('user'):
        user = user_profile.user
        if not user.email:
            continue

        unread_messages = user_profile.send_notify_messages.all()
        unread_count = len(unread_messages)

        if not unread_count:
            continue

        lang = user_profile.language
        translation.activate(lang)

        user_profile.send_notify_messages.clear()

        subject = u'{0}, '.format(user.first_name) + _(u'est_novye_soobshenija')

        unread_count_string = get_string(unread_count)

        context = {
            "domain": domain,
            "title": subject,
            "user": user,
            "unread_count": unread_count,
            "unread_count_string": unread_count_string,
            "messages": unread_messages,
            "STATIC_URL": settings.STATIC_URL,
        }

        plain_text = render_to_string('email_notification_mail.txt', context)
        html = render_to_string('email_notification_mail.html', context)
        notify_messages.append((subject, plain_text, html, from_email, [user.email]))

        translation.deactivate()

    return notify_messages 
开发者ID:znick,项目名称:anytask,代码行数:42,代码来源:send_mail_notifications.py

示例11: send_fulltext

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def send_fulltext(domain, from_email):
    notify_messages = []

    for i_message, message in enumerate(
            Message.objects.exclude(
                send_notify_messages__isnull=True
            ).prefetch_related('recipients')
    ):
        notify_messages.append([])
        for user in message.recipients.all():
            if not user.email:
                continue

            user_profile = user.profile
            user_profile.send_notify_messages.remove(message)

            lang = user_profile.language
            translation.activate(lang)

            subject = message.title
            message_text = render_mail(message, user)

            plain_text = strip_tags(message_text).replace(' ', ' ')

            context = {
                "domain": domain,
                "title": subject,
                "message_text": message_text,
            }
            html = render_to_string('email_fulltext_mail.html', context)

            notify_messages[i_message].append((subject, plain_text, html, from_email, [user.email]))

            translation.deactivate()

    return notify_messages 
开发者ID:znick,项目名称:anytask,代码行数:38,代码来源:send_mail_notifications.py

示例12: __call__

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def __call__(self, request):
        if request.META['PATH_INFO'].startswith('/en'):
            language = 'en'
        else:
            language = 'tr'

        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
        response = self.get_response(request)

        patch_vary_headers(response, ('Accept-Language',))
        response['Content-Language'] = translation.get_language()
        translation.deactivate()
        return response 
开发者ID:vigo,项目名称:django2-project-template,代码行数:16,代码来源:locale.py

示例13: __exit__

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def __exit__(self, *exc):
        translation.deactivate() 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:4,代码来源:helpers.py

示例14: process_response

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def process_response(self, request, response):
        patch_vary_headers(response, ("Accept-Language",))
        response["Content-Language"] = translation.get_language()
        translation.deactivate()
        return response 
开发者ID:madre,项目名称:devops,代码行数:7,代码来源:middleware.py

示例15: tearDown

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import deactivate [as 别名]
def tearDown(self):
        translation.deactivate() 
开发者ID:linuxsoftware,项目名称:ls.joyous,代码行数:4,代码来源:test_extra_info.py


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