Skip to content

Commit

Permalink
🕰 API: include last_published_at (#196)
Browse files Browse the repository at this point in the history
# API
Include `last_published_at` in meta for
- `/exhibits/`
- `/collections/`

Used for WGBH-MLA/ov-frontend#73
  • Loading branch information
mrharpo authored Aug 28, 2024
1 parent 67c8c97 commit 0efceae
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
File renamed without changes.
24 changes: 24 additions & 0 deletions exhibits/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar

from wagtail.api.v2.views import PagesAPIViewSet

from .models import ExhibitPage
Expand All @@ -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")
22 changes: 0 additions & 22 deletions exhibits/views.py

This file was deleted.

5 changes: 5 additions & 0 deletions ov_collections/views.py → ov_collections/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions ov_wag/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 0efceae

Please sign in to comment.