示例#1
0
class BookSchema(BaseSchema):
    title = attributes.String()
    date_published = attributes.Date()
    created_at = attributes.DateTime()
    updated_at = attributes.DateTime(allow_none=True)

    author = relationships.ToOne(foreign_types=('author', ))
    series = relationships.ToOne(foreign_types=('series', ), allow_none=True)
    chapters = relationships.ToMany(foreign_types=('chapters', ))
    photos = relationships.ToMany(foreign_types=('photos', ), allow_none=True)

    class Options:
        resource_cls = Book
        resource_type = 'books'
示例#2
0
class CommentSchema(BaseSchema):
    body = attributes.String(required=Event.CREATE, max_length=1024)
    author = relationships.ToOne(required=Event.CREATE,
                                 foreign_types=('people', ))

    class Options:
        resource_cls = Comment
        resource_type = 'comments'

    @sets('author')
    async def set_author(self,
                         field,
                         resource,
                         data,
                         sp,
                         context=None,
                         **kwargs):
        rid = self.ctx.registry.ensure_identifier(data['data'])
        storage = self.ctx.app['storage']
        author = storage[rid.type].get(rid.id)
        if author is None:
            raise ResourceNotFound(rid.type, rid.id)

        logger.debug('Set author of %r to %r.', resource, author)

        resource.author = author
        return resource
示例#3
0
class ArticleSchema(BaseSchema):
    title = attributes.String(required=Event.CREATE, max_length=256)
    author = relationships.ToOne(required=Event.CREATE,
                                 foreign_types=('people', ))
    comments = relationships.ToMany(foreign_types=('comments', ))

    class Options:
        resource_cls = Article
        resource_type = 'articles'
示例#4
0
class ChapterSchema(BaseSchema):
    title = attributes.String()
    ordering = attributes.Integer()
    created_at = attributes.DateTime()
    updated_at = attributes.DateTime(allow_none=True)

    book = relationships.ToOne(foreign_types=('books', ))

    class Options:
        resource_cls = Chapter
        resource_type = 'chapters'
示例#5
0
class PhotoSchema(BaseSchema):
    title = attributes.String()
    uri = attributes.String()
    created_at = attributes.DateTime()
    updated_at = attributes.DateTime(allow_none=True)

    imageable = relationships.ToOne(foreign_types=('authors', 'books',
                                                   'series')  # polymorphic
                                    )

    class Options:
        resource_cls = Photo
        resource_type = 'photos'