• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python declarative.setdefaults_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tri.declarative.setdefaults_path函数的典型用法代码示例。如果您正苦于以下问题:Python setdefaults_path函数的具体用法?Python setdefaults_path怎么用?Python setdefaults_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: datetime

    def datetime(**kwargs):
        iso_formats = [
            '%Y-%m-%d %H:%M:%S',
            '%Y-%m-%d %H:%M',
            '%Y-%m-%d %H',
        ]

        def datetime_parse(string_value, **_):
            errors = []
            for iso_format in iso_formats:
                try:
                    return datetime.strptime(string_value, iso_format)
                except ValueError as e:
                    errors.append('%s' % e)
            assert errors
            raise ValidationError('Time data "%s" does not match any of the formats %s' % (string_value, ', '.join('"%s"' % x for x in iso_formats)))

        def datetime_render_value(value, **_):
            return value.strftime(iso_formats[0]) if value else ''

        setdefaults_path(
            kwargs,
            parse=datetime_parse,
            render_value=datetime_render_value,
        )
        return Field(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:26,代码来源:__init__.py


示例2: member_from_model

def member_from_model(model, factory_lookup, defaults_factory, factory_lookup_register_function=None, field_name=None, model_field=None, **kwargs):
    if model_field is None:
        # noinspection PyProtectedMember
        model_field = model._meta.get_field(field_name)

    setdefaults_path(
        kwargs,
        defaults_factory(model_field),
        name=field_name,
    )

    factory = factory_lookup.get(type(model_field), MISSING)

    if factory is MISSING:
        for django_field_type, func in reversed(factory_lookup.items()):
            if isinstance(model_field, django_field_type):
                factory = func
                break

    if factory is MISSING:  # pragma: no cover
        message = 'No factory for %s.' % type(model_field)
        if factory_lookup_register_function is not None:
            message += ' Register a factory with %s, you can also register one that returns None to not handle this field type' % factory_lookup_register_function.__name__
        raise AssertionError(message)

    return factory(model_field=model_field, model=model, **kwargs) if factory else None
开发者ID:boxed,项目名称:tri.form,代码行数:26,代码来源:__init__.py


示例3: email

 def email(**kwargs):
     setdefaults_path(
         kwargs,
         input_type='email',
         parse=lambda string_value, **_: validate_email(string_value) or string_value,
     )
     return Field(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:7,代码来源:__init__.py


示例4: many_to_many_factory

 def many_to_many_factory(model_field, **kwargs):
     setdefaults_path(
         kwargs,
         choices=model_field.rel.to._default_manager.all(),
         model=model_field.foreign_related_fields[0].model,
     )
     return Column.multi_choice_queryset(model_field=model_field, **kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:7,代码来源:db_compat.py


示例5: foreign_key_factory

 def foreign_key_factory(model_field, **kwargs):
     setdefaults_path(
         kwargs,
         choices=model_field.foreign_related_fields[0].model.objects.all(),
         model=model_field.foreign_related_fields[0].model,
     )
     return Column.choice_queryset(model_field=model_field, **kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:7,代码来源:db_compat.py


示例6: foreign_key_factory

def foreign_key_factory(model_field, **kwargs):
    setdefaults_path(
        kwargs,
        choices=model_field.foreign_related_fields[0].model.objects.all(),
    )
    kwargs['model'] = model_field.foreign_related_fields[0].model
    return Field.choice_queryset(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:7,代码来源:__init__.py


示例7: test_setdefatults_path_retain_empty

def test_setdefatults_path_retain_empty():
    actual = setdefaults_path(Namespace(a=Namespace()), a__b=Namespace())
    expected = Namespace(a__b=Namespace())
    assert expected == actual

    actual = setdefaults_path(Namespace(), attrs__class=Namespace())
    expected = Namespace(attrs__class=Namespace())
    assert expected == actual
开发者ID:TriOptima,项目名称:tri.declarative,代码行数:8,代码来源:test_misc.py


示例8: multi_choice_queryset

 def multi_choice_queryset(**kwargs):
     setdefaults_path(
         kwargs,
         attrs__multiple=True,
         choice_to_option=lambda form, field, choice: (choice, choice.pk, "%s" % choice, field.value_list and choice in field.value_list),
         is_list=True,
     )
     return Field.choice_queryset(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:8,代码来源:__init__.py


示例9: integer

    def integer(**kwargs):
        def int_parse(string_value, **_):
            return int(string_value)

        setdefaults_path(
            kwargs,
            parse=int_parse,
        )
        return Field(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:9,代码来源:__init__.py


示例10: decimal

    def decimal(**kwargs):
        def decimal_parse(string_value, **_):
            return Decimal(string_value)

        setdefaults_path(
            kwargs,
            parse=decimal_parse,
        )
        return Field(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:9,代码来源:__init__.py


示例11: many_to_many_factory

def many_to_many_factory(model_field, **kwargs):
    setdefaults_path(
        kwargs,
        choices=model_field.rel.to.objects.all(),
        read_from_instance=lambda field, instance: getattr_path(instance, field.attr).all(),
        extra__django_related_field=True,
    )
    kwargs['model'] = model_field.rel.to
    return Field.multi_choice_queryset(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:9,代码来源:__init__.py


示例12: phone_number

    def phone_number(**kwargs):
        def phone_number_is_valid(parsed_data, **_):
            return re.match(r'^\+\d{1,3}(( |-)?\(\d+\))?(( |-)?\d+)+$', parsed_data, re.IGNORECASE), 'Please use format +<country code> (XX) XX XX. Example of US number: +1 (212) 123 4567 or +1 212 123 4567'

        setdefaults_path(
            kwargs,
            is_valid=phone_number_is_valid,
        )
        return Field(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:9,代码来源:__init__.py


示例13: email

    def email(**kwargs):
        def email_parse(string_value, **_):
            return validate_email(string_value) or string_value

        setdefaults_path(
            kwargs,
            input_type='email',
            parse=email_parse,
        )
        return Field(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:10,代码来源:__init__.py


示例14: url

    def url(**kwargs):
        def url_parse(string_value, **_):
            return URLValidator(string_value) or string_value

        setdefaults_path(
            kwargs,
            input_type='email',
            parse=url_parse,
        )
        return Field(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:10,代码来源:__init__.py


示例15: info

 def info(value, **kwargs):
     """
     Shortcut to create an info entry.
     """
     setdefaults_path(
         kwargs,
         initial=value,
         editable=False,
         attr=None,
     )
     return Field(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:11,代码来源:__init__.py


示例16: multi_choice_queryset

    def multi_choice_queryset(**kwargs):
        def multi_choice_queryset_choice_to_option(field, choice, **_):
            return choice, choice.pk, "%s" % choice, field.value_list and choice in field.value_list

        setdefaults_path(
            kwargs,
            attrs__multiple=True,
            choice_to_option=multi_choice_queryset_choice_to_option,
            is_list=True,
        )
        return Field.choice_queryset(**kwargs)
开发者ID:TriOptima,项目名称:tri.form,代码行数:11,代码来源:__init__.py


示例17: file

    def file(**kwargs):
        def file_write_to_instance(field, instance, value):
            if value:
                default_write_to_instance(field=field, instance=instance, value=value)

        setdefaults_path(
            kwargs,
            input_type='file',
            template_string='{% extends "tri_form/table_form_row.html" %}{% block extra_content %}{{ field.value }}{% endblock %}',
            write_to_instance=file_write_to_instance,
        )
        return Field(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:12,代码来源:__init__.py


示例18: boolean

 def boolean(**kwargs):
     """
     Boolean field. Tries hard to parse a boolean value from its input.
     """
     setdefaults_path(
         kwargs,
         parse=lambda string_value, **_: bool_parse(string_value),
         required=False,
         template='tri_form/{style}_form_row_checkbox.html',
         input_template='tri_form/checkbox.html',
         is_boolean=True,
     )
     return Field(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:13,代码来源:__init__.py


示例19: float

    def float(**kwargs):
        def parse_float(string_value, **_):
            try:
                return float(string_value)
            except ValueError:
                # Acrobatics so we get equal formatting in python 2/3
                raise ValueError("could not convert string to float: %s" % string_value)

        setdefaults_path(
            kwargs,
            parse=parse_float,
        )
        return Field(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:13,代码来源:__init__.py


示例20: heading

 def heading(label, show=True, template='tri_form/heading.html', **kwargs):
     """
     Shortcut to create a fake input that performs no parsing but is useful to separate sections of a form.
     """
     setdefaults_path(
         kwargs,
         label=label,
         show=show,
         template=template,
         editable=False,
         attr=None,
         name='@@[email protected]@',
     )
     return Field(**kwargs)
开发者ID:boxed,项目名称:tri.form,代码行数:14,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python form.Field类代码示例发布时间:2022-05-27
下一篇:
Python declarative.setdefaults函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap