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


Python declarative.setdefaults_path函数代码示例

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


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


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