|
|
|
@ -22,16 +22,38 @@ class BookAuthorV2Serializer(serializers.ModelSerializer): |
|
|
|
class BookResearcherV2Serializer(serializers.ModelSerializer): |
|
|
|
name = LocalizedField() |
|
|
|
author = BookAuthorV2Serializer(read_only=True) |
|
|
|
author_id = serializers.SerializerMethodField() |
|
|
|
slug = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
class Meta: |
|
|
|
model = BookResearcher |
|
|
|
fields = ['id', 'name', 'slug', 'author'] |
|
|
|
fields = ['id', 'name', 'slug', 'author', 'author_id'] |
|
|
|
|
|
|
|
def get_author_id(self, obj): |
|
|
|
return obj.author_id |
|
|
|
|
|
|
|
def get_slug(self, obj): |
|
|
|
if obj.author and obj.author.slug: |
|
|
|
return obj.author.slug |
|
|
|
return obj.slug |
|
|
|
|
|
|
|
class BookEditorV2Serializer(serializers.ModelSerializer): |
|
|
|
name = LocalizedField() |
|
|
|
author = BookAuthorV2Serializer(read_only=True) |
|
|
|
author_id = serializers.SerializerMethodField() |
|
|
|
slug = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
class Meta: |
|
|
|
model = BookEditor |
|
|
|
fields = ['id', 'name', 'slug', 'author'] |
|
|
|
fields = ['id', 'name', 'slug', 'author', 'author_id'] |
|
|
|
|
|
|
|
def get_author_id(self, obj): |
|
|
|
return obj.author_id |
|
|
|
|
|
|
|
def get_slug(self, obj): |
|
|
|
if obj.author and obj.author.slug: |
|
|
|
return obj.author.slug |
|
|
|
return obj.slug |
|
|
|
|
|
|
|
class BookReferenceV2ListSerializer(serializers.ModelSerializer): |
|
|
|
title = LocalizedField() |
|
|
|
@ -122,14 +144,14 @@ class BookReferenceV2DetailSerializer(serializers.ModelSerializer): |
|
|
|
title = LocalizedField() |
|
|
|
authors = serializers.SerializerMethodField() |
|
|
|
image = serializers.SerializerMethodField() |
|
|
|
tag = BookTagV2Serializer(read_only=True) |
|
|
|
|
|
|
|
information = serializers.SerializerMethodField() |
|
|
|
excerpts = serializers.SerializerMethodField() |
|
|
|
volumes = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
class Meta: |
|
|
|
model = BookReference |
|
|
|
fields = ['id', 'title', 'authors', 'image', 'information', 'excerpts', 'volumes'] |
|
|
|
fields = ['id', 'title', 'authors', 'image', 'tag', 'information', 'volumes'] |
|
|
|
|
|
|
|
def get_authors(self, obj): |
|
|
|
if obj.author: |
|
|
|
@ -157,33 +179,6 @@ class BookReferenceV2DetailSerializer(serializers.ModelSerializer): |
|
|
|
"editions": editions |
|
|
|
} |
|
|
|
|
|
|
|
def get_excerpts(self, obj): |
|
|
|
from apps.hadis.models import Hadis |
|
|
|
hadis_ids = obj.hadis_references.values_list('hadis', flat=True) |
|
|
|
hadis_qs = Hadis.objects.filter(id__in=hadis_ids, status=True).order_by('id') |
|
|
|
|
|
|
|
paginator = PageNumberPagination() |
|
|
|
paginator.page_size = 20 |
|
|
|
request = self.context.get("request") |
|
|
|
|
|
|
|
paginated_hadis = paginator.paginate_queryset(hadis_qs, request) if request else None |
|
|
|
|
|
|
|
if paginated_hadis is not None: |
|
|
|
serializer = HadisShortSerializer(paginated_hadis, many=True, context=self.context) |
|
|
|
return { |
|
|
|
'count': paginator.page.paginator.count, |
|
|
|
'next': paginator.get_next_link(), |
|
|
|
'previous': paginator.get_previous_link(), |
|
|
|
'results': serializer.data |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
'count': hadis_qs.count(), |
|
|
|
'next': None, |
|
|
|
'previous': None, |
|
|
|
'results': HadisShortSerializer(hadis_qs, many=True, context=self.context).data |
|
|
|
} |
|
|
|
|
|
|
|
def get_volumes(self, obj): |
|
|
|
if obj.has_editions: |
|
|
|
editions = obj.editions.all() |
|
|
|
@ -203,7 +198,7 @@ class BookReferenceV2DetailSerializer(serializers.ModelSerializer): |
|
|
|
return { |
|
|
|
"has_editions": False, |
|
|
|
"editions_volumes": [], |
|
|
|
"all_volumes": BookVolumeV2Serializer(obj.volumes.filter(edition__isnull=True), many=True, context=self.context).data |
|
|
|
"all_volumes": BookVolumeV2Serializer(obj.volumes.all(), many=True, context=self.context).data |
|
|
|
} |
|
|
|
|
|
|
|
class BookReferenceV2SyncSerializer(serializers.ModelSerializer): |
|
|
|
|