Esempio n. 1
0
class MainDataItem(schema.SchemaCompoundedAttribute):
    type = schema.SchemaAttribute(data_type=str)
    id = schema.SchemaAttribute(data_type=str)
    attributes = schema.SchemaFreeContentCompoundedAttribute(
        attributes_mapping, required=False)
    links = LinksObject(required=False)
    relationships = schema.SchemaFreeContentCompoundedAttribute(
        relationships_type_mapping, required=False)
Esempio n. 2
0
class UserSchema(schema.Schema):
    username = schema.SchemaAttribute(str)
    first_name = schema.SchemaAttribute(str,
                                        required=False,
                                        required_with=['birth_date'])
    email = schema.SchemaAttribute(str)
    is_active = schema.SchemaAttribute(bool)
    birth_date = schema.SchemaAttribute(str, required=False)
Esempio n. 3
0
class RelationshipLinksObject(LinksObject):
    related = schema.SchemaAttribute(data_type=str)
Esempio n. 4
0
class LinksObject(schema.SchemaCompoundedAttribute):
    self = schema.SchemaAttribute(data_type=str)
Esempio n. 5
0
class RelationshipItemData(schema.SchemaCompoundedAttribute):
    type = schema.SchemaAttribute(data_type=str)
    id = schema.SchemaAttribute(data_type=str)
Esempio n. 6
0
import schema


class LinksObject(schema.SchemaCompoundedAttribute):
    self = schema.SchemaAttribute(data_type=str)


class RelationshipLinksObject(LinksObject):
    related = schema.SchemaAttribute(data_type=str)


attributes_mapping = {str: schema.SchemaAttribute(data_type=str)}


class RelationshipItemData(schema.SchemaCompoundedAttribute):
    type = schema.SchemaAttribute(data_type=str)
    id = schema.SchemaAttribute(data_type=str)


relationships_data_type_mapping = {
    dict: RelationshipItemData(),
    list:
    schema.SchemaCollectionAttribute(inner_attribute=RelationshipItemData())
}


class RelationshipItem(schema.SchemaCompoundedAttribute):
    links = RelationshipLinksObject(required=False)
    data = schema.SchemaFreeTypeAttribute(
        mapping=relationships_data_type_mapping)
Esempio n. 7
0
class Post(schema.SchemaCompoundedAttribute):
    title = schema.SchemaAttribute(data_type=str)
    tags = schema.SchemaCollectionAttribute(
        inner_attribute=schema.SchemaAttribute(data_type=str))
Esempio n. 8
0
class UserAppearance(schema.SchemaCompoundedAttribute):
    height = schema.SchemaAttribute(data_type=str)
    age = schema.SchemaAttribute(data_type=int)
Esempio n. 9
0
class ProfileSchema(schema.SchemaCompoundedAttribute):
    last_logged = schema.SchemaAttribute(str)
    settings = Settings()
Esempio n. 10
0
class Settings(schema.SchemaCompoundedAttribute):
    profile_color = schema.SchemaAttribute(str)
    stay_logged = schema.SchemaAttribute(bool)
Esempio n. 11
0
        'settings': {
            'profile_color': 'green',
            'stay_logged': True
        }
    }
}
example_compounded_user_data.update(profile_data)


class UserAppearance(schema.SchemaCompoundedAttribute):
    height = schema.SchemaAttribute(data_type=str)
    age = schema.SchemaAttribute(data_type=int)


user_attribute_mapping = {
    str: schema.SchemaAttribute(data_type=str),
    dict: UserAppearance(data_type=dict)
}

example_free_content_user_data = copy.deepcopy(example_compounded_user_data)
attributes_data = {
    'attributes': {
        'surname': 'Kolik',
        'job': 'Programmer',
        'appearance': {
            'height': '174cm',
            'age': 22
        }
    }
}
example_free_content_user_data.update(attributes_data)