How to use the marshmallow.fields.DateTime function in marshmallow

To help you get started, we’ve selected a few marshmallow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github perdy / flama / tests / components / validation / test_schemas.py View on Github external
import datetime

import marshmallow
import pytest
from marshmallow import validate
from starlette.testclient import TestClient

from flama.applications import Flama

utc = datetime.timezone.utc


class Product(marshmallow.Schema):
    name = marshmallow.fields.String(validate=validate.Length(max=10))
    rating = marshmallow.fields.Integer(missing=None, validate=validate.Range(min=0, max=100))
    created = marshmallow.fields.DateTime()


class ReviewedProduct(Product):
    reviewer = marshmallow.fields.String(validate=validate.Length(max=20))


class Location(marshmallow.Schema):
    latitude = marshmallow.fields.Number(validate=validate.Range(max=90.0, min=-90.0))
    longitude = marshmallow.fields.Number(validate=validate.Range(max=180.0, min=-180.0))


class Place(marshmallow.Schema):
    location = marshmallow.fields.Nested(Location)
    name = marshmallow.fields.String(validate=validate.Length(max=100))
github mljar / mljar-api-python / mljar / model / project.py View on Github external
from marshmallow import Schema, fields, post_load

from .base import BaseModel

from ..exceptions import UnknownProjectTask

class ProjectSchema(Schema):
    hid = fields.Str()
    title = fields.Str()
    description = fields.Str(allow_none=True)
    task = fields.Str()
    hardware = fields.Str()
    scope = fields.Str()
    info = fields.Dict(allow_none=True)
    created_at = fields.DateTime()
    created_by = fields.Number()
    experiments_cnt = fields.Number()
    models_cnt = fields.Number()
    datasets = fields.List(fields.Dict(), allow_none=True)
    topalg = fields.List(fields.Dict(), allow_none=True)
    total_timelog = fields.Number(allow_none=True)
    compute_now = fields.Number()
    insights = fields.List(fields.Dict(), allow_none=True)

    @post_load
    def make_project_instance(self, data):
        return Project(**data)

class Project(BaseModel):
    schema = ProjectSchema(strict=True)
github theotherp / nzbhydra / nzbhydra / api.py View on Github external
indexerguid = fields.String()
    size = fields.Integer()
    category = fields.String()
    has_nfo = fields.Integer()
    details_link = fields.String()
    hash = fields.Integer()
    dbsearchid = fields.Integer()
    downloadType = fields.String()
    comments = fields.Integer()
    grabs = fields.Integer()
    files = fields.Integer()


class IndexerApiAccessSchema(Schema):
    indexer = fields.Nested(IndexerSchema, only="name")
    time = fields.DateTime()
    type = fields.String()
    url = fields.String()
    response_successful = fields.Boolean()
    response_time = fields.Integer()
    error = fields.String()


class RejectionCountSchema(Schema):
    passworded = fields.Integer()
    forbiddenword = fields.Integer()
    requiredword = fields.Integer()
    forbiddenregex = fields.Integer()
    requiredregex = fields.Integer()
    size = fields.Integer()
    age = fields.Integer()
    missing = fields.Integer()
github olawalejarvis / blog_api_tutorial / src / models / UserModel.py View on Github external
def __generate_hash(self, password):
    return bcrypt.generate_password_hash(password, rounds=10).decode("utf-8")
  
  def check_hash(self, password):
    return bcrypt.check_password_hash(self.password, password)
  
  def __repr(self):
    return ''.format(self.id)

class UserSchema(Schema):
  id = fields.Int(dump_only=True)
  name = fields.Str(required=True)
  email = fields.Email(required=True)
  password = fields.Str(required=True, load_only=True)
  created_at = fields.DateTime(dump_only=True)
  modified_at = fields.DateTime(dump_only=True)
  blogposts = fields.Nested(BlogpostSchema, many=True)
github corpus-christi / corpus-christi / api / src / events / models.py View on Github external
teams = relationship("EventTeam", backref="event")
    persons = relationship("EventPerson", backref="event")
    participants = relationship("EventParticipant", backref="event")
    images = relationship("ImageEvent", backref="event")
    groups = relationship("EventGroup", backref="event")

    def __repr__(self):
        return f""


class EventSchema(Schema):
    id = fields.Integer(dump_only=True, required=True, validate=Range(min=1))
    title = fields.String(required=True, validate=Length(min=1))
    description = fields.String(allow_none=True)
    start = fields.DateTime(required=True)
    end = fields.DateTime(required=True)
    location_id = fields.Integer(allow_none=True)
    active = fields.Boolean()
    attendance = fields.Integer(allow_none=True)
    aggregate = fields.Boolean(allow_none=True)

    location = fields.Nested('LocationSchema', allow_none=True, dump_only=True)
    participants = fields.Nested('EventParticipantSchema', many=True, exclude=['event'], dump_only=True)
    persons = fields.Nested('EventPersonSchema', many=True, exclude=['event'], dump_only=True)
    teams = fields.Nested('EventTeamSchema', many=True, exclude=['event'], dump_only=True)
    assets = fields.Nested('EventAssetSchema', many=True, exclude=['event'], dump_only=True)
    images = fields.Nested('ImageEventSchema', many=True, exclude=['event'], dump_only=True)
    groups = fields.Nested('EventGroupSchema', many=True, exclude=['event'], dump_only=True)


# ---- EventAsset
github labd / commercetools-python-sdk / src / commercetools / schemas / _subscription.py View on Github external
modified_at = marshmallow.fields.DateTime(allow_none=True, data_key="modifiedAt")

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["notification_type"]
        return types.ResourceDeletedDelivery(**data)


class ResourceUpdatedDeliverySchema(SubscriptionDeliverySchema):
    "Marshmallow schema for :class:`commercetools.types.ResourceUpdatedDelivery`."
    version = marshmallow.fields.Integer(allow_none=True)
    old_version = marshmallow.fields.Integer(allow_none=True, data_key="oldVersion")
    modified_at = marshmallow.fields.DateTime(allow_none=True, data_key="modifiedAt")

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["notification_type"]
        return types.ResourceUpdatedDelivery(**data)


class SnsDestinationSchema(DestinationSchema):
    "Marshmallow schema for :class:`commercetools.types.SnsDestination`."
    access_key = marshmallow.fields.String(allow_none=True, data_key="accessKey")
    access_secret = marshmallow.fields.String(allow_none=True, data_key="accessSecret")
    topic_arn = marshmallow.fields.String(allow_none=True, data_key="topicArn")
github actorcloud / ActorCloud / server / actor_libs / schemas / __init__.py View on Github external
class CustomOptions(SchemaOpts):
    """ Override schema default options. """

    def __init__(self, meta):
        super(CustomOptions, self).__init__(meta)
        self.dateformat = '%Y-%m-%d %H:%M:%S'
        self.strict = True


class BaseSchema(Schema):
    OPTIONS_CLASS = CustomOptions
    is_private = False

    id = fields.Int(dump_only=True)
    createAt = fields.DateTime(dump_only=True)
    updateAt = fields.DateTime(dump_only=True)

    def handle_error(self, exception, data):
        """ Log and raise our custom exception when (de)serialization fails. """
        raise FormInvalid(errors=exception.messages)

    @classmethod
    def validate_request(cls, request_dict=None, obj=None):
        request_get_json = request.get_json()
        if not request_get_json:
            raise APIException()
        if not request_dict:
            request_dict = request_get_json
        instance = cls()
        instance._obj = obj
        result = instance.load(request_dict)
github teracyhq-incubator / flask-boilerplate / app / api_1_0 / schemas.py View on Github external
description = fields.Str()
    created_at = fields.DateTime()
    updated_at = fields.DateTime()


class RoleListSchema(Schema):
    data = fields.List(fields.Nested(RoleSchema))
    paging = fields.Nested(PagingSchema)


class UserSchema(Schema):
    id = fields.Int()
    email = fields.Email()
    active = fields.Bool()
    confirmed_at = fields.DateTime()
    created_at = fields.DateTime()
    updated_at = fields.DateTime()
    roles = fields.List(fields.Nested(RoleSchema))


class UserListSchema(Schema):
    data = fields.List(fields.Nested(UserSchema))
    paging = fields.Nested(PagingSchema)
github teracyhq-incubator / flask-boilerplate / app / api_1_0 / schemas.py View on Github external
created_at = fields.DateTime()
    updated_at = fields.DateTime()


class RoleListSchema(Schema):
    data = fields.List(fields.Nested(RoleSchema))
    paging = fields.Nested(PagingSchema)


class UserSchema(Schema):
    id = fields.Int()
    email = fields.Email()
    active = fields.Bool()
    confirmed_at = fields.DateTime()
    created_at = fields.DateTime()
    updated_at = fields.DateTime()
    roles = fields.List(fields.Nested(RoleSchema))


class UserListSchema(Schema):
    data = fields.List(fields.Nested(UserSchema))
    paging = fields.Nested(PagingSchema)