Browse Source

sync reference hadises fixed.

master
Mohsen Taba 5 months ago
parent
commit
ce5638389f
  1. 10
      apps/hadis/docs.py
  2. 14
      apps/hadis/serializers/hadis.py
  3. 32
      apps/hadis/serializers/reference.py

10
apps/hadis/docs.py

@ -57,13 +57,13 @@ hadis_category_tree_swagger = swagger_auto_schema(
operation_description=(
"Get complete hierarchical tree of Hadis categories grouped by sect type (shia/sunni). "
"Categories are not grouped by source_type in the response (mobile filters source_type client-side). "
"This sync endpoint returns only category metadata (no hadis payload) for fast offline building of navigation trees."
"This sync endpoint returns only category metadata (no hadis payload) for fast offline building of navigation trees. Includes sect information and full category tree with hadis counts and children counts."
),
operation_summary="Get Complete Hadis Category Tree",
tags=['Hadis'],
responses={
status.HTTP_200_OK: openapi.Response(
description="Complete hierarchical tree grouped by sect with only category metadata (no hadis payloads)",
description="Complete hierarchical tree grouped by sect with category metadata including hadis counts and children counts",
examples={
"application/json": {
"count": 6,
@ -87,7 +87,7 @@ hadis_category_tree_swagger = swagger_auto_schema(
"categories": [
{
"id": 10,
"name": "Tafsir",
"title": "Tafsir",
"description": "Quran commentary",
"slug": "-330",
"source_type": "quran",
@ -101,7 +101,7 @@ hadis_category_tree_swagger = swagger_auto_schema(
"children": [
{
"id": 11,
"name": "Surah Al-Fatiha",
"title": "Surah Al-Fatiha",
"description": "Opening chapter",
"slug": "-330",
"source_type": "quran",
@ -136,7 +136,7 @@ hadis_category_tree_swagger = swagger_auto_schema(
"categories": [
{
"id": 20,
"name": "Book of Faith",
"title": "Book of Faith",
"description": "Iman topics",
"slug": "-330",
"source_type": "hadith",

14
apps/hadis/serializers/hadis.py

@ -600,6 +600,20 @@ class HadisBasicSerializer(serializers.ModelSerializer):
}
return None
class HadisShortSerializer(serializers.ModelSerializer):
"""Basic serializer for Hadis with minimal information"""
translation = LocalizedField()
title = LocalizedField()
title_narrator = LocalizedField()
class Meta:
model = Hadis
fields = [
'id', 'slug', 'title', 'title_narrator', 'text',
'translation', 'share_link']
class HadisDetailSerializer(serializers.ModelSerializer):
"""Detailed serializer for Hadis with core information (transmitters and corrections moved to separate endpoints)"""

32
apps/hadis/serializers/reference.py

@ -2,8 +2,8 @@ from rest_framework import serializers
from django.utils.translation import get_language
from .category import get_localized_text
from ..serializers import HadisListSerializer,HadisBasicSerializer,LocalizedField
from ..models import BookReference , BookAuthor , BookReferenceImage, HadisReference , BookAttribute
from ..serializers import HadisBasicSerializer,LocalizedField, HadisShortSerializer
from ..models import BookReference , BookAuthor , BookReferenceImage , BookAttribute
class BookAuthorSerializer(serializers.ModelSerializer):
@ -163,27 +163,7 @@ class BookReferenceSyncSerializer(serializers.ModelSerializer):
'rating': obj.rate
}
def get_hadises(self, obj):
"""Get all hadises related to this book reference (already prefetched)"""
request = self.context.get('request')
hadis_list = []
# obj.hadis_references.all() is already prefetched!
for hadis_ref in obj.hadis_references.all():
hadis = hadis_ref.hadis # Already prefetched, no query!
# Handle get_translation - if it's a method, call it; if field, access it
translation = hadis.get_translation if callable(hadis.get_translation) else hadis.translation
if callable(translation):
translation = translation()
hadis_list.append({
'id': hadis.id,
'title': get_localized_text(hadis.title, request),
'title_narrator': get_localized_text(hadis.title_narrator, request),
'text': get_localized_text(hadis.text, request),
'translation': get_localized_text(translation, request),
'share_link': hadis.share_link
})
return hadis_list
def get_hadises(self,obj):
references = obj.hadis_references.all()
hadis_list = [ref.hadis for ref in references if ref.hadis]
return HadisShortSerializer(hadis_list,many=True).data
Loading…
Cancel
Save