Python django.template.defaultfilters 模块,pluralize() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用django.template.defaultfilters.pluralize()

项目:django-intercoolerjs-helpers    作者:kezabelle    | 项目源码 | 文件源码
def click(request):
    global clicktrack
    clicktrack += 1
    do_reset = (request.is_intercooler() and
                request.intercooler_data.element.id == 'intro-btn2' and
                request.intercooler_data.current_url.match is not None)
    if do_reset:
        clicktrack = 0
    time = pluralize(clicktrack)
    text = "<span>You clicked me {} time{}...</span>".format(clicktrack, time)
    if do_reset:
        text = "<span>You reset the counter!, via {}</span>".format(request.intercooler_data.trigger.id)
    if not request.is_intercooler():
        raise Http404("Not allowed to come here outside of an Intercooler.js request!")
    resp = HttpResponse(text)
    return resp
项目:buggy    作者:fusionbox    | 项目源码 | 文件源码
def post(self, *args, **kwargs):
        self.form = self.get_form()
        self.object_list = self.get_queryset()
        bulk_action_form = self.get_bulk_action_form()
        errors = None
        if bulk_action_form.is_valid():
            try:
                with transaction.atomic():
                    for bug in bulk_action_form.cleaned_data['bugs']:
                        state_machine = self.mutator_class(self.request.user, bug)
                        state_machine.process_action(bulk_action_form.cleaned_data)
            except ValidationError as e:
                errors = e
        else:
            errors = sum(bulk_action_form.errors.values(), [])

        if errors:
            for error in errors:
                messages.error(self.request, 'Bulk Action Failed: {}'.format(error))
        else:
            bug_count = len(bulk_action_form.cleaned_data['bugs'])
            messages.success(
                self.request,
                'Success: {} bug{} updated'.format(bug_count, pluralize(bug_count)),
            )

        return HttpResponseRedirect(self.request.get_full_path())
项目:vishleva.com    作者:webmalc    | 项目源码 | 文件源码
def duration(self):
        duration = self.end - self.begin
        seconds = duration.total_seconds()
        hours = int(seconds // 3600)
        minutes = int((seconds % 3600) // 60)
        return '{} day{} {} hour{} {} minute{}'.format(
            duration.days,
            pluralize(duration.days), hours,
            pluralize(hours), minutes, pluralize(minutes))
项目:intel-manager-for-lustre    作者:intel-hpdd    | 项目源码 | 文件源码
def display_name(self):
        make = self.make if self.make != "" else "Unknown Make"
        model = self.model if self.model != "" else "Unknown Model"
        count = "(%s outlet%s)" % (self.max_outlets, pluralize(self.max_outlets)) if self.max_outlets > 0 else ""
        return ("%s %s %s" % (make, model, count)).strip()
项目:wagtail-personalisation    作者:LabD    | 项目源码 | 文件源码
def render(self):
        page_count = models.PersonalisablePageMetadata.objects.filter(
            segment__isnull=True).count()
        title = _("Personalised Page")
        return mark_safe("""
            <li class="icon icon-fa-file-o">
                <span>{}</span>{}{}
            </li>""".format(page_count, title, pluralize(page_count)))
项目:wagtail-personalisation    作者:LabD    | 项目源码 | 文件源码
def render(self):
        page_count = models.PersonalisablePageMetadata.objects.filter(
            segment__isnull=False).count()
        title = _("Variant")
        return mark_safe("""
                <li class="icon icon-fa-files-o">
                    <span>{}</span>{}{}
                </li>""".format(page_count, title, pluralize(page_count)))
项目:djk-sample    作者:Dmitri-Sintsov    | 项目源码 | 文件源码
def get_row_str_fields(self, obj, row=None):
        str_fields = super().get_row_str_fields(obj, row)
        if str_fields is None:
            str_fields = {}
        # Add formatted display of virtual field.
        is_plural = pluralize(row['exists_days'], arg='days')
        str_fields['exists_days'] = '{} {}'.format(row['exists_days'], 'day' if is_plural == '' else is_plural)
        return str_fields