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


Python fields.DateTime方法代码示例

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


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

示例1: __init__

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import DateTime [as 别名]
def __init__(self, allow_extra):
        class LocationSchema(Schema):
            latitude = fields.Float(allow_none=True)
            longitude = fields.Float(allow_none=True)

        class SkillSchema(Schema):
            subject = fields.Str(required=True)
            subject_id = fields.Integer(required=True)
            category = fields.Str(required=True)
            qual_level = fields.Str(required=True)
            qual_level_id = fields.Integer(required=True)
            qual_level_ranking = fields.Float(default=0)

        class Model(Schema):
            id = fields.Integer(required=True)
            client_name = fields.Str(validate=validate.Length(max=255), required=True)
            sort_index = fields.Float(required=True)
            # client_email = fields.Email()
            client_phone = fields.Str(validate=validate.Length(max=255), allow_none=True)

            location = fields.Nested(LocationSchema)

            contractor = fields.Integer(validate=validate.Range(min=0), allow_none=True)
            upstream_http_referrer = fields.Str(validate=validate.Length(max=1023), allow_none=True)
            grecaptcha_response = fields.Str(validate=validate.Length(min=20, max=1000), required=True)
            last_updated = fields.DateTime(allow_none=True)
            skills = fields.Nested(SkillSchema, many=True)

        self.allow_extra = allow_extra  # unused
        self.schema = Model() 
开发者ID:samuelcolvin,项目名称:pydantic,代码行数:32,代码来源:test_marshmallow.py

示例2: test_datetime_based

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import DateTime [as 别名]
def test_datetime_based():
    class TestSchema(Schema):
        f_date = fields.Date()
        f_datetime = fields.DateTime()
        f_time = fields.Time()

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    assert dumped["definitions"]["TestSchema"]["properties"]["f_date"] == {
        "format": "date",
        "title": "f_date",
        "type": "string",
    }

    assert dumped["definitions"]["TestSchema"]["properties"]["f_datetime"] == {
        "format": "date-time",
        "title": "f_datetime",
        "type": "string",
    }

    assert dumped["definitions"]["TestSchema"]["properties"]["f_time"] == {
        "format": "time",
        "title": "f_time",
        "type": "string",
    } 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:29,代码来源:test_dump.py

示例3: get_datetime

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import DateTime [as 别名]
def get_datetime(
    key, value, is_list=False, is_optional=False, default=None, options=None
):
    """
    Get the value corresponding to the key and converts it to `datetime`/`list(datetime)`.

    Args:
        key: the dict key.
        value: the value to parse.
        is_list: If this is one element or a list of elements.
        is_optional: To raise an error if key was not found.
        default: default value if is_optional is True.
        options: list/tuple if provided, the value must be one of these values.

    Returns:
        `date`: value corresponding to the key.
    """
    if is_list:
        return _get_typed_list_value(
            key=key,
            value=value,
            target_type=datetime,
            type_convert=fields.DateTime().deserialize,
            is_optional=is_optional,
            default=default,
            options=options,
        )

    return _get_typed_value(
        key=key,
        value=value,
        target_type=datetime,
        type_convert=fields.DateTime().deserialize,
        is_optional=is_optional,
        default=default,
        options=options,
    ) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:39,代码来源:parser.py


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