本文整理汇总了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)
示例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
示例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)
示例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)
示例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
示例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))
示例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))
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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))