|
|
|
@ -244,6 +244,7 @@ class HadisSyncSerializer(serializers.ModelSerializer): |
|
|
|
'slug': t.reliability.slug, |
|
|
|
'color': t.reliability.color, |
|
|
|
'main_color_code': t.reliability.main_color_code, |
|
|
|
'description': get_localized_text(t.reliability.description, request), |
|
|
|
} |
|
|
|
|
|
|
|
uncertain_list = [] |
|
|
|
@ -257,6 +258,7 @@ class HadisSyncSerializer(serializers.ModelSerializer): |
|
|
|
'slug': ut.reliability.slug, |
|
|
|
'color': ut.reliability.color, |
|
|
|
'main_color_code': ut.reliability.main_color_code, |
|
|
|
'description': get_localized_text(ut.reliability.description, request), |
|
|
|
} |
|
|
|
uncertain_list.append({ |
|
|
|
'id': ut.id, |
|
|
|
@ -476,6 +478,8 @@ class TransmitterSerializer(serializers.ModelSerializer): |
|
|
|
"""Serializer for Transmitters""" |
|
|
|
full_name = LocalizedField() |
|
|
|
arabic_full_name = ArabicLocalizedField(source='full_name') |
|
|
|
kunya = LocalizedField() |
|
|
|
arabic_kunya = ArabicLocalizedField(source='kunya') |
|
|
|
known_as = LocalizedField() |
|
|
|
arabic_known_as = ArabicLocalizedField(source='known_as') |
|
|
|
nickname = LocalizedField() |
|
|
|
@ -495,7 +499,7 @@ class TransmitterSerializer(serializers.ModelSerializer): |
|
|
|
'id', 'full_name', 'arabic_full_name', 'slug', |
|
|
|
'birth_year_hijri', 'death_year_hijri', 'age_at_death', |
|
|
|
'birth_year_raw', 'death_year_raw', 'age_at_death_raw', |
|
|
|
'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', |
|
|
|
'kunya', 'arabic_kunya', 'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', |
|
|
|
'reliability', 'madhhab', 'generation', 'share_link', 'gender' |
|
|
|
] |
|
|
|
|
|
|
|
@ -526,6 +530,8 @@ class TransmitterShortSerializer(serializers.ModelSerializer): |
|
|
|
"""Serializer for Transmitters""" |
|
|
|
full_name = LocalizedField() |
|
|
|
arabic_full_name = ArabicLocalizedField(source='full_name') |
|
|
|
kunya = LocalizedField() |
|
|
|
arabic_kunya = ArabicLocalizedField(source='kunya') |
|
|
|
known_as = LocalizedField() |
|
|
|
arabic_known_as = ArabicLocalizedField(source='known_as') |
|
|
|
nickname = LocalizedField() |
|
|
|
@ -541,7 +547,7 @@ class TransmitterShortSerializer(serializers.ModelSerializer): |
|
|
|
fields = [ |
|
|
|
'id', 'full_name', 'arabic_full_name', 'slug', |
|
|
|
'birth_year_hijri', 'death_year_hijri', 'birth_year_raw', 'death_year_raw', |
|
|
|
'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', 'reliability', 'gender' |
|
|
|
'kunya', 'arabic_kunya', 'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', 'reliability', 'gender' |
|
|
|
] |
|
|
|
|
|
|
|
def get_birth_year_hijri(self, obj): |
|
|
|
@ -691,6 +697,105 @@ class TransmitterOriginalTextSerializer(serializers.ModelSerializer): |
|
|
|
return images_list |
|
|
|
|
|
|
|
|
|
|
|
def _serialize_transmitter_m2m_items(items, request, include_description=False): |
|
|
|
result = [] |
|
|
|
for item in items: |
|
|
|
entry = { |
|
|
|
'id': item.id, |
|
|
|
'slug': getattr(item, 'slug', None), |
|
|
|
'title': get_localized_text(item.title, request), |
|
|
|
'arabic_title': get_arabic_localized_text(item.title), |
|
|
|
} |
|
|
|
if include_description: |
|
|
|
entry['description'] = get_localized_text(getattr(item, 'description', None), request) |
|
|
|
result.append(entry) |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
def _resolve_transmitter_m2m_text(items, fallback_json, request, arabic=False, secondary_fallback_json=None): |
|
|
|
parts = [] |
|
|
|
for item in items: |
|
|
|
txt = get_arabic_localized_text(item.title) if arabic else get_localized_text(item.title, request) |
|
|
|
if txt and str(txt).strip(): |
|
|
|
parts.append(str(txt).strip()) |
|
|
|
if parts: |
|
|
|
sep = '، ' if arabic else ', ' |
|
|
|
return sep.join(parts) |
|
|
|
if fallback_json: |
|
|
|
val = get_arabic_localized_text(fallback_json) if arabic else get_localized_text(fallback_json, request) |
|
|
|
if val: |
|
|
|
return val |
|
|
|
if secondary_fallback_json: |
|
|
|
val = get_arabic_localized_text(secondary_fallback_json) if arabic else get_localized_text(secondary_fallback_json, request) |
|
|
|
if val: |
|
|
|
return val |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def _resolve_transmitter_city_text(city_obj, fallback_json, request, arabic=False): |
|
|
|
if city_obj and getattr(city_obj, 'title', None): |
|
|
|
val = get_arabic_localized_text(city_obj.title) if arabic else get_localized_text(city_obj.title, request) |
|
|
|
if val: |
|
|
|
return val |
|
|
|
if fallback_json: |
|
|
|
return get_arabic_localized_text(fallback_json) if arabic else get_localized_text(fallback_json, request) |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def _serialize_transmitter_relatives(obj, request): |
|
|
|
from django.db.models import Q |
|
|
|
from ..models.transmitter import RelationType |
|
|
|
|
|
|
|
relatives_qs = obj.relatives.select_related('relation_type_ref', 'narrator').all() |
|
|
|
|
|
|
|
grouped = {} |
|
|
|
for rel in relatives_qs: |
|
|
|
rt_obj = rel.relation_type_ref |
|
|
|
if not rt_obj and rel.relation_type: |
|
|
|
rt_obj = RelationType.objects.filter( |
|
|
|
Q(code__iexact=rel.relation_type) | Q(slug__iexact=rel.relation_type) |
|
|
|
).first() |
|
|
|
|
|
|
|
rel_type = (rt_obj.code or rt_obj.slug or rel.relation_type) if rt_obj else rel.relation_type |
|
|
|
rel_val_src = (rt_obj.title if (rt_obj and rt_obj.title) else rel.relation_value) |
|
|
|
slug = rel.narrator.slug if rel.narrator else None |
|
|
|
|
|
|
|
name = rel.name |
|
|
|
if rel.narrator and not name: |
|
|
|
name = get_localized_text(rel.narrator.full_name, request) |
|
|
|
arabic_name = ( |
|
|
|
get_arabic_localized_text(rel.narrator.full_name) |
|
|
|
if rel.narrator |
|
|
|
else rel.name |
|
|
|
) or name |
|
|
|
|
|
|
|
item = { |
|
|
|
"id": rel.narrator_id, |
|
|
|
"name": name, |
|
|
|
"arabic_name": arabic_name, |
|
|
|
"slug": slug, |
|
|
|
} |
|
|
|
|
|
|
|
if rel_type not in grouped: |
|
|
|
grouped[rel_type] = { |
|
|
|
"relation_value": get_localized_text(rel_val_src, request) if rel_val_src else None, |
|
|
|
"arabic_relation_value": get_arabic_localized_text(rel_val_src) if rel_val_src else None, |
|
|
|
"items": [] |
|
|
|
} |
|
|
|
grouped[rel_type]["items"].append(item) |
|
|
|
|
|
|
|
result = [] |
|
|
|
for rel_type, data in grouped.items(): |
|
|
|
result.append({ |
|
|
|
"relation_type": rel_type, |
|
|
|
"relation_value": data["relation_value"], |
|
|
|
"arabic_relation_value": data["arabic_relation_value"], |
|
|
|
"members": data["items"] |
|
|
|
}) |
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
class TransmitterDetailSerializer(serializers.ModelSerializer): |
|
|
|
""" Serializer for Details of Transmitters """ |
|
|
|
|
|
|
|
@ -700,23 +805,31 @@ class TransmitterDetailSerializer(serializers.ModelSerializer): |
|
|
|
arabic_known_as = ArabicLocalizedField(source='known_as') |
|
|
|
nickname = LocalizedField() |
|
|
|
arabic_nickname = ArabicLocalizedField(source='nickname') |
|
|
|
kunya = LocalizedField() |
|
|
|
arabic_kunya = ArabicLocalizedField(source='kunya') |
|
|
|
origin = LocalizedField() |
|
|
|
arabic_origin = ArabicLocalizedField(source='origin') |
|
|
|
kunya = serializers.SerializerMethodField() |
|
|
|
arabic_kunya = serializers.SerializerMethodField() |
|
|
|
kunyas = serializers.SerializerMethodField() |
|
|
|
origin = serializers.SerializerMethodField() |
|
|
|
arabic_origin = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
mawla_status = LocalizedField(source='freed_slave_of') |
|
|
|
arabic_mawla_status = ArabicLocalizedField(source='freed_slave_of') |
|
|
|
profession = LocalizedField(source='occupation') |
|
|
|
arabic_profession = ArabicLocalizedField(source='occupation') |
|
|
|
physical_traits = LocalizedField(source='features') |
|
|
|
arabic_physical_traits = ArabicLocalizedField(source='features') |
|
|
|
|
|
|
|
lived_in = LocalizedField() |
|
|
|
died_in = LocalizedField() |
|
|
|
profession = serializers.SerializerMethodField() |
|
|
|
arabic_profession = serializers.SerializerMethodField() |
|
|
|
professions = serializers.SerializerMethodField() |
|
|
|
physical_traits = serializers.SerializerMethodField() |
|
|
|
arabic_physical_traits = serializers.SerializerMethodField() |
|
|
|
features = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
lived_in = serializers.SerializerMethodField() |
|
|
|
arabic_lived_in = serializers.SerializerMethodField() |
|
|
|
died_in = serializers.SerializerMethodField() |
|
|
|
arabic_died_in = serializers.SerializerMethodField() |
|
|
|
description = LocalizedField() |
|
|
|
companion_type = LocalizedField() |
|
|
|
arabic_companion_type = ArabicLocalizedField(source='companion_type') |
|
|
|
companion_type = serializers.SerializerMethodField() |
|
|
|
arabic_companion_type = serializers.SerializerMethodField() |
|
|
|
sahabi_status = serializers.SerializerMethodField() |
|
|
|
madhhab = serializers.SerializerMethodField() |
|
|
|
madhhabs = serializers.SerializerMethodField() |
|
|
|
birth_year_hijri = serializers.SerializerMethodField() |
|
|
|
death_year_hijri = serializers.SerializerMethodField() |
|
|
|
age_at_death = serializers.SerializerMethodField() |
|
|
|
@ -732,18 +845,111 @@ class TransmitterDetailSerializer(serializers.ModelSerializer): |
|
|
|
class Meta: |
|
|
|
model = Transmitters |
|
|
|
fields = [ |
|
|
|
'id','full_name', 'arabic_full_name', 'kunya', 'arabic_kunya', 'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', |
|
|
|
'origin', 'arabic_origin', 'mawla_status', 'arabic_mawla_status', 'profession', 'arabic_profession', 'physical_traits', 'arabic_physical_traits', |
|
|
|
'lived_in','died_in','birth_year_hijri', |
|
|
|
'death_year_hijri','age_at_death', |
|
|
|
'id', 'full_name', 'arabic_full_name', 'kunya', 'arabic_kunya', 'kunyas', |
|
|
|
'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', |
|
|
|
'origin', 'arabic_origin', 'mawla_status', 'arabic_mawla_status', |
|
|
|
'profession', 'arabic_profession', 'professions', |
|
|
|
'physical_traits', 'arabic_physical_traits', 'features', |
|
|
|
'lived_in', 'arabic_lived_in', 'died_in', 'arabic_died_in', |
|
|
|
'birth_year_hijri', 'death_year_hijri', 'age_at_death', |
|
|
|
'birth_year_raw', 'death_year_raw', 'age_at_death_raw', |
|
|
|
'reliability', |
|
|
|
'madhhab',"in_sahih_muslim","in_sahih_bukhari", |
|
|
|
"description",'generation','share_link', |
|
|
|
'tadlis', 'ikhtilat', 'companion_type', 'arabic_companion_type', 'relatives', |
|
|
|
'madhhab', 'madhhabs', "in_sahih_muslim", "in_sahih_bukhari", |
|
|
|
"description", 'generation', 'share_link', |
|
|
|
'tadlis', 'ikhtilat', 'companion_type', 'arabic_companion_type', 'sahabi_status', 'relatives', |
|
|
|
'father', 'sons', 'gender' |
|
|
|
] |
|
|
|
|
|
|
|
def get_kunya(self, obj): |
|
|
|
return _resolve_transmitter_m2m_text(obj.kunyas.all(), obj.kunya, self.context.get('request'), arabic=False) |
|
|
|
|
|
|
|
def get_arabic_kunya(self, obj): |
|
|
|
return _resolve_transmitter_m2m_text(obj.kunyas.all(), obj.kunya, self.context.get('request'), arabic=True) |
|
|
|
|
|
|
|
def get_kunyas(self, obj): |
|
|
|
return _serialize_transmitter_m2m_items(obj.kunyas.all(), self.context.get('request')) |
|
|
|
|
|
|
|
def get_profession(self, obj): |
|
|
|
return _resolve_transmitter_m2m_text( |
|
|
|
obj.professions_list.all(), obj.profession, self.context.get('request'), |
|
|
|
arabic=False, secondary_fallback_json=obj.occupation |
|
|
|
) |
|
|
|
|
|
|
|
def get_arabic_profession(self, obj): |
|
|
|
return _resolve_transmitter_m2m_text( |
|
|
|
obj.professions_list.all(), obj.profession, self.context.get('request'), |
|
|
|
arabic=True, secondary_fallback_json=obj.occupation |
|
|
|
) |
|
|
|
|
|
|
|
def get_professions(self, obj): |
|
|
|
return _serialize_transmitter_m2m_items(obj.professions_list.all(), self.context.get('request')) |
|
|
|
|
|
|
|
def get_physical_traits(self, obj): |
|
|
|
return _resolve_transmitter_m2m_text(obj.features_list.all(), obj.features, self.context.get('request'), arabic=False) |
|
|
|
|
|
|
|
def get_arabic_physical_traits(self, obj): |
|
|
|
return _resolve_transmitter_m2m_text(obj.features_list.all(), obj.features, self.context.get('request'), arabic=True) |
|
|
|
|
|
|
|
def get_features(self, obj): |
|
|
|
return _serialize_transmitter_m2m_items(obj.features_list.all(), self.context.get('request')) |
|
|
|
|
|
|
|
def get_origin(self, obj): |
|
|
|
return _resolve_transmitter_city_text(obj.origin_city, obj.origin, self.context.get('request'), arabic=False) |
|
|
|
|
|
|
|
def get_arabic_origin(self, obj): |
|
|
|
return _resolve_transmitter_city_text(obj.origin_city, obj.origin, self.context.get('request'), arabic=True) |
|
|
|
|
|
|
|
def get_lived_in(self, obj): |
|
|
|
return _resolve_transmitter_city_text(obj.lived_in_city, obj.lived_in, self.context.get('request'), arabic=False) |
|
|
|
|
|
|
|
def get_arabic_lived_in(self, obj): |
|
|
|
return _resolve_transmitter_city_text(obj.lived_in_city, obj.lived_in, self.context.get('request'), arabic=True) |
|
|
|
|
|
|
|
def get_died_in(self, obj): |
|
|
|
return _resolve_transmitter_city_text(obj.died_in_city, obj.died_in, self.context.get('request'), arabic=False) |
|
|
|
|
|
|
|
def get_arabic_died_in(self, obj): |
|
|
|
return _resolve_transmitter_city_text(obj.died_in_city, obj.died_in, self.context.get('request'), arabic=True) |
|
|
|
|
|
|
|
def get_companion_type(self, obj): |
|
|
|
request = self.context.get('request') |
|
|
|
if obj.sahabi_status and obj.sahabi_status.title: |
|
|
|
val = get_localized_text(obj.sahabi_status.title, request) |
|
|
|
if val: |
|
|
|
return val |
|
|
|
return get_localized_text(obj.companion_type, request) |
|
|
|
|
|
|
|
def get_arabic_companion_type(self, obj): |
|
|
|
if obj.sahabi_status and obj.sahabi_status.title: |
|
|
|
val = get_arabic_localized_text(obj.sahabi_status.title) |
|
|
|
if val: |
|
|
|
return val |
|
|
|
return get_arabic_localized_text(obj.companion_type) |
|
|
|
|
|
|
|
def get_sahabi_status(self, obj): |
|
|
|
if obj.sahabi_status: |
|
|
|
request = self.context.get('request') |
|
|
|
return { |
|
|
|
'id': obj.sahabi_status.id, |
|
|
|
'slug': obj.sahabi_status.slug, |
|
|
|
'title': get_localized_text(obj.sahabi_status.title, request), |
|
|
|
'arabic_title': get_arabic_localized_text(obj.sahabi_status.title), |
|
|
|
'description': get_localized_text(obj.sahabi_status.description, request), |
|
|
|
} |
|
|
|
return None |
|
|
|
|
|
|
|
def get_madhhab(self, obj): |
|
|
|
if obj.madhhab: |
|
|
|
return obj.madhhab |
|
|
|
request = self.context.get('request') |
|
|
|
m_items = list(obj.madhhabs.all()) |
|
|
|
if m_items: |
|
|
|
return get_localized_text(m_items[0].title, request) or m_items[0].slug |
|
|
|
return None |
|
|
|
|
|
|
|
def get_madhhabs(self, obj): |
|
|
|
return _serialize_transmitter_m2m_items(obj.madhhabs.all(), self.context.get('request'), include_description=True) |
|
|
|
|
|
|
|
def get_birth_year_hijri(self, obj): |
|
|
|
return format_transmitter_date(obj, 'birth', self.context.get('request')) |
|
|
|
|
|
|
|
@ -827,43 +1033,7 @@ class TransmitterDetailSerializer(serializers.ModelSerializer): |
|
|
|
return None |
|
|
|
|
|
|
|
def get_relatives(self, obj): |
|
|
|
request = self.context.get('request') |
|
|
|
relatives_qs = obj.relatives.select_related('relation_type_ref', 'narrator').all() |
|
|
|
|
|
|
|
grouped = {} |
|
|
|
for rel in relatives_qs: |
|
|
|
rel_type = (rel.relation_type_ref.code or rel.relation_type_ref.slug or rel.relation_type) if rel.relation_type_ref else rel.relation_type |
|
|
|
rel_val_src = (rel.relation_type_ref.title if (rel.relation_type_ref and rel.relation_type_ref.title) else rel.relation_value) |
|
|
|
slug = rel.narrator.slug if rel.narrator else None |
|
|
|
|
|
|
|
# Use narrator's localized name if exists and name is empty, otherwise use the direct name |
|
|
|
name = rel.name |
|
|
|
if rel.narrator and not name: |
|
|
|
name = get_localized_text(rel.narrator.full_name, request) |
|
|
|
|
|
|
|
item = { |
|
|
|
"name": name, |
|
|
|
"slug": slug |
|
|
|
} |
|
|
|
|
|
|
|
if rel_type not in grouped: |
|
|
|
grouped[rel_type] = { |
|
|
|
"relation_value": get_localized_text(rel_val_src, request) if rel_val_src else None, |
|
|
|
"arabic_relation_value": get_arabic_localized_text(rel_val_src) if rel_val_src else None, |
|
|
|
"items": [] |
|
|
|
} |
|
|
|
grouped[rel_type]["items"].append(item) |
|
|
|
|
|
|
|
result = [] |
|
|
|
for rel_type, data in grouped.items(): |
|
|
|
result.append({ |
|
|
|
"relation_type": rel_type, |
|
|
|
"relation_value": data["relation_value"], |
|
|
|
"arabic_relation_value": data["arabic_relation_value"], |
|
|
|
"members": data["items"] |
|
|
|
}) |
|
|
|
|
|
|
|
return result |
|
|
|
return _serialize_transmitter_relatives(obj, self.context.get('request')) |
|
|
|
|
|
|
|
|
|
|
|
class TransmittersFiltersSerializer(serializers.ModelSerializer): |
|
|
|
@ -890,36 +1060,68 @@ class TransmitterSyncSerializer(serializers.ModelSerializer): |
|
|
|
"""Get biographical information (flattened)""" |
|
|
|
request = self.context.get('request') # ← FIX: Define request |
|
|
|
if obj.reliability: |
|
|
|
r= { |
|
|
|
r = { |
|
|
|
'id': obj.reliability.id, |
|
|
|
'title': get_localized_text(obj.reliability.title, request), |
|
|
|
'slug': obj.reliability.slug, |
|
|
|
'color': obj.reliability.color, |
|
|
|
'main_color_code': obj.reliability.main_color_code, |
|
|
|
'description': get_localized_text(obj.reliability.description, request), |
|
|
|
} |
|
|
|
else : |
|
|
|
r= None |
|
|
|
else: |
|
|
|
r = None |
|
|
|
|
|
|
|
sahabi_status_data = None |
|
|
|
if obj.sahabi_status: |
|
|
|
sahabi_status_data = { |
|
|
|
'id': obj.sahabi_status.id, |
|
|
|
'slug': obj.sahabi_status.slug, |
|
|
|
'title': get_localized_text(obj.sahabi_status.title, request), |
|
|
|
'arabic_title': get_arabic_localized_text(obj.sahabi_status.title), |
|
|
|
'description': get_localized_text(obj.sahabi_status.description, request), |
|
|
|
} |
|
|
|
|
|
|
|
companion_val = ( |
|
|
|
get_localized_text(obj.sahabi_status.title, request) |
|
|
|
if (obj.sahabi_status and obj.sahabi_status.title) |
|
|
|
else get_localized_text(obj.companion_type, request) |
|
|
|
) |
|
|
|
arabic_companion_val = ( |
|
|
|
get_arabic_localized_text(obj.sahabi_status.title) |
|
|
|
if (obj.sahabi_status and obj.sahabi_status.title) |
|
|
|
else get_arabic_localized_text(obj.companion_type) |
|
|
|
) |
|
|
|
|
|
|
|
madhhab_val = obj.madhhab |
|
|
|
madhhabs_objs = list(obj.madhhabs.all()) |
|
|
|
if not madhhab_val and madhhabs_objs: |
|
|
|
madhhab_val = get_localized_text(madhhabs_objs[0].title, request) or madhhabs_objs[0].slug |
|
|
|
|
|
|
|
return { |
|
|
|
'full_name': get_localized_text(obj.full_name, request), |
|
|
|
'arabic_full_name': get_arabic_localized_text(obj.full_name), |
|
|
|
'gender': obj.gender, |
|
|
|
'kunya': get_localized_text(obj.kunya, request), |
|
|
|
'arabic_kunya': get_arabic_localized_text(obj.kunya), |
|
|
|
'kunya': _resolve_transmitter_m2m_text(obj.kunyas.all(), obj.kunya, request, arabic=False), |
|
|
|
'arabic_kunya': _resolve_transmitter_m2m_text(obj.kunyas.all(), obj.kunya, request, arabic=True), |
|
|
|
'kunyas': _serialize_transmitter_m2m_items(obj.kunyas.all(), request), |
|
|
|
'known_as': get_localized_text(obj.known_as, request), |
|
|
|
'arabic_known_as': get_arabic_localized_text(obj.known_as), |
|
|
|
'nickname': get_localized_text(obj.nickname, request), |
|
|
|
'arabic_nickname': get_arabic_localized_text(obj.nickname), |
|
|
|
'origin': get_localized_text(obj.origin, request), |
|
|
|
'arabic_origin': get_arabic_localized_text(obj.origin), |
|
|
|
'origin': _resolve_transmitter_city_text(obj.origin_city, obj.origin, request, arabic=False), |
|
|
|
'arabic_origin': _resolve_transmitter_city_text(obj.origin_city, obj.origin, request, arabic=True), |
|
|
|
'mawla_status': get_localized_text(obj.freed_slave_of, request), |
|
|
|
'arabic_mawla_status': get_arabic_localized_text(obj.freed_slave_of), |
|
|
|
'profession': get_localized_text(obj.occupation, request), |
|
|
|
'arabic_profession': get_arabic_localized_text(obj.occupation), |
|
|
|
'physical_traits': get_localized_text(obj.features, request), |
|
|
|
'arabic_physical_traits': get_arabic_localized_text(obj.features), |
|
|
|
'lived_in': get_localized_text(obj.lived_in, request), |
|
|
|
'died_in': get_localized_text(obj.died_in, request), |
|
|
|
'profession': _resolve_transmitter_m2m_text(obj.professions_list.all(), obj.profession, request, arabic=False, secondary_fallback_json=obj.occupation), |
|
|
|
'arabic_profession': _resolve_transmitter_m2m_text(obj.professions_list.all(), obj.profession, request, arabic=True, secondary_fallback_json=obj.occupation), |
|
|
|
'professions': _serialize_transmitter_m2m_items(obj.professions_list.all(), request), |
|
|
|
'physical_traits': _resolve_transmitter_m2m_text(obj.features_list.all(), obj.features, request, arabic=False), |
|
|
|
'arabic_physical_traits': _resolve_transmitter_m2m_text(obj.features_list.all(), obj.features, request, arabic=True), |
|
|
|
'features': _serialize_transmitter_m2m_items(obj.features_list.all(), request), |
|
|
|
'lived_in': _resolve_transmitter_city_text(obj.lived_in_city, obj.lived_in, request, arabic=False), |
|
|
|
'arabic_lived_in': _resolve_transmitter_city_text(obj.lived_in_city, obj.lived_in, request, arabic=True), |
|
|
|
'died_in': _resolve_transmitter_city_text(obj.died_in_city, obj.died_in, request, arabic=False), |
|
|
|
'arabic_died_in': _resolve_transmitter_city_text(obj.died_in_city, obj.died_in, request, arabic=True), |
|
|
|
'birth_year_hijri': format_transmitter_date(obj, 'birth', request), |
|
|
|
'death_year_hijri': format_transmitter_date(obj, 'death', request), |
|
|
|
'age_at_death': format_transmitter_date(obj, 'age', request), |
|
|
|
@ -928,7 +1130,8 @@ class TransmitterSyncSerializer(serializers.ModelSerializer): |
|
|
|
'age_at_death_raw': obj.age_at_death, |
|
|
|
'generation': obj.generation, |
|
|
|
'reliability': r, |
|
|
|
'madhhab': obj.madhhab, |
|
|
|
'madhhab': madhhab_val, |
|
|
|
'madhhabs': _serialize_transmitter_m2m_items(madhhabs_objs, request, include_description=True), |
|
|
|
'in_sahih_muslim': obj.in_sahih_muslim, |
|
|
|
'in_sahih_bukhari': obj.in_sahih_bukhari, |
|
|
|
'description': get_localized_text(obj.description, request), |
|
|
|
@ -936,47 +1139,14 @@ class TransmitterSyncSerializer(serializers.ModelSerializer): |
|
|
|
'share_link': obj.share_link, |
|
|
|
'tadlis': obj.tadlis, |
|
|
|
'ikhtilat': obj.ikhtilat, |
|
|
|
'companion_type': get_localized_text(obj.companion_type, request), |
|
|
|
'arabic_companion_type': get_arabic_localized_text(obj.companion_type), |
|
|
|
'companion_type': companion_val, |
|
|
|
'arabic_companion_type': arabic_companion_val, |
|
|
|
'sahabi_status': sahabi_status_data, |
|
|
|
'relatives': self._get_relatives(obj, request), |
|
|
|
} |
|
|
|
|
|
|
|
def _get_relatives(self, obj, request): |
|
|
|
relatives_qs = obj.relatives.select_related('relation_type_ref', 'narrator').all() |
|
|
|
|
|
|
|
grouped = {} |
|
|
|
for rel in relatives_qs: |
|
|
|
rel_type = (rel.relation_type_ref.code or rel.relation_type_ref.slug or rel.relation_type) if rel.relation_type_ref else rel.relation_type |
|
|
|
rel_val_src = (rel.relation_type_ref.title if (rel.relation_type_ref and rel.relation_type_ref.title) else rel.relation_value) |
|
|
|
slug = rel.narrator.slug if rel.narrator else None |
|
|
|
|
|
|
|
name = rel.name |
|
|
|
if rel.narrator and not name: |
|
|
|
name = get_localized_text(rel.narrator.full_name, request) |
|
|
|
|
|
|
|
item = { |
|
|
|
"name": name, |
|
|
|
"slug": slug |
|
|
|
} |
|
|
|
|
|
|
|
if rel_type not in grouped: |
|
|
|
grouped[rel_type] = { |
|
|
|
"relation_value": get_localized_text(rel_val_src, request) if rel_val_src else None, |
|
|
|
"arabic_relation_value": get_arabic_localized_text(rel_val_src) if rel_val_src else None, |
|
|
|
"items": [] |
|
|
|
} |
|
|
|
grouped[rel_type]["items"].append(item) |
|
|
|
|
|
|
|
result = [] |
|
|
|
for rel_type, data in grouped.items(): |
|
|
|
result.append({ |
|
|
|
"relation_type": rel_type, |
|
|
|
"relation_value": data["relation_value"], |
|
|
|
"arabic_relation_value": data["arabic_relation_value"], |
|
|
|
"members": data["items"] |
|
|
|
}) |
|
|
|
|
|
|
|
return result |
|
|
|
return _serialize_transmitter_relatives(obj, request) |
|
|
|
|
|
|
|
def get_scholars_opinions(self, obj): |
|
|
|
"""Get all scholarly opinions about this transmitter""" |
|
|
|
@ -1172,11 +1342,12 @@ class HadisReferenceSerializer(serializers.ModelSerializer): |
|
|
|
edition = obj.book_reference.editions.first() |
|
|
|
if edition: |
|
|
|
request = self.context.get("request") |
|
|
|
pub = edition.publisher |
|
|
|
if isinstance(pub, list): |
|
|
|
pub = get_localized_text(pub, request) |
|
|
|
pub_src = edition.publisher_item.title if (getattr(edition, "publisher_item_id", None) and edition.publisher_item and edition.publisher_item.title) else edition.publisher |
|
|
|
pub = get_localized_text(pub_src, request) if isinstance(pub_src, list) else pub_src |
|
|
|
ed_title = get_localized_text(edition.title, request) if isinstance(getattr(edition, "title", None), list) else getattr(edition, "title", None) |
|
|
|
return { |
|
|
|
"id": edition.id, |
|
|
|
"title": ed_title or "", |
|
|
|
"edition_number": edition.edition_number, |
|
|
|
"publisher": pub or "", |
|
|
|
"year_of_publication": edition.year_of_publication or "", |
|
|
|
@ -1254,7 +1425,7 @@ class HadisReferenceSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
pub = getattr(obj.book_reference, "publisher", None) |
|
|
|
if pub is None and first_ed: |
|
|
|
pub = first_ed.publisher |
|
|
|
pub = first_ed.publisher_item.title if (getattr(first_ed, "publisher_item_id", None) and first_ed.publisher_item and first_ed.publisher_item.title) else first_ed.publisher |
|
|
|
if isinstance(pub, list): |
|
|
|
pub = get_localized_text(pub, request) |
|
|
|
|
|
|
|
@ -1350,28 +1521,29 @@ class HadisReferenceSerializer(serializers.ModelSerializer): |
|
|
|
# 3. Loop through authors and convert each object to a string (name) |
|
|
|
# Result will be like: ["Al-Bukhari", "Muslim"] |
|
|
|
out = [] |
|
|
|
lang = _extract_request_lang(self.context.get('request')) |
|
|
|
for author in authors: |
|
|
|
name = field.to_representation(author.name) |
|
|
|
|
|
|
|
# Format birth and death dates (Hijri/CE) |
|
|
|
birth_hijri = author.birth_year_hijri |
|
|
|
birth_hijri = author.get_formatted_birth_year(lang=lang) if hasattr(author, 'get_formatted_birth_year') else author.birth_year_hijri |
|
|
|
birth_miladi = author.birth_year_miladi |
|
|
|
death_hijri = author.death_year_hijri |
|
|
|
death_hijri = author.get_formatted_death_year(lang=lang) if hasattr(author, 'get_formatted_death_year') else 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" |
|
|
|
birth_str = f"{birth_hijri} / {birth_miladi}CE" |
|
|
|
elif birth_hijri: |
|
|
|
birth_str = f"{birth_hijri}AH" |
|
|
|
birth_str = f"{birth_hijri}" |
|
|
|
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" |
|
|
|
death_str = f"{death_hijri} / {death_miladi}CE" |
|
|
|
elif death_hijri: |
|
|
|
death_str = f"{death_hijri}AH" |
|
|
|
death_str = f"{death_hijri}" |
|
|
|
elif death_miladi: |
|
|
|
death_str = f"{death_miladi}CE" |
|
|
|
|
|
|
|
@ -1624,7 +1796,13 @@ class NarratorRelationSerializer(serializers.ModelSerializer): |
|
|
|
سریالایزر سبک برای نمایش راویان به عنوان استاد یا شاگرد |
|
|
|
""" |
|
|
|
full_name = LocalizedField() |
|
|
|
arabic_full_name = ArabicLocalizedField(source='full_name') |
|
|
|
kunya = LocalizedField() |
|
|
|
arabic_kunya = ArabicLocalizedField(source='kunya') |
|
|
|
known_as = LocalizedField() |
|
|
|
arabic_known_as = ArabicLocalizedField(source='known_as') |
|
|
|
nickname = LocalizedField() |
|
|
|
arabic_nickname = ArabicLocalizedField(source='nickname') |
|
|
|
birth_year_hijri = serializers.SerializerMethodField() |
|
|
|
death_year_hijri = serializers.SerializerMethodField() |
|
|
|
birth_year_raw = serializers.CharField(source='birth_year_hijri', read_only=True) |
|
|
|
@ -1634,7 +1812,8 @@ class NarratorRelationSerializer(serializers.ModelSerializer): |
|
|
|
class Meta: |
|
|
|
model = Transmitters |
|
|
|
fields = [ |
|
|
|
'id', 'slug', 'full_name', 'known_as', |
|
|
|
'id', 'slug', 'full_name', 'arabic_full_name', |
|
|
|
'kunya', 'arabic_kunya', 'known_as', 'arabic_known_as', 'nickname', 'arabic_nickname', |
|
|
|
'birth_year_hijri', 'death_year_hijri', 'birth_year_raw', 'death_year_raw', |
|
|
|
'reliability', 'gender' |
|
|
|
] |
|
|
|
@ -1652,10 +1831,12 @@ class NarratorRelationSerializer(serializers.ModelSerializer): |
|
|
|
return { |
|
|
|
'id': obj.reliability.id, |
|
|
|
'title': get_localized_text(obj.reliability.title, request), |
|
|
|
'slug': obj.reliability.slug, |
|
|
|
'color': obj.reliability.color, |
|
|
|
'main_color_code': obj.reliability.main_color_code, |
|
|
|
'description': get_localized_text(obj.reliability.description, request), |
|
|
|
} |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
# --- سریالایزرهای کمکی تصاویر رفرنس --- |
|
|
|
@ -1717,11 +1898,12 @@ class BaseDetailedReferenceSerializer(serializers.ModelSerializer): |
|
|
|
edition = obj.book_reference.editions.first() |
|
|
|
if edition: |
|
|
|
request = self.context.get("request") |
|
|
|
pub = edition.publisher |
|
|
|
if isinstance(pub, list): |
|
|
|
pub = get_localized_text(pub, request) |
|
|
|
pub_src = edition.publisher_item.title if (getattr(edition, "publisher_item_id", None) and edition.publisher_item and edition.publisher_item.title) else edition.publisher |
|
|
|
pub = get_localized_text(pub_src, request) if isinstance(pub_src, list) else pub_src |
|
|
|
ed_title = get_localized_text(edition.title, request) if isinstance(getattr(edition, "title", None), list) else getattr(edition, "title", None) |
|
|
|
return { |
|
|
|
"id": edition.id, |
|
|
|
"title": ed_title or "", |
|
|
|
"edition_number": edition.edition_number, |
|
|
|
"publisher": pub or "", |
|
|
|
"year_of_publication": edition.year_of_publication or "", |
|
|
|
@ -1779,7 +1961,7 @@ class DetailedCorrectionReferenceSerializer(BaseDetailedReferenceSerializer): |
|
|
|
|
|
|
|
pub = getattr(obj.book_reference, "publisher", None) |
|
|
|
if pub is None and first_ed: |
|
|
|
pub = first_ed.publisher |
|
|
|
pub = first_ed.publisher_item.title if (getattr(first_ed, "publisher_item_id", None) and first_ed.publisher_item and first_ed.publisher_item.title) else first_ed.publisher |
|
|
|
if isinstance(pub, list): |
|
|
|
pub = get_localized_text(pub, request) |
|
|
|
|
|
|
|
@ -1815,24 +1997,7 @@ class DetailedCorrectionReferenceSerializer(BaseDetailedReferenceSerializer): |
|
|
|
return None |
|
|
|
|
|
|
|
def get_edition(self, obj): |
|
|
|
edition = obj.edition |
|
|
|
if not edition and getattr(obj, "book_volume", None) and obj.book_volume.edition: |
|
|
|
edition = obj.book_volume.edition |
|
|
|
if not edition and getattr(obj, "book_reference", None) and hasattr(obj.book_reference, "editions"): |
|
|
|
edition = obj.book_reference.editions.first() |
|
|
|
if edition: |
|
|
|
request = self.context.get('request') |
|
|
|
pub = edition.publisher |
|
|
|
if isinstance(pub, list): |
|
|
|
pub = get_localized_text(pub, request) |
|
|
|
return { |
|
|
|
'id': edition.id, |
|
|
|
'edition_number': edition.edition_number, |
|
|
|
'publisher': pub or '', |
|
|
|
'year_of_publication': edition.year_of_publication or '', |
|
|
|
'number_of_volumes': edition.number_of_volumes, |
|
|
|
} |
|
|
|
return None |
|
|
|
return self.get_edition_info(obj) |
|
|
|
|
|
|
|
def get_open_book_url(self, obj): |
|
|
|
request = self.context.get('request') |
|
|
|
|