Beispiel #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)
Beispiel #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)
Beispiel #3
0
class RelationshipLinksObject(LinksObject):
    related = schema.SchemaAttribute(data_type=str)
Beispiel #4
0
class LinksObject(schema.SchemaCompoundedAttribute):
    self = schema.SchemaAttribute(data_type=str)
Beispiel #5
0
class RelationshipItemData(schema.SchemaCompoundedAttribute):
    type = schema.SchemaAttribute(data_type=str)
    id = schema.SchemaAttribute(data_type=str)
Beispiel #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)
Beispiel #7
0
class Post(schema.SchemaCompoundedAttribute):
    title = schema.SchemaAttribute(data_type=str)
    tags = schema.SchemaCollectionAttribute(
        inner_attribute=schema.SchemaAttribute(data_type=str))
Beispiel #8
0
class UserAppearance(schema.SchemaCompoundedAttribute):
    height = schema.SchemaAttribute(data_type=str)
    age = schema.SchemaAttribute(data_type=int)
Beispiel #9
0
class ProfileSchema(schema.SchemaCompoundedAttribute):
    last_logged = schema.SchemaAttribute(str)
    settings = Settings()
Beispiel #10
0
class Settings(schema.SchemaCompoundedAttribute):
    profile_color = schema.SchemaAttribute(str)
    stay_logged = schema.SchemaAttribute(bool)
Beispiel #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)