class ChangeSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Change
        fields = ('category', 'page', 'data', 'created_at', 'author', '_links')
        dump_only = fields
        include_fk = True

    data = fields.List(
        fields.Tuple(
            (fields.Int(validate=validate.Range(-1, 1)), fields.String)))
    author = fields.UUID()
    _links = ma.Hyperlinks({
        'collection':
        ma.URLFor('changes',
                  values={
                      'category_id': '<category>',
                      'page_id': '<page>'
                  }),
        'page':
        ma.URLFor('page',
                  values={
                      'category_id': '<category>',
                      'page_id': '<page>'
                  }),
        'author':
        ma.URLFor('user', values={'user_id': '<author>'})
    })
class CategorySchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Category
        fields = ('id', 'title', 'order', '_links')
        dump_only = ('_links', )

    order = ma.auto_field(validate=[Range(min=0)])
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('category', values={'category_id': '<id>'}),
        'collection':
        ma.URLFor('categories'),
        'pages':
        ma.URLFor('pages', values={'category_id': '<id>'})
    })
class EventSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Event
        fields = ('id', 'name', 'details', 'start', 'end', 'owner', '_links')
        dump_only = ('id', 'owner', '_links')
        include_fk = True

    id = fields.UUID()
    owner = ma.auto_field('owner_id')
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('event', values={'event_id': '<id>'}),
        'collection':
        ma.URLFor('events'),
        'owner':
        ma.URLFor('user', values={'user_id': '<owner>'})
    })
Beispiel #4
0
class UserSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = User
        model_converter = ModelConverter
        fields = ('id', 'password', 'first_name', 'last_name', 'email', 'role',
                  '_links')
        dump_only = ('id', '_links')
        load_only = ('password', )

    id = fields.UUID()
    password = fields.String()
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('user', values={'user_id': '<id>'}),
        'collection':
        ma.URLFor('users')
    })
class GallerySchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Gallery
        fields = ('id', 'title', 'owner', 'media', '_links')
        dump_only = ('id', 'owner', 'media', '_links')
        include_relationships = True
        include_fk = True

    id = fields.UUID()
    owner = ma.auto_field('owner_id')
    media = fields.Nested(MediaSchema, many=True)
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('gallery', values={'gallery_id': '<id>'}),
        'collection':
        ma.URLFor('galleries'),
        'owner':
        ma.URLFor('user', values={'user_id': '<owner>'})
    })
Beispiel #6
0
class MediaSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Media
        fields = ('id', 'name', 'mimetype', 'extension', 'owner', '_links')
        dump_only = ('id', 'owner', '_links')
        include_fk = True

    id = fields.UUID()
    owner = ma.auto_field('owner_id')
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('media', values={'media_id': '<id>'}),
        'collection':
        ma.URLFor('medias'),
        'image':
        ma.URLFor('media_file', values={'media_id': '<id>'}),
        'thumbnail':
        ma.URLFor('media_file', values={
            'media_id': '<id>',
            'thumb': ''
        }),
        'owner':
        ma.URLFor('user', values={'user_id': '<owner>'})
    })
class PageSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Page
        fields = ('category', 'id', 'title', 'order', '_links')
        dump_only = ('_links', )
        include_fk = True

    order = ma.auto_field(validate=[Range(min=0)])
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('page',
                  values={
                      'category_id': '<category>',
                      'page_id': '<id>'
                  }),
        'collection':
        ma.URLFor('pages', values={'category_id': '<category>'}),
        'content':
        ma.URLFor('content',
                  values={
                      'category_id': '<category>',
                      'page_id': '<id>'
                  })
    })