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


Python defaultfilters.pluralize方法代码示例

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


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

示例1: environment

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def environment(**options: Any) -> Environment:
    env = Environment(**options)
    env.globals.update({
        'default_page_params': {
            'debug_mode': False,
            'webpack_public_path': staticfiles_storage.url(
                settings.WEBPACK_LOADER['DEFAULT']['BUNDLE_DIR_NAME'],
            ),
        },
        'static': staticfiles_storage.url,
        'url': reverse,
        'render_markdown_path': render_markdown_path,
    })

    env.install_gettext_translations(translation, True)

    env.filters['slugify'] = slugify
    env.filters['pluralize'] = pluralize
    env.filters['display_list'] = display_list
    env.filters['device_action'] = device_action
    env.filters['timesince'] = timesince

    return env 
开发者ID:zulip,项目名称:zulip,代码行数:25,代码来源:__init__.py

示例2: save_form_submission_data

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def save_form_submission_data(instance, form):
    """ saves the form submission data """

    # copy the cleaned_data so we dont mess with the original
    submission_data = form.cleaned_data.copy()

    # change the submission data to a count of the files
    for field in form.files.keys():
        count = len(form.files.getlist(field))
        submission_data[field] = "{} file{}".format(count, pluralize(count))

    # save the submission data
    submission = instance.get_submission_class().objects.create(
        form_data=json.dumps(submission_data, cls=FormSubmissionSerializer),
        form=instance,
    )

    # save the form files
    for field in form.files:
        for file in form.files.getlist(field):
            FormSubmissionFile.objects.create(
                submission=submission, field=field, file=file
            ) 
开发者ID:labd,项目名称:wagtailstreamforms,代码行数:25,代码来源:wagtailstreamforms_hooks.py

示例3: handle

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def handle(self, *args, **options):
        duplicate_records = self.get_duplicate_records()
        duplicate_count = duplicate_records.count()
        logging.info('%d duplicate condition%s found in database.', duplicate_count, pluralize(duplicate_count))

        for record in duplicate_records:
            num_of_duplicates = record.pop('id_count')
            conditions = Condition.objects.filter(**record)
            first_condition = conditions.first()
            logging.info('Condition with id [%d] has %d duplicates.', first_condition.id, int(num_of_duplicates) - 1)
            for condition in conditions.exclude(id=first_condition.id):
                conditional_offers_queryset = ConditionalOffer.objects.filter(condition=condition)
                if conditional_offers_queryset.exists():
                    conditional_offers_queryset.update(condition=first_condition)
                logging.info('Deleting condition record with id [%d].', condition.id)
                condition.delete() 
开发者ID:edx,项目名称:ecommerce,代码行数:18,代码来源:remove_duplicate_conditions.py

示例4: render

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
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))) 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:9,代码来源:wagtail_hooks.py

示例5: email_submission

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def email_submission(instance, form):
    """ Send an email with the submission. """

    if not hasattr(instance, 'advanced_settings'):
        return

    addresses = [instance.advanced_settings.to_address]
    content = ['Please see below submission\n', ]
    from_address = settings.DEFAULT_FROM_EMAIL
    subject = 'New Form Submission : %s' % instance.title

    # build up the email content
    for field, value in form.cleaned_data.items():
        if field in form.files:
            count = len(form.files.getlist(field))
            value = '{} file{}'.format(count, pluralize(count))
        elif isinstance(value, list):
            value = ', '.join(value)
        content.append('{}: {}'.format(field, value))
    content = '\n'.join(content)

    # create the email message
    email = EmailMessage(
        subject=subject,
        body=content,
        from_email=from_address,
        to=addresses
    )

    # attach any files submitted
    for field in form.files:
        for file in form.files.getlist(field):
            file.seek(0)
            email.attach(file.name, file.read(), file.content_type)

    # finally send the email
    email.send(fail_silently=True) 
开发者ID:labd,项目名称:wagtailstreamforms,代码行数:39,代码来源:wagtailstreamforms_hooks.py

示例6: handle

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def handle(self, *args, **options):
        limit = options['limit']
        offset = options['offset']
        priority = options['priority']

        try:
            conditional_offers = ConditionalOffer.objects.filter(
                offer_type=ConditionalOffer.VOUCHER,
                priority=priority
            )[offset:offset + limit]

            count = len(conditional_offers)
            if count == 0:
                logger.info('No offer found which needs a priority fix')
                return

            line_feed = '\n'
            offer_names = 'Conditional offers to be updated{line_feed}'.format(line_feed=line_feed)
            for i in range(count):
                if i == count - 1:
                    line_feed = ''
                offer_names = '{names}{index}. {name}{line_feed}'.format(
                    names=offer_names, index=i + 1, name=conditional_offers[i].name, line_feed=line_feed
                )

            # List down all conditional which needs to be updated.
            logger.warning(offer_names)

            pluralized = pluralize(count)
            if query_yes_no(self.CONFIRMATION_PROMPT.format(count=count, pluralized=pluralized), default="no"):
                for offer in conditional_offers:
                    offer.priority = OFFER_PRIORITY_VOUCHER
                    offer.save()
                logger.info('Operation completed. %d conditional offer%s updated successfully.', count, pluralized)
            else:
                logger.info('Operation canceled.')

        except Exception as exc:  # pylint: disable=broad-except
            logger.exception('Command execution failed while executing batch %d,%d\n%s', offset, limit, exc) 
开发者ID:edx,项目名称:ecommerce,代码行数:41,代码来源:change_priority_of_offers.py

示例7: test_integers

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def test_integers(self):
        self.assertEqual(pluralize(1), '')
        self.assertEqual(pluralize(0), 's')
        self.assertEqual(pluralize(2), 's') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_pluralize.py

示例8: test_floats

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def test_floats(self):
        self.assertEqual(pluralize(0.5), 's')
        self.assertEqual(pluralize(1.5), 's') 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_pluralize.py

示例9: test_decimals

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def test_decimals(self):
        self.assertEqual(pluralize(Decimal(1)), '')
        self.assertEqual(pluralize(Decimal(0)), 's')
        self.assertEqual(pluralize(Decimal(2)), 's') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_pluralize.py

示例10: test_lists

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def test_lists(self):
        self.assertEqual(pluralize([1]), '')
        self.assertEqual(pluralize([]), 's')
        self.assertEqual(pluralize([1, 2, 3]), 's') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_pluralize.py

示例11: test_suffixes

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def test_suffixes(self):
        self.assertEqual(pluralize(1, 'es'), '')
        self.assertEqual(pluralize(0, 'es'), 'es')
        self.assertEqual(pluralize(2, 'es'), 'es')
        self.assertEqual(pluralize(1, 'y,ies'), 'y')
        self.assertEqual(pluralize(0, 'y,ies'), 'ies')
        self.assertEqual(pluralize(2, 'y,ies'), 'ies')
        self.assertEqual(pluralize(0, 'y,ies,error'), '') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_pluralize.py

示例12: test_value_error

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def test_value_error(self):
        self.assertEqual(pluralize('', 'y,es'), 'y') 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:test_pluralize.py

示例13: handle

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def handle(self, *args, **options):
        extension_by_filename = {}
        for extension in Extension.objects.all():
            filename = get_filename_from_url(extension.xpi.url)
            extension_by_filename[filename] = extension

        target_revisions = RecipeRevision.objects.filter(action__name="opt-out-study")
        update_count = 0
        for rev in target_revisions:
            # Pull into a local variable to modify the arguments since
            # `rev.arguments` is actually a property that parses JSON, not a
            # real attribute of the object
            arguments = rev.arguments

            if not arguments.get("addonUrl"):
                self.stderr.write(
                    f"Warning: Recipe {rev.recipe.id} revision {rev.id} has action=opt-out-study, "
                    f"but no addonUrl"
                )
                continue

            filename = get_filename_from_url(arguments["addonUrl"])

            if filename not in extension_by_filename:
                self.stderr.write(
                    f"Warning: Recipe {rev.recipe.id} revision {rev.id} has an addonUrl that does "
                    f"not match any in the database."
                )
                continue

            extension = extension_by_filename[filename]
            new_url = extension.xpi.url
            if arguments["addonUrl"] == new_url:
                # nothing to do
                continue

            arguments["addonUrl"] = extension.xpi.url
            rev.arguments = arguments
            rev.save()

            # The revision has changed so update the signature
            recipe = rev.recipe
            recipe.update_signature()
            recipe.save()

            update_count += 1

        self.stdout.write(f"{update_count} revision{pluralize(update_count)} updated") 
开发者ID:mozilla,项目名称:normandy,代码行数:50,代码来源:update_addon_urls.py

示例14: handle

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import pluralize [as 别名]
def handle(self, *args, **options):
        partner_code = options['partner']

        catalogs = Catalog.objects.filter(partner__short_code__iexact=partner_code)
        ranges = Range.objects.filter(catalog__in=catalogs).distinct()
        benefits = Benefit.objects.filter(range__in=ranges).distinct()
        conditional_offers = ConditionalOffer.objects.filter(benefit__in=benefits).distinct()

        count = len(conditional_offers)
        if count == 0:
            logger.info('No offer found for partner [%s].', partner_code)
            return

        line_feed = '\n'
        offer_names = 'Conditional offers to be deleted for partner [{partner_code}] {line_feed}'.format(
            partner_code=partner_code, line_feed=line_feed
        )
        for i in range(count):
            if i == count - 1:
                line_feed = ''
            offer_names = '{names} {index}. {name} {line_feed}'.format(
                names=offer_names, index=i + 1, name=conditional_offers[i].name, line_feed=line_feed
            )

        # List down all conditional offers to be deleted.
        logger.warning(offer_names)

        pluralized = pluralize(count)
        if query_yes_no(self.CONFIRMATION_PROMPT.format(count=count, pluralized=pluralized), default="no"):
            # disconnect post_delete oscar receiver to avoid Condition matching query does not exist.
            signals.post_delete.disconnect(
                receiver=delete_unused_related_conditions_and_benefits, sender=ConditionalOffer
            )

            # delete partner related conditional offers.
            conditional_offers.delete()

            # re-connect post_delete oscar receiver.
            signals.post_delete.connect(
                receiver=delete_unused_related_conditions_and_benefits, sender=ConditionalOffer
            )
            logger.info('%d conditional offer%s removed successfully.', count, pluralized)
        else:
            logger.info('Operation canceled.')
            return 
开发者ID:edx,项目名称:ecommerce,代码行数:47,代码来源:remove_partner_offers.py


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