Python marshmallow.fields.DateTime() Examples

The following are 3 code examples of marshmallow.fields.DateTime(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module marshmallow.fields , or try the search function .
Example #1
Source File: test_marshmallow.py    From pydantic with MIT License 6 votes vote down vote up
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() 
Example #2
Source File: test_dump.py    From marshmallow-jsonschema with MIT License 5 votes vote down vote up
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",
    } 
Example #3
Source File: parser.py    From polyaxon with Apache License 2.0 5 votes vote down vote up
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,
    )