コード例 #1
0
class BookSchema(BaseSchema):
    class Meta:
        fields = ('id', 'title', 'sort', 'author_sort', 'pubdate',
                  'series_index', 'path', 'has_cover', 'authors', 'languages',
                  'tags', 'publishers', 'identifiers', 'series', 'timestamp',
                  'last_modified', '_links')

    id = fields.String(required=False, allow_none=False)
    series_index = fields.Integer()
    timestamp = fields.String(dump_only=True)
    last_modified = fields.String(dump_only=True)

    authors = fields.Nested(AuthorSchema,
                            only=('name', 'link'),
                            many=True,
                            required=False)
    languages = fields.Nested(LanguageSchema, many=True, required=False)
    tags = fields.Nested(TagSchema, only=('name'), many=True, required=False)
    identifiers = fields.Nested(IdentifierSchema,
                                only=('type', 'val'),
                                many=True,
                                required=False)
    publishers = fields.Nested(PublisherSchema,
                               only=('name'),
                               many=True,
                               required=False)
    series = fields.Nested(SeriesSchema,
                           only=('name'),
                           many=True,
                           required=False)

    _links = ma.Hyperlinks(
        {
            'self': ma.UrlFor('api.get_book', id='<id>'),
            'collection': ma.UrlFor('api.get_books')
        },
        dump_only=True)

    @post_dump()
    def timestamps(self, data):
        if data['timestamp']:
            ts = datetime.utcnow().strptime(data['timestamp'],
                                            '%Y-%m-%d %H:%M:%S.%f')
            data['timestamp'] = utils.isoformat(ts)
        if data['last_modified']:
            ts = datetime.utcnow().strptime(data['last_modified'],
                                            '%Y-%m-%d %H:%M:%S.%f')
            data['last_modified'] = utils.isoformat(ts)
コード例 #2
0
class CommentSchema(BaseSchema):
    class Meta:
        fields = ('id', 'text', '_links')

    id = fields.String(required=False, allow_none=False)
    _links = ma.Hyperlinks({'self': ma.UrlFor('api.get_comment', id='<id>')},
                           dump_only=True)
コード例 #3
0
class PublisherSchema(BaseSchema):
    class Meta:
        fields = ('id', 'name', 'sort', '_links')

    id = fields.String(required=False, allow_none=False)
    _links = ma.Hyperlinks({'self': ma.UrlFor('api.get_publisher', id='<id>')},
                           dump_only=True)