當前位置: 首頁>>代碼示例>>Python>>正文


Python translation.ungettext方法代碼示例

本文整理匯總了Python中django.utils.translation.ungettext方法的典型用法代碼示例。如果您正苦於以下問題:Python translation.ungettext方法的具體用法?Python translation.ungettext怎麽用?Python translation.ungettext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils.translation的用法示例。


在下文中一共展示了translation.ungettext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: model_ngettext

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def model_ngettext(obj, n=None):
    """
    Return the appropriate `verbose_name` or `verbose_name_plural` value for
    `obj` depending on the count `n`.

    `obj` may be a `Model` instance, `Model` subclass, or `QuerySet` instance.
    If `obj` is a `QuerySet` instance, `n` is optional and the length of the
    `QuerySet` is used.

    """
    if isinstance(obj, models.query.QuerySet):
        if n is None:
            n = obj.count()
        obj = obj.model
    d = model_format_dict(obj)
    singular, plural = d["verbose_name"], d["verbose_name_plural"]
    return ungettext(singular, plural, n or 0) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:19,代碼來源:util.py

示例2: _make_blocktrans

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def _make_blocktrans(self, singular, plural=None, context=None, trans_vars=None,
                         count_var=None):
        if trans_vars is None:
            trans_vars = {}  # pragma: no cover
        if self.environment.finalize:
            finalized_trans_vars = {
                key: self.environment.finalize(val) for key, val in trans_vars.items()
            }
        else:
            finalized_trans_vars = trans_vars
        if plural is None:
            if context is None:
                return ugettext(force_text(singular)) % finalized_trans_vars
            else:
                return pgettext(force_text(context), force_text(singular)) % finalized_trans_vars
        else:
            if context is None:
                return ungettext(
                    force_text(singular), force_text(plural), trans_vars[count_var]
                ) % finalized_trans_vars
            else:
                return npgettext(
                    force_text(context), force_text(singular), force_text(plural),
                    trans_vars[count_var]
                ) % finalized_trans_vars 
開發者ID:MoritzS,項目名稱:jinja2-django-tags,代碼行數:27,代碼來源:extensions.py

示例3: judge

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def judge(self, request, queryset):
        if not request.user.has_perm('judge.rejudge_submission') or not request.user.has_perm('judge.edit_own_problem'):
            self.message_user(request, gettext('You do not have the permission to rejudge submissions.'),
                              level=messages.ERROR)
            return
        queryset = queryset.order_by('id')
        if not request.user.has_perm('judge.rejudge_submission_lot') and \
                queryset.count() > settings.DMOJ_SUBMISSIONS_REJUDGE_LIMIT:
            self.message_user(request, gettext('You do not have the permission to rejudge THAT many submissions.'),
                              level=messages.ERROR)
            return
        if not request.user.has_perm('judge.edit_all_problem'):
            id = request.profile.id
            queryset = queryset.filter(Q(problem__authors__id=id) | Q(problem__curators__id=id))
        judged = len(queryset)
        for model in queryset:
            model.judge(rejudge=True, batch_rejudge=True)
        self.message_user(request, ungettext('%d submission was successfully scheduled for rejudging.',
                                             '%d submissions were successfully scheduled for rejudging.',
                                             judged) % judged) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:22,代碼來源:submission.py

示例4: model_ngettext

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def model_ngettext(obj, n=None):
    """
    Return the appropriate `verbose_name` or `verbose_name_plural` value for
    `obj` depending on the count `n`.

    `obj` may be a `Model` instance, `Model` subclass, or `QuerySet` instance.
    If `obj` is a `QuerySet` instance, `n` is optional and the length of the
    `QuerySet` is used.
    """
    if isinstance(obj, models.query.QuerySet):
        if n is None:
            n = obj.count()
        obj = obj.model
    d = model_format_dict(obj)
    singular, plural = d["verbose_name"], d["verbose_name_plural"]
    return ungettext(singular, plural, n or 0) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:18,代碼來源:utils.py

示例5: get_context

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def get_context(self, context):
        if self.actions and self.admin_view.result_count:
            av = self.admin_view
            selection_note_all = ungettext('%(total_count)s selected',
                                           'All %(total_count)s selected', av.result_count)

            new_context = {
                'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(av.result_list)},
                'selection_note_all': selection_note_all % {'total_count': av.result_count},
                'action_choices': self.get_action_choices(),
                'actions_selection_counter': self.actions_selection_counter,
            }
            context.update(new_context)
        return context 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:16,代碼來源:actions.py

示例6: flag_comments

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def flag_comments(self, request, queryset):
        self._bulk_flag(queryset, perform_flag,
                        lambda n: ungettext('flagged', 'flagged', n)) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:5,代碼來源:comments.py

示例7: approve_comments

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def approve_comments(self, request, queryset):
        self._bulk_flag(queryset, perform_approve,
                        lambda n: ungettext('approved', 'approved', n)) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:5,代碼來源:comments.py

示例8: remove_comments

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def remove_comments(self, request, queryset):
        self._bulk_flag(queryset, perform_delete,
                        lambda n: ungettext('removed', 'removed', n)) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:5,代碼來源:comments.py

示例9: ngettext

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def ngettext(self, singular, plural, n):
        return ungettext(singular, plural, n) 
開發者ID:jpush,項目名稱:jbox,代碼行數:4,代碼來源:i18n.py

示例10: full_clean

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def full_clean(self):
        """
        Cleans all of self.data and populates self._errors and
        self._non_form_errors.
        """
        self._errors = []
        self._non_form_errors = self.error_class()

        if not self.is_bound:  # Stop further processing.
            return
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            self._errors.append(form.errors)
        try:
            if (self.validate_max and
                    self.total_form_count() - len(self.deleted_forms) > self.max_num) or \
                    self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max:
                raise ValidationError(ungettext(
                    "Please submit %d or fewer forms.",
                    "Please submit %d or fewer forms.", self.max_num) % self.max_num,
                    code='too_many_forms',
                )
            if (self.validate_min and
                    self.total_form_count() - len(self.deleted_forms) < self.min_num):
                raise ValidationError(ungettext(
                    "Please submit %d or more forms.",
                    "Please submit %d or more forms.", self.min_num) % self.min_num,
                    code='too_few_forms')
            # Give self.clean() a chance to do cross-form validation.
            self.clean()
        except ValidationError as e:
            self._non_form_errors = self.error_class(e.error_list) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:34,代碼來源:formsets.py

示例11: filesizeformat

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def filesizeformat(bytes):
    """
    Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc).
    """
    try:
        bytes = float(bytes)
    except (TypeError, ValueError, UnicodeDecodeError):
        value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
        return avoid_wrapping(value)

    filesize_number_format = lambda value: formats.number_format(round(value, 1), 1)

    KB = 1 << 10
    MB = 1 << 20
    GB = 1 << 30
    TB = 1 << 40
    PB = 1 << 50

    if bytes < KB:
        value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
    elif bytes < MB:
        value = ugettext("%s KB") % filesize_number_format(bytes / KB)
    elif bytes < GB:
        value = ugettext("%s MB") % filesize_number_format(bytes / MB)
    elif bytes < TB:
        value = ugettext("%s GB") % filesize_number_format(bytes / GB)
    elif bytes < PB:
        value = ugettext("%s TB") % filesize_number_format(bytes / TB)
    else:
        value = ugettext("%s PB") % filesize_number_format(bytes / PB)

    return avoid_wrapping(value) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:35,代碼來源:defaultfilters.py

示例12: recalculate_points

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def recalculate_points(self, request, queryset):
        count = 0
        for profile in queryset:
            profile.calculate_points()
            count += 1
        self.message_user(request, ungettext('%d user have scores recalculated.',
                                             '%d users have scores recalculated.',
                                             count) % count) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:10,代碼來源:profile.py

示例13: hide_comment

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def hide_comment(self, request, queryset):
        count = queryset.update(hidden=True)
        self.message_user(request, ungettext('%d comment successfully hidden.',
                                             '%d comments successfully hidden.',
                                             count) % count) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:7,代碼來源:comments.py

示例14: unhide_comment

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def unhide_comment(self, request, queryset):
        count = queryset.update(hidden=False)
        self.message_user(request, ungettext('%d comment successfully unhidden.',
                                             '%d comments successfully unhidden.',
                                             count) % count) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:7,代碼來源:comments.py

示例15: recalculate_score

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import ungettext [as 別名]
def recalculate_score(self, request, queryset):
        if not request.user.has_perm('judge.rejudge_submission'):
            self.message_user(request, gettext('You do not have the permission to rejudge submissions.'),
                              level=messages.ERROR)
            return
        submissions = list(queryset.defer(None).select_related(None).select_related('problem')
                           .only('points', 'case_points', 'case_total', 'problem__partial', 'problem__points'))
        for submission in submissions:
            submission.points = round(submission.case_points / submission.case_total * submission.problem.points
                                      if submission.case_total else 0, 1)
            if not submission.problem.partial and submission.points < submission.problem.points:
                submission.points = 0
            submission.save()
            submission.update_contest()

        for profile in Profile.objects.filter(id__in=queryset.values_list('user_id', flat=True).distinct()):
            profile.calculate_points()
            cache.delete('user_complete:%d' % profile.id)
            cache.delete('user_attempted:%d' % profile.id)

        for participation in ContestParticipation.objects.filter(
                id__in=queryset.values_list('contest__participation_id')).prefetch_related('contest'):
            participation.recompute_results()

        self.message_user(request, ungettext('%d submission were successfully rescored.',
                                             '%d submissions were successfully rescored.',
                                             len(submissions)) % len(submissions)) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:29,代碼來源:submission.py


注:本文中的django.utils.translation.ungettext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。