X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/18aa8ca52202003e5628a882f3469a04d905cc05..b6d44713f806e7186589da45d7622123a9c36a60:/src/catalogue/api/serializers.py diff --git a/src/catalogue/api/serializers.py b/src/catalogue/api/serializers.py index daa86fec8..5f96e0270 100644 --- a/src/catalogue/api/serializers.py +++ b/src/catalogue/api/serializers.py @@ -40,10 +40,124 @@ class TagDetailSerializer(serializers.ModelSerializer): ] +class AuthorItemSerializer(serializers.ModelSerializer): + url = AbsoluteURLField() + href = AbsoluteURLField( + view_name='catalogue_api_author', + view_args=('slug',) + ) + + class Meta: + model = Tag + fields = [ + 'url', 'href', 'name' + ] + +class AuthorSerializer(AuthorItemSerializer): + photo_thumb = ThumbnailField('139x193', source='photo') + + class Meta: + model = Tag + fields = [ + 'url', 'href', 'name', 'slug', 'sort_key', 'description', + 'genitive', 'photo', 'photo_thumb', 'photo_attribution', + ] + +class EpochItemSerializer(serializers.ModelSerializer): + url = AbsoluteURLField() + href = AbsoluteURLField( + view_name='catalogue_api_epoch', + view_args=('slug',) + ) + class Meta: + model = Tag + fields = ['url', 'href', 'name'] + +class EpochSerializer(EpochItemSerializer): + class Meta: + model = Tag + fields = [ + 'url', 'href', 'name', 'slug', 'sort_key', 'description', + 'adjective_feminine_singular', 'adjective_nonmasculine_plural', + ] + +class GenreItemSerializer(serializers.ModelSerializer): + url = AbsoluteURLField() + href = AbsoluteURLField( + view_name='catalogue_api_genre', + view_args=('slug',) + ) + class Meta: + model = Tag + fields = ['url', 'href', 'name'] + +class GenreSerializer(GenreItemSerializer): + class Meta: + model = Tag + fields = [ + 'url', 'href', 'name', 'slug', 'sort_key', 'description', + 'plural', 'genre_epoch_specific', + ] + +class KindItemSerializer(serializers.ModelSerializer): + url = AbsoluteURLField() + href = AbsoluteURLField( + view_name='catalogue_api_kind', + view_args=('slug',) + ) + class Meta: + model = Tag + fields = ['url', 'href', 'name'] + +class KindSerializer(KindItemSerializer): + class Meta: + model = Tag + fields = [ + 'url', 'href', 'name', 'slug', 'sort_key', 'description', + 'collective_noun', + ] + + class TranslatorSerializer(serializers.Serializer): name = serializers.CharField(source='*') +class BookSerializer2(serializers.ModelSerializer): + url = AbsoluteURLField() + href = AbsoluteURLField(view_name='catalogue_api_book', view_args=['slug']) + xml = EmbargoURLField(source='xml_url') + html = EmbargoURLField(source='html_url') + txt = EmbargoURLField(source='txt_url') + fb2 = EmbargoURLField(source='fb2_url') + epub = EmbargoURLField(source='epub_url') + mobi = EmbargoURLField(source='mobi_url') + pdf = EmbargoURLField(source='pdf_url') + + authors = AuthorItemSerializer(many=True) + translators = AuthorItemSerializer(many=True) + epochs = EpochItemSerializer(many=True) + genres = GenreItemSerializer(many=True) + kinds = KindItemSerializer(many=True) + parent = serializers.HyperlinkedRelatedField( + read_only=True, + view_name='catalogue_api_book', + lookup_field='slug' + ) + + class Meta: + model = Book + fields = [ + 'slug', 'title', 'full_sort_key', + 'href', 'url', 'language', + 'authors', 'translators', + 'epochs', 'genres', 'kinds', + #'children', + 'parent', 'preview', + 'epub', 'mobi', 'pdf', 'html', 'txt', 'fb2', 'xml', + 'cover_thumb', 'cover', + 'isbn_pdf', 'isbn_epub', 'isbn_mobi', + ] + class BookSerializer(LegacyMixin, serializers.ModelSerializer): author = serializers.CharField(source='author_unicode') kind = serializers.CharField(source='kind_unicode')