Merge branch 'main' of https://gitea.corbz.dev/corbz/PYRSS-Website
This commit is contained in:
commit
3efaae8b5c
@ -117,13 +117,26 @@ class SubscriptionSerializer(DynamicModelSerializer):
|
|||||||
fields = ("uuid", "name", "rss_url", "image", "server", "creation_datetime")
|
fields = ("uuid", "name", "rss_url", "image", "server", "creation_datetime")
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionChannelSerializer(DynamicModelSerializer):
|
class SubscriptionChannelSerializerGET(DynamicModelSerializer):
|
||||||
"""
|
"""
|
||||||
Serializer for the SubscriptionChannel Model.
|
Serializer for the SubscriptionChannel Model.
|
||||||
|
This serializer should be used with GET requests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# subscription = serializers.PrimaryKeyRelatedField(queryset=Subscription.objects.all())
|
subscription = SubscriptionSerializer()
|
||||||
subscription = SubscriptionSerializer(read_only=True)
|
|
||||||
|
class Meta:
|
||||||
|
model = SubscriptionChannel
|
||||||
|
fields = ("uuid", "id", "subscription", "creation_datetime")
|
||||||
|
|
||||||
|
|
||||||
|
class SubscriptionChannelSerializerPOST(DynamicModelSerializer):
|
||||||
|
"""
|
||||||
|
Serializer for the SubscriptionChannel Model.
|
||||||
|
This serializer should be used with POST requests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
subscription = serializers.PrimaryKeyRelatedField(queryset=Subscription.objects.all())
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SubscriptionChannel
|
model = SubscriptionChannel
|
||||||
|
@ -11,7 +11,12 @@ from rest_framework.authentication import SessionAuthentication, TokenAuthentica
|
|||||||
from rest_framework.parsers import MultiPartParser, FormParser
|
from rest_framework.parsers import MultiPartParser, FormParser
|
||||||
|
|
||||||
from apps.home.models import Subscription, SubscriptionChannel, TrackedContent
|
from apps.home.models import Subscription, SubscriptionChannel, TrackedContent
|
||||||
from .serializers import SubscriptionSerializer, SubscriptionChannelSerializer, TrackedContentSerializer
|
from .serializers import (
|
||||||
|
SubscriptionSerializer,
|
||||||
|
SubscriptionChannelSerializerGET,
|
||||||
|
SubscriptionChannelSerializerPOST,
|
||||||
|
TrackedContentSerializer
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -95,13 +100,19 @@ class SubscriptionChannel_ListView(generics.ListCreateAPIView):
|
|||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
pagination_class = DefaultPagination
|
pagination_class = DefaultPagination
|
||||||
serializer_class = SubscriptionChannelSerializer
|
# serializer_class = SubscriptionChannelSerializer
|
||||||
queryset = SubscriptionChannel.objects.all().order_by("-creation_datetime")
|
queryset = SubscriptionChannel.objects.all().order_by("-creation_datetime")
|
||||||
|
|
||||||
filter_backends = [rest_filters.DjangoFilterBackend, filters.OrderingFilter]
|
filter_backends = [rest_filters.DjangoFilterBackend, filters.OrderingFilter]
|
||||||
filterset_fields = ["uuid", "id", "subscription", "subscription__server"]
|
filterset_fields = ["uuid", "id", "subscription", "subscription__server"]
|
||||||
ordering_fields = ["creation_datetime"]
|
ordering_fields = ["creation_datetime"]
|
||||||
|
|
||||||
|
def get_serializer(self, *args, **kwargs):
|
||||||
|
if self.request.method == "POST":
|
||||||
|
return SubscriptionChannelSerializerPOST(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
return SubscriptionChannelSerializerGET(*args, **kwargs)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
@ -116,6 +127,11 @@ class SubscriptionChannel_ListView(generics.ListCreateAPIView):
|
|||||||
exception=True
|
exception=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Switch to the GET serializer for return data, as it contains more data on the subscription.
|
||||||
|
# We can't modify the POST serializer to contain this data, otherwise it expects it in POST.
|
||||||
|
self.request.method = "GET"
|
||||||
|
serializer = self.get_serializer(serializer.instance)
|
||||||
|
|
||||||
headers = self.get_success_headers(serializer.data)
|
headers = self.get_success_headers(serializer.data)
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
||||||
|
|
||||||
@ -131,7 +147,7 @@ class SubscriptionChannel_DetailView(generics.RetrieveDestroyAPIView):
|
|||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
parser_classes = [MultiPartParser, FormParser]
|
parser_classes = [MultiPartParser, FormParser]
|
||||||
|
|
||||||
serializer_class = SubscriptionChannelSerializer
|
serializer_class = SubscriptionChannelSerializerGET
|
||||||
queryset = SubscriptionChannel.objects.all().order_by("-creation_datetime")
|
queryset = SubscriptionChannel.objects.all().order_by("-creation_datetime")
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
[2024-01-26 20:15:38] [ERROR] [django.security.DisallowedHost]: Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.
|
|
||||||
Traceback (most recent call last):
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
|
|
||||||
response = get_response(request)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/utils/deprecation.py", line 133, in __call__
|
|
||||||
response = self.process_request(request)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
|
|
||||||
host = request.get_host()
|
|
||||||
^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/http/request.py", line 151, in get_host
|
|
||||||
raise DisallowedHost(msg)
|
|
||||||
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.
|
|
||||||
[2024-01-26 20:15:38] [WARNING] [django.server]: "GET / HTTP/1.1" 400 74757
|
|
||||||
[2024-01-26 20:15:38] [ERROR] [django.security.DisallowedHost]: Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.
|
|
||||||
Traceback (most recent call last):
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
|
|
||||||
response = get_response(request)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/utils/deprecation.py", line 133, in __call__
|
|
||||||
response = self.process_request(request)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
|
|
||||||
host = request.get_host()
|
|
||||||
^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/mnt/storage/projects/Websites/PYRSS-Website/venv/lib/python3.11/site-packages/django/http/request.py", line 151, in get_host
|
|
||||||
raise DisallowedHost(msg)
|
|
||||||
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.
|
|
||||||
[2024-01-26 20:15:38] [WARNING] [django.server]: "GET /favicon.ico HTTP/1.1" 400 74722
|
|
||||||
[2024-01-26 20:15:49] [INFO] [django.utils.autoreload]: Watching for file changes with StatReloader
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET / HTTP/1.1" 302 0
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /admin/ HTTP/1.1" 200 10059
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/css/base.css HTTP/1.1" 200 21544
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/css/nav_sidebar.css HTTP/1.1" 200 2810
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/css/dashboard.css HTTP/1.1" 200 441
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/css/dark_mode.css HTTP/1.1" 200 2682
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/js/theme.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/js/nav_sidebar.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/css/responsive.css HTTP/1.1" 200 17905
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/img/icon-changelink.svg HTTP/1.1" 200 380
|
|
||||||
[2024-01-26 20:15:50] [INFO] [django.server]: "GET /static/admin/img/icon-addlink.svg HTTP/1.1" 200 331
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /api/rssfeed/ HTTP/1.1" 200 12613
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/css/bootstrap.min.css HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/js/csrf.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/css/bootstrap-tweaks.css HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/css/default.css HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/js/jquery-3.5.1.min.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/js/ajax-form.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/css/prettify.css HTTP/1.1" 200 817
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/js/bootstrap.min.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/js/default.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/js/prettify-min.js HTTP/1.1" 304 0
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/img/grid.png HTTP/1.1" 200 1458
|
|
||||||
[2024-01-26 20:16:00] [INFO] [django.server]: "GET /static/rest_framework/fonts/glyphicons-halflings-regular.woff2 HTTP/1.1" 200 18028
|
|
||||||
[2024-01-26 20:16:28] [WARNING] [django.server]: "GET /api/rssfeed/ HTTP/1.1" 403 58
|
|
||||||
[2024-01-26 20:16:28] [INFO] [django.server]: "GET /static/rest_framework/css/bootstrap.min.css.map HTTP/1.1" 304 0
|
|
Loading…
x
Reference in New Issue
Block a user