From 0efceaeb10e22703e1d418e30d0bb667c50e6baa Mon Sep 17 00:00:00 2001 From: Harpo Date: Wed, 28 Aug 2024 09:57:30 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=B0=20API:=20include=20`last=5Fpublish?= =?UTF-8?q?ed=5Fat`=20(#196)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # API Include `last_published_at` in meta for - `/exhibits/` - `/collections/` Used for https://github.com/WGBH-MLA/ov-frontend/issues/73 --- authors/{views.py => api.py} | 0 exhibits/api.py | 24 ++++++++++++++++++++++++ exhibits/views.py | 22 ---------------------- ov_collections/{views.py => api.py} | 5 +++++ ov_wag/api.py | 7 +++---- 5 files changed, 32 insertions(+), 26 deletions(-) rename authors/{views.py => api.py} (100%) delete mode 100644 exhibits/views.py rename ov_collections/{views.py => api.py} (76%) diff --git a/authors/views.py b/authors/api.py similarity index 100% rename from authors/views.py rename to authors/api.py diff --git a/exhibits/api.py b/exhibits/api.py index 6473c1b..bc6d82e 100644 --- a/exhibits/api.py +++ b/exhibits/api.py @@ -1,3 +1,5 @@ +from typing import ClassVar + from wagtail.api.v2.views import PagesAPIViewSet from .models import ExhibitPage @@ -8,3 +10,25 @@ class FeaturedExhibitsAPIViewSet(PagesAPIViewSet): def get_queryset(self): return ExhibitPage.objects.live().public().filter(featured=True) + + +class ExhibitsAPIViewSet(PagesAPIViewSet): + model = ExhibitPage + + meta_fields: ClassVar[list[str]] = PagesAPIViewSet.meta_fields + [ + 'last_published_at', + ] + + listing_default_fields: ClassVar[list[str]] = [ + *PagesAPIViewSet.listing_default_fields, + 'title', + 'last_published_at', + 'cover_image', + 'cover_thumb', + 'hero_image', + 'hero_thumb', + 'authors', + ] + + def get_queryset(self): + return self.model.objects.live().order_by("-last_published_at") diff --git a/exhibits/views.py b/exhibits/views.py deleted file mode 100644 index 2f0acb8..0000000 --- a/exhibits/views.py +++ /dev/null @@ -1,22 +0,0 @@ -from typing import ClassVar - -from wagtail.api.v2.views import PagesAPIViewSet - -from .models import ExhibitPage - - -class ExhibitsAPIViewSet(PagesAPIViewSet): - model = ExhibitPage - - listing_default_fields: ClassVar[list[str]] = [ - *PagesAPIViewSet.listing_default_fields, - 'title', - 'cover_image', - 'cover_thumb', - 'hero_image', - 'hero_thumb', - 'authors', - ] - - def get_queryset(self): - return self.model.objects.live().order_by("-last_published_at") diff --git a/ov_collections/views.py b/ov_collections/api.py similarity index 76% rename from ov_collections/views.py rename to ov_collections/api.py index 93ad61d..16d0a96 100644 --- a/ov_collections/views.py +++ b/ov_collections/api.py @@ -8,11 +8,16 @@ class CollectionAPIViewSet(PagesAPIViewSet): model = Collection + meta_fields: ClassVar[list[str]] = PagesAPIViewSet.meta_fields + [ + 'last_published_at', + ] + listing_default_fields: ClassVar[list[str]] = [ *PagesAPIViewSet.listing_default_fields, 'title', 'introduction', 'cover_image', + 'last_published_at', ] def get_queryset(self): diff --git a/ov_wag/api.py b/ov_wag/api.py index 1d00f0b..305d8ff 100644 --- a/ov_wag/api.py +++ b/ov_wag/api.py @@ -6,10 +6,9 @@ from wagtail.images.api.v2.views import ImagesAPIViewSet from wagtail_headless_preview.models import PagePreview -from authors.views import AuthorsAPIViewSet -from exhibits.api import FeaturedExhibitsAPIViewSet -from exhibits.views import ExhibitsAPIViewSet -from ov_collections.views import CollectionAPIViewSet +from authors.api import AuthorsAPIViewSet +from exhibits.api import ExhibitsAPIViewSet, FeaturedExhibitsAPIViewSet +from ov_collections.api import CollectionAPIViewSet # Create the router. 'wagtailapi' is the URL namespace api_router = WagtailAPIRouter('wagtailapi')