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