1
- from rest_framework import generics , filters
1
+ from rest_framework import generics
2
2
from rest_framework .views import APIView
3
3
from rest_framework .response import Response
4
4
from django_filters .rest_framework import DjangoFilterBackend
5
5
from backend .models .publications import Publication
6
6
from api .filters .publications import PublicationFilter
7
7
from api .serializers .publications import PublicationsSerializer
8
8
from api .utils import Pagination
9
- from rest_framework .permissions import IsAuthenticated
9
+ from rest_framework .permissions import IsAuthenticated
10
+
10
11
11
12
class PaginatedPublicationsEndpoint (generics .ListAPIView ):
12
13
permission_classes = (IsAuthenticated ,)
13
14
queryset = Publication .objects .all ()
14
15
serializer_class = PublicationsSerializer
15
16
pagination_class = Pagination
16
17
18
+
17
19
class PublicationsEndpoint (generics .ListAPIView ):
18
20
permission_classes = (IsAuthenticated ,)
19
21
queryset = Publication .objects .all ()
20
22
serializer_class = PublicationsSerializer
21
23
24
+
22
25
class PublicationsQueryEndpoint (generics .ListAPIView ):
23
26
permission_classes = (IsAuthenticated ,)
24
27
queryset = Publication .objects .all ()
25
28
serializer_class = PublicationsSerializer
26
29
filter_backends = [DjangoFilterBackend ]
27
30
filterset_class = PublicationFilter
28
31
32
+
29
33
class PaginatedPublicationsQueryEndpoint (generics .ListAPIView ):
30
34
permission_classes = (IsAuthenticated ,)
31
35
queryset = Publication .objects .all ()
@@ -34,27 +38,27 @@ class PaginatedPublicationsQueryEndpoint(generics.ListAPIView):
34
38
filterset_class = PublicationFilter
35
39
pagination_class = Pagination
36
40
41
+
37
42
class PublicationEndpoint (APIView ):
38
43
permission_classes = (IsAuthenticated ,)
39
44
40
-
41
45
def get (self , request , format = None , ** kwargs ):
42
46
"""
43
47
Returns the a publication by its slug.
44
48
"""
45
49
46
50
try :
47
- publication = Publication .objects .get (slug = kwargs .get (' slug' ))
51
+ publication = Publication .objects .get (slug = kwargs .get (" slug" ))
48
52
49
53
formatted_publication = {
50
- ' title' : publication .title ,
51
- ' description' : publication .description ,
52
- ' created_at' : publication .created_at ,
53
- ' slug' : publication .slug ,
54
- ' body' : publication .body ,
55
- ' image' : publication .image .url ,
54
+ " title" : publication .title ,
55
+ " description" : publication .description ,
56
+ " created_at" : publication .created_at ,
57
+ " slug" : publication .slug ,
58
+ " body" : publication .body ,
59
+ " image" : publication .image .url ,
56
60
}
57
-
61
+
58
62
return Response (formatted_publication )
59
63
except Publication .DoesNotExist :
60
- return Response ("This publication doesn't exist yet." )
64
+ return Response ("This publication doesn't exist yet." )
0 commit comments