2022-10-23 21:30:00 +01:00
|
|
|
from django.http import HttpResponseRedirect
|
2022-08-22 23:26:39 +01:00
|
|
|
from django.http.request import HttpRequest
|
2022-10-23 21:30:00 +01:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.views.generic import RedirectView
|
2022-08-23 09:23:22 +01:00
|
|
|
from rest_framework.generics import ListAPIView
|
2022-08-22 23:26:39 +01:00
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.views import APIView
|
2022-08-23 09:23:22 +01:00
|
|
|
from wagtail.models import Page
|
|
|
|
from wagtail.query import PageQuerySet
|
|
|
|
|
2022-08-25 00:27:31 +01:00
|
|
|
from website.blog.models import BlogPostPage
|
2022-08-23 14:56:05 +01:00
|
|
|
|
|
|
|
from . import filters, serializers
|
|
|
|
from .pagination import CustomPageNumberPagination
|
2022-08-22 23:26:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PingAPIView(APIView):
|
|
|
|
"""
|
|
|
|
PONGs
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get(self, request: HttpRequest) -> Response:
|
|
|
|
return Response("PONG")
|
2022-08-23 09:23:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PageLinksAPIView(ListAPIView):
|
|
|
|
serializer_class = serializers.PageLinkSerializer
|
|
|
|
|
|
|
|
def get_queryset(self) -> PageQuerySet:
|
|
|
|
return (
|
|
|
|
Page.objects.live()
|
2022-08-28 16:51:27 +01:00
|
|
|
.public()
|
2022-08-23 09:23:22 +01:00
|
|
|
.exclude(depth__lte=1)
|
|
|
|
.only("id", "url_path", "title")
|
|
|
|
.order_by("title")
|
|
|
|
)
|
2022-08-23 14:56:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LMOTFYAPIView(ListAPIView):
|
|
|
|
"""
|
|
|
|
Let Me Orange That For You
|
|
|
|
"""
|
|
|
|
|
2022-10-31 20:39:36 +00:00
|
|
|
filter_backends = [filters.WagtailSearchFilter]
|
2022-08-23 14:56:05 +01:00
|
|
|
serializer_class = serializers.LMOTFYSerializer
|
|
|
|
pagination_class = CustomPageNumberPagination
|
|
|
|
|
|
|
|
def get_queryset(self) -> PageQuerySet:
|
2022-08-28 16:51:27 +01:00
|
|
|
return (
|
|
|
|
BlogPostPage.objects.live()
|
|
|
|
.public()
|
|
|
|
.select_related("hero_image", "hero_unsplash_photo")
|
2022-08-25 00:27:31 +01:00
|
|
|
)
|
2022-10-23 21:30:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SwaggerRedirectView(RedirectView):
|
|
|
|
SWAGGER_EDITOR_URL = "https://editor.swagger.io/?url="
|
|
|
|
|
|
|
|
def get(self, request: HttpRequest) -> HttpResponseRedirect:
|
|
|
|
return HttpResponseRedirect(
|
|
|
|
self.SWAGGER_EDITOR_URL + request.build_absolute_uri(reverse("api:schema"))
|
|
|
|
)
|
2024-01-28 18:06:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LatestPostsAPIView(ListAPIView):
|
|
|
|
"""
|
|
|
|
List my latest blog posts
|
|
|
|
"""
|
|
|
|
|
|
|
|
serializer_class = serializers.LatestPostSerializer
|
|
|
|
pagination_class = CustomPageNumberPagination
|
|
|
|
|
|
|
|
def get_queryset(self) -> PageQuerySet:
|
|
|
|
return (
|
|
|
|
BlogPostPage.objects.live()
|
|
|
|
.public()
|
|
|
|
.only("id", "url_path", "title", "date")
|
|
|
|
.order_by("-date")
|
|
|
|
)
|