|
|
|
@ -246,9 +246,10 @@ class HadisListSerializer(serializers.ModelSerializer): |
|
|
|
class HadisStatusSerializer(serializers.ModelSerializer): |
|
|
|
"""Serializer for HadisStatus""" |
|
|
|
title = LocalizedField() |
|
|
|
description = LocalizedField() |
|
|
|
class Meta: |
|
|
|
model = HadisStatus |
|
|
|
fields = ['id', 'title', 'color'] |
|
|
|
fields = ['id', 'title', 'color', 'description'] |
|
|
|
|
|
|
|
|
|
|
|
class HadisTagSerializer(serializers.ModelSerializer): |
|
|
|
@ -564,16 +565,26 @@ class HadisReferenceSerializer(serializers.ModelSerializer): |
|
|
|
'book_language', 'type_name', 'subject_area','book_authors' |
|
|
|
] |
|
|
|
|
|
|
|
def get_type_name(self,obj): |
|
|
|
return "Comperhensive Shia's Hadith Encyclopedia" |
|
|
|
|
|
|
|
def get_subject_area(self,obj): |
|
|
|
return ["Hadith", |
|
|
|
"Islamic History", |
|
|
|
"Theology", |
|
|
|
"Philosophy", |
|
|
|
"Tafsir" |
|
|
|
] |
|
|
|
def get_type_name(self, obj): |
|
|
|
"""Get localized type name from book_reference.type""" |
|
|
|
if obj.book_reference and obj.book_reference.type: |
|
|
|
field = LocalizedField() |
|
|
|
field._context = self.context |
|
|
|
return field.to_representation(obj.book_reference.type.title) |
|
|
|
return None |
|
|
|
|
|
|
|
def get_subject_area(self, obj): |
|
|
|
"""Get list of localized subject area names""" |
|
|
|
if obj.book_reference and obj.book_reference.subject_area.exists(): |
|
|
|
subject_areas = [] |
|
|
|
field = LocalizedField() |
|
|
|
field._context = self.context |
|
|
|
|
|
|
|
for subject in obj.book_reference.subject_area.all(): |
|
|
|
subject_areas.append(field.to_representation(subject.title)) |
|
|
|
|
|
|
|
return subject_areas |
|
|
|
return [] |
|
|
|
|
|
|
|
def get_book_english_name(self,obj): |
|
|
|
english_name_data = obj.book_reference.title |
|
|
|
@ -611,13 +622,36 @@ class HadisReferenceSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
# 3. Loop through authors and convert each object to a string (name) |
|
|
|
# Result will be like: ["Al-Bukhari", "Muslim"] |
|
|
|
out =[] |
|
|
|
out = [] |
|
|
|
for author in authors: |
|
|
|
name = field.to_representation(author.name) |
|
|
|
|
|
|
|
# Format birth and death dates (Hijri/CE) |
|
|
|
birth_hijri = author.birth_year_hijri |
|
|
|
birth_miladi = author.birth_year_miladi |
|
|
|
death_hijri = author.death_year_hijri |
|
|
|
death_miladi = author.death_year_miladi |
|
|
|
|
|
|
|
birth_str = "" |
|
|
|
if birth_hijri and birth_miladi: |
|
|
|
birth_str = f"{birth_hijri}AH/{birth_miladi}CE" |
|
|
|
elif birth_hijri: |
|
|
|
birth_str = f"{birth_hijri}AH" |
|
|
|
elif birth_miladi: |
|
|
|
birth_str = f"{birth_miladi}CE" |
|
|
|
|
|
|
|
death_str = "" |
|
|
|
if death_hijri and death_miladi: |
|
|
|
death_str = f"{death_hijri}AH/{death_miladi}CE" |
|
|
|
elif death_hijri: |
|
|
|
death_str = f"{death_hijri}AH" |
|
|
|
elif death_miladi: |
|
|
|
death_str = f"{death_miladi}CE" |
|
|
|
|
|
|
|
out.append({ |
|
|
|
'name': name, |
|
|
|
'birth': '1037AH/1627CE', |
|
|
|
'death': '1105AH/1694CE', |
|
|
|
'birth': birth_str, |
|
|
|
'death': death_str, |
|
|
|
}) |
|
|
|
|
|
|
|
return out |
|
|
|
@ -731,7 +765,6 @@ class HadisShortSerializer(serializers.ModelSerializer): |
|
|
|
class HadisDetailSerializer(serializers.ModelSerializer): |
|
|
|
"""Detailed serializer for Hadis with core information (transmitters and corrections moved to separate endpoints)""" |
|
|
|
hadis_status = HadisStatusSerializer(read_only=True) |
|
|
|
hadis_status_text = LocalizedField() |
|
|
|
tags = HadisTagSerializer(many=True, read_only=True) |
|
|
|
references = HadisReferenceSerializer( |
|
|
|
many=True, |
|
|
|
@ -744,7 +777,7 @@ class HadisDetailSerializer(serializers.ModelSerializer): |
|
|
|
class Meta: |
|
|
|
model = Hadis |
|
|
|
fields = [ |
|
|
|
'id', 'number', 'slug','hadis_status','hadis_status_text', 'links','share_link', |
|
|
|
'id', 'number', 'slug','hadis_status','links','share_link', |
|
|
|
'tags','references','reference_images','address' |
|
|
|
] |
|
|
|
|
|
|
|
|