From 4771e004fa76453dd11240bb934018a1f7070d41 Mon Sep 17 00:00:00 2001 From: mohsentaba Date: Wed, 24 Dec 2025 11:12:55 +0330 Subject: [PATCH] sect types updated. --- apps/hadis/docs.py | 55 ++++++++++++++++-------------- apps/hadis/serializers/category.py | 7 ++-- apps/hadis/views/category.py | 36 +++---------------- 3 files changed, 38 insertions(+), 60 deletions(-) diff --git a/apps/hadis/docs.py b/apps/hadis/docs.py index 17463e9..41689c6 100644 --- a/apps/hadis/docs.py +++ b/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" + ] + } + ] } } ), diff --git a/apps/hadis/serializers/category.py b/apps/hadis/serializers/category.py index 97d0951..7d67a76 100644 --- a/apps/hadis/serializers/category.py +++ b/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)) diff --git a/apps/hadis/views/category.py b/apps/hadis/views/category.py index df37c9b..1ce1fc8 100644 --- a/apps/hadis/views/category.py +++ b/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