|
|
|
@ -11,7 +11,8 @@ from ..serializers import ( |
|
|
|
CategorySerializer , |
|
|
|
HadisCategorySelectSerializer , |
|
|
|
HadisCategorySelectSourceSerializer, |
|
|
|
get_localized_text |
|
|
|
get_localized_text, |
|
|
|
SimpleCategory |
|
|
|
) |
|
|
|
from ..docs import ( |
|
|
|
hadis_sect_list_swagger, |
|
|
|
@ -212,6 +213,34 @@ class HadisCategorySelectBySectView(ListAPIView): |
|
|
|
@categories_tree_by_sect_swagger |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
return self.list(request, *args, **kwargs) |
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs): |
|
|
|
# 1. Run the standard list logic (get pagination, filter, results) |
|
|
|
response = super().list(request, *args, **kwargs) |
|
|
|
|
|
|
|
# 2. Find the "Parent" Category based on the URL slug |
|
|
|
category_slug = self.kwargs.get('slug') |
|
|
|
category_obj = get_object_or_404(HadisCategory, slug=category_slug) |
|
|
|
|
|
|
|
# 3. Serialize this single category for the Hero section |
|
|
|
# You might need a simple serializer just for titles/descriptions |
|
|
|
category_data = SimpleCategory(category_obj).data |
|
|
|
|
|
|
|
# 4. Inject it into the response data |
|
|
|
# Note: We access response.data because we are using DRF's Response object |
|
|
|
if isinstance(response.data, dict): |
|
|
|
# Reorder the response to place current_category before results |
|
|
|
ordered_data = {} |
|
|
|
for key in ['count', 'next', 'previous']: |
|
|
|
if key in response.data: |
|
|
|
ordered_data[key] = response.data[key] |
|
|
|
ordered_data['current_category'] = category_data |
|
|
|
if 'results' in response.data: |
|
|
|
ordered_data['results'] = response.data['results'] |
|
|
|
response.data = ordered_data |
|
|
|
|
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
sect_type = self.kwargs.get('sect_type') |
|
|
|
@ -248,6 +277,34 @@ class HadisCategorySelectBySectSourceView(ListAPIView): |
|
|
|
@categories_tree_by_sect_source_swagger |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
return self.list(request, *args, **kwargs) |
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs): |
|
|
|
# 1. Run the standard list logic (get pagination, filter, results) |
|
|
|
response = super().list(request, *args, **kwargs) |
|
|
|
|
|
|
|
# 2. Find the "Parent" Category based on the URL slug |
|
|
|
category_slug = self.kwargs.get('slug') |
|
|
|
category_obj = get_object_or_404(HadisCategory, slug=category_slug) |
|
|
|
|
|
|
|
# 3. Serialize this single category for the Hero section |
|
|
|
# You might need a simple serializer just for titles/descriptions |
|
|
|
category_data = SimpleCategory(category_obj).data |
|
|
|
|
|
|
|
# 4. Inject it into the response data |
|
|
|
# Note: We access response.data because we are using DRF's Response object |
|
|
|
if isinstance(response.data, dict): |
|
|
|
# Reorder the response to place current_category before results |
|
|
|
ordered_data = {} |
|
|
|
for key in ['count', 'next', 'previous']: |
|
|
|
if key in response.data: |
|
|
|
ordered_data[key] = response.data[key] |
|
|
|
ordered_data['current_category'] = category_data |
|
|
|
if 'results' in response.data: |
|
|
|
ordered_data['results'] = response.data['results'] |
|
|
|
response.data = ordered_data |
|
|
|
|
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
sect_type = self.kwargs.get('sect_type') |
|
|
|
@ -300,6 +357,7 @@ class CategoriesBySectView(ListAPIView): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
return self.list(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
from rest_framework.decorators import api_view, permission_classes, authentication_classes |
|
|
|
from rest_framework.permissions import AllowAny |
|
|
|
from rest_framework.response import Response |
|
|
|
|