-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from rest_framework import serializers | ||
|
||
from thabloid.models.thabloid import Thabloid | ||
from thaliawebsite.api.v2.serializers.cleaned_model_serializer import ( | ||
CleanedModelSerializer, | ||
) | ||
from utils.media.services import get_media_url | ||
|
||
|
||
class ThabloidSerializer(CleanedModelSerializer): | ||
"""API Serializer for thabloids.""" | ||
|
||
file = serializers.SerializerMethodField() | ||
cover = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
"""Meta class for the serializer.""" | ||
|
||
model = Thabloid | ||
fields = ("pk", "year", "issue", "cover", "file") | ||
|
||
def get_cover(self, instance): | ||
return get_media_url(instance.cover, absolute_url=True) | ||
|
||
def get_file(self, instance): | ||
return get_media_url(instance.file, absolute_url=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Thabloid API v2 urls.""" | ||
from django.urls import include, path | ||
|
||
from thabloid.api.v2.views import ThabloidDetailView, ThabloidListView | ||
|
||
app_name = "thabloid" | ||
|
||
urlpatterns = [ | ||
path( | ||
"thabloid/", | ||
include( | ||
[ | ||
path("thabloids/", ThabloidListView.as_view(), name="thabloid-list"), | ||
path( | ||
"thabloids/<int:pk>", | ||
ThabloidDetailView.as_view(), | ||
name="thabloid-detail", | ||
), | ||
] | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope | ||
from rest_framework import filters | ||
from rest_framework.generics import ListAPIView, RetrieveAPIView | ||
|
||
from thabloid.api.v2.serializers import ThabloidSerializer | ||
from thabloid.models.thabloid import Thabloid | ||
|
||
|
||
class ThabloidListView(ListAPIView): | ||
"""Returns a list of all Thabloids.""" | ||
|
||
serializer_class = ThabloidSerializer | ||
|
||
queryset = Thabloid.objects.all() | ||
|
||
permission_classes = [ | ||
IsAuthenticatedOrTokenHasScope, | ||
] | ||
required_scopes = ["thabloid:read"] | ||
filter_backends = (filters.SearchFilter,) | ||
search_fields = ("year", "issue") | ||
|
||
|
||
class ThabloidDetailView(RetrieveAPIView): | ||
"""Returns details about a specific Thabloid.""" | ||
|
||
serializer_class = ThabloidSerializer | ||
|
||
queryset = Thabloid.objects.all() | ||
|
||
permission_classes = [ | ||
IsAuthenticatedOrTokenHasScope, | ||
] | ||
required_scopes = ["thabloid:read"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters