Browse Source

slug for hadis urls and serializers.

master
Mohsen Taba 5 months ago
parent
commit
6289214947
  1. 24
      apps/hadis/docs.py
  2. 8
      apps/hadis/serializers/hadis.py
  3. 8
      apps/hadis/urls.py
  4. 31
      apps/hadis/views/hadis.py

24
apps/hadis/docs.py

@ -392,10 +392,10 @@ hadis_basic_swagger = swagger_auto_schema(
tags=['Hadis'],
manual_parameters=[
openapi.Parameter(
'hadis_id',
'hadis_slug',
openapi.IN_PATH,
description="ID of the hadis",
type=openapi.TYPE_INTEGER,
description="Slug of the hadis",
type=openapi.TYPE_STRING,
required=True
)
],
@ -436,10 +436,10 @@ hadis_detail_swagger = swagger_auto_schema(
tags=['Hadis'],
manual_parameters=[
openapi.Parameter(
'hadis_id',
'hadis_slug',
openapi.IN_PATH,
description="ID of the hadis",
type=openapi.TYPE_INTEGER,
description="Slug of the hadis",
type=openapi.TYPE_STRING,
required=True
)
],
@ -511,10 +511,10 @@ hadis_transmitters_swagger = swagger_auto_schema(
manual_parameters=[
# Path Parameter: ID
openapi.Parameter(
'hadis_id',
'hadis_slug',
openapi.IN_PATH,
description="The ID of the Hadis to fetch",
type=openapi.TYPE_INTEGER,
description="The Slug of the Hadis to fetch",
type=openapi.TYPE_STRING,
required=True
),
# Query Parameter: Layer Filter (Optional)
@ -627,10 +627,10 @@ hadis_corrections_swagger = swagger_auto_schema(
tags=['Hadis'],
manual_parameters=[
openapi.Parameter(
'hadis_id',
'hadis_slug',
openapi.IN_PATH,
description="Unique identifier of the hadis. Must be a valid hadis ID that exists in the system. Only active hadis (status=True) are accessible.",
type=openapi.TYPE_INTEGER,
description="Slug of the hadis. Must be a valid hadis slug that exists in the system. Only active hadis (status=True) are accessible.",
type=openapi.TYPE_STRING,
required=True,
example=1
)

8
apps/hadis/serializers/hadis.py

@ -48,7 +48,7 @@ class HadisSyncSerializer(serializers.ModelSerializer):
model = Hadis
fields = [
# header (no-extend)
'id', 'number', 'category_id', 'title', 'title_narrator', 'text', 'translation',
'id', 'number', 'slug', 'category_id', 'title', 'title_narrator', 'text', 'translation',
# grouped sections
'detail', 'narrators', 'explanations', 'corrections',
]
@ -150,7 +150,7 @@ class HadisListSerializer(serializers.ModelSerializer):
class Meta:
model = Hadis
fields = ['id', 'number', 'title','title_narrator', 'text' ,
fields = ['id', 'number', 'slug', 'title','title_narrator', 'text' ,
'translation','category','share_link']
def get_category(self, obj):
@ -505,7 +505,7 @@ class HadisBasicSerializer(serializers.ModelSerializer):
class Meta:
model = Hadis
fields = [
'id', 'title', 'title_narrator', 'text',
'id', 'slug', 'title', 'title_narrator', 'text',
'translation', 'share_link','explanation','category'
]
@ -540,7 +540,7 @@ class HadisDetailSerializer(serializers.ModelSerializer):
class Meta:
model = Hadis
fields = [
'id', 'number',
'id', 'number', 'slug',
'hadis_status_text','hadis_status', 'links','share_link',
'tags', 'references','reference_images','address'
]

8
apps/hadis/urls.py

@ -16,10 +16,10 @@ urlpatterns = [
path('sync/references/', BookReferenceSyncView.as_view(), name='reference-sync'),
path('info/', HadisInfoView.as_view(), name='hadis-info'),
path('category/<int:category_id>/', HadisListView.as_view(), name='hadis-list'),
path('<int:hadis_id>/', HadisBasicView.as_view(), name='hadis-basic'),
path('<int:hadis_id>/detail/', HadisDetailView.as_view(), name='hadis-detail'),
path('<int:hadis_id>/transmitters/', HadisTransmittersView.as_view(), name='hadis-transmitters'),
path('<int:hadis_id>/corrections/', HadisCorrectionsView.as_view(), name='hadis-corrections'),
path('<str:hadis_slug>/', HadisBasicView.as_view(), name='hadis-basic'),
path('<str:hadis_slug>/detail/', HadisDetailView.as_view(), name='hadis-detail'),
path('<str:hadis_slug>/transmitters/', HadisTransmittersView.as_view(), name='hadis-transmitters'),
path('<str:hadis_slug>/corrections/', HadisCorrectionsView.as_view(), name='hadis-corrections'),
path('categories/<str:sect_type>/<str:slug>/<str:source_type>/', HadisCategorySelectBySectSourceView.as_view(), name='categories-tree-by-sect-source'),
path('categories/<str:sect_type>/<str:slug>/', HadisCategorySelectBySectView.as_view(), name='categories-tree-by-sect'),
path('categories/<str:sect_type>/', CategoriesBySectView.as_view(), name='categories-by-sect'),

31
apps/hadis/views/hadis.py

@ -85,11 +85,11 @@ class HadisListView(ListAPIView):
class HadisBasicView(RetrieveAPIView):
"""
API view to retrieve basic Hadis information by hadis_id
API view to retrieve basic Hadis information by hadis_slug
"""
serializer_class = HadisBasicSerializer
lookup_field = 'id'
lookup_url_kwarg = 'hadis_id'
lookup_field = 'slug'
lookup_url_kwarg = 'hadis_slug'
@hadis_basic_swagger
def get(self, request, *args, **kwargs):
@ -101,11 +101,11 @@ class HadisBasicView(RetrieveAPIView):
class HadisDetailView(RetrieveAPIView):
"""
API view to retrieve detailed Hadis information by hadis_id (excluding transmitters and corrections)
API view to retrieve detailed Hadis information by hadis_slug (excluding transmitters and corrections)
"""
serializer_class = HadisDetailSerializer
lookup_field = 'id'
lookup_url_kwarg = 'hadis_id'
lookup_field = 'slug'
lookup_url_kwarg = 'hadis_slug'
@hadis_detail_swagger
def get(self, request, *args, **kwargs):
@ -129,7 +129,8 @@ class HadisTransmittersView(RetrieveAPIView):
if a ?layer=slug param is provided.
"""
serializer_class = HadisTransmitterListSerializer
lookup_url_kwarg = 'hadis_id'
lookup_field = 'slug'
lookup_url_kwarg = 'hadis_slug'
@hadis_transmitters_swagger
def get(self, request, *args, **kwargs):
@ -162,8 +163,8 @@ class HadisCorrectionsView(ListAPIView):
API view to retrieve corrections for a specific hadis
"""
serializer_class = HadisCorrectionSerializer
lookup_field = 'id'
lookup_url_kwarg = 'hadis_id'
lookup_field = 'slug'
lookup_url_kwarg = 'hadis_slug'
@hadis_corrections_swagger
def get(self, request, *args, **kwargs):
@ -187,7 +188,11 @@ class HadisCorrectionsView(ListAPIView):
# })
def get_queryset(self):
hadis_id = self.kwargs.get('hadis_id')
if not HadisCorrection.objects.filter(hadis=hadis_id).exists():
return Hadis.objects.none()
return HadisCorrection.objects.filter(hadis=hadis_id)
hadis_slug = self.kwargs.get('hadis_slug')
try:
hadis = Hadis.objects.get(slug=hadis_slug, status=True)
if not HadisCorrection.objects.filter(hadis=hadis).exists():
return Hadis.objects.none()
return HadisCorrection.objects.filter(hadis=hadis)
except Hadis.DoesNotExist:
return HadisCorrection.objects.none()
Loading…
Cancel
Save