From f42a5444e5bcfbe9f04c5c377fdedf6fee18b543 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Feb 2021 11:17:31 -0800 Subject: [PATCH] User ordered collection subtype for shelves --- bookwyrm/activitypub/__init__.py | 2 +- bookwyrm/activitypub/ordered_collection.py | 13 ++++++++++--- bookwyrm/models/base_model.py | 1 + bookwyrm/models/shelf.py | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bookwyrm/activitypub/__init__.py b/bookwyrm/activitypub/__init__.py index 9f46e12a..201e8042 100644 --- a/bookwyrm/activitypub/__init__.py +++ b/bookwyrm/activitypub/__init__.py @@ -10,7 +10,7 @@ from .note import Note, GeneratedNote, Article, Comment, Review, Quotation from .note import Tombstone from .interaction import Boost, Like from .ordered_collection import OrderedCollection, OrderedCollectionPage -from .ordered_collection import BookList +from .ordered_collection import BookList, Shelf from .person import Person, PublicKey from .response import ActivitypubResponse from .book import Edition, Work, Author diff --git a/bookwyrm/activitypub/ordered_collection.py b/bookwyrm/activitypub/ordered_collection.py index 94254644..fea793cf 100644 --- a/bookwyrm/activitypub/ordered_collection.py +++ b/bookwyrm/activitypub/ordered_collection.py @@ -13,13 +13,20 @@ class OrderedCollection(ActivityObject): last: str = None name: str = None owner: str = None - to: List[str] = field(default_factory=lambda: []) - cc: List[str] = field(default_factory=lambda: []) type: str = 'OrderedCollection' +@dataclass(init=False) +class OrderedCollectionPrivate(OrderedCollection): + to: List[str] = field(default_factory=lambda: []) + cc: List[str] = field(default_factory=lambda: []) @dataclass(init=False) -class BookList(OrderedCollection): +class Shelf(OrderedCollectionPrivate): + ''' structure of an ordered collection activity ''' + type: str = 'Shelf' + +@dataclass(init=False) +class BookList(OrderedCollectionPrivate): ''' structure of an ordered collection activity ''' summary: str = None curation: str = 'closed' diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index b652ae9f..ba0a54be 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -229,6 +229,7 @@ class OrderedCollectionPageMixin(ActivitypubMixin): serializer = self.activity_serializer # a dict from the model fields activity = generate_activity(self) + if remote_id: activity['id'] = remote_id diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index 87200f38..ff5660dd 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -23,6 +23,8 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): through_fields=('shelf', 'book') ) + activity_serializer = activitypub.Shelf + def save(self, *args, **kwargs): ''' set the identifier ''' saved = super().save(*args, **kwargs)