Browse Source

sect types updated.

master
Mohsen Taba 5 months ago
parent
commit
4771e004fa
  1. 55
      apps/hadis/docs.py
  2. 7
      apps/hadis/serializers/category.py
  3. 36
      apps/hadis/views/category.py

55
apps/hadis/docs.py

@ -12,33 +12,36 @@ hadis_sect_list_swagger = swagger_auto_schema(
description="List of hadis sects grouped by type with count",
examples={
"application/json": {
"count": 4,
"results": {
"shia": [
{
"id": 1,
"title": "Twelver Shia",
"seo_field": None
},
{
"id": 2,
"title": "Ismaili Shia",
"seo_field": None
}
],
"sunni": [
{
"id": 3,
"title": "Hanafi",
"seo_field": None
},
{
"id": 4,
"title": "Maliki",
"seo_field": None
}
"count": 2,
"next": 'null',
"previous": 'null',
"results": [
{
"id": 20,
"sect_type": "shia",
"title": "Шииты-двунадесятники",
"order":1,
"description": [],
"source_types": [
"hadith",
"quote",
"quran"
]
}
},
{
"id": 21,
"sect_type": "sunni",
"title": "Сунниты",
"order":1,
"description": [],
"source_types": [
"fatwa",
"hadith",
"history",
"quran"
]
}
]
}
}
),

7
apps/hadis/serializers/category.py

@ -79,14 +79,15 @@ class HadisCategorySectListSerializer(serializers.ModelSerializer):
class Meta:
model = HadisSect
fields = ['id', 'title', 'description', 'source_types']
fields = ['id','sect_type', 'title','order', 'description', 'source_types']
def get_source_types(self, obj):
"""Get unique source types for this sect's categories"""
source_types = HadisCategory.objects.filter(
sect=obj
).values_list('source_type', flat=True).distinct()
return list(source_types)
).values_list('source_type', flat=True)
# Use set to ensure uniqueness, then convert back to list
return list(set(source_types))

36
apps/hadis/views/category.py

@ -35,36 +35,6 @@ class HadisCategorySectListView(ListAPIView):
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
response = super().list(request, *args, **kwargs)
lang = request.LANGUAGE_CODE
# Group sects by type
grouped_data = {
'shia': [],
'sunni': []
}
for sect in queryset:
sect_data = {
'id': sect.id,
'title': sect.title,
}
if sect.sect_type == HadisSect.SectType.SHIA:
grouped_data['shia'].append(sect_data)
elif sect.sect_type == HadisSect.SectType.SUNNI:
grouped_data['sunni'].append(sect_data)
# Create response with count and results
response_data = {
'count': queryset.count(),
'results': grouped_data
}
return Response(response_data)
class HadisCategoryTreeView(ListAPIView):
"""
@ -130,12 +100,16 @@ class HadisCategoryTreeView(ListAPIView):
# Add sect info
sect_id = str(category.sect.id)
if sect_id not in grouped_data[sect_type]['sects']:
source_types = HadisCategory.objects.filter(
sect=category.sect
).values_list('source_type', flat=True)
grouped_data[sect_type]['sects'][sect_id] = {
'id': category.sect.id,
'sect_type': category.sect.sect_type,
'title': get_localized_text(category.sect.title, request),
'description': category.sect.description,
'order': category.sect.order
'order': category.sect.order,
'source_types':list(set(source_types))
}
# Build tree using prefetched data

Loading…
Cancel
Save