Formatter for converting model images to AP Images
Replaces reduntant properties on user and book models
This commit is contained in:
@ -12,6 +12,7 @@ from bookwyrm.utils.fields import ArrayField
|
||||
|
||||
from .base_model import ActivityMapping, BookWyrmModel
|
||||
from .base_model import ActivitypubMixin, OrderedCollectionPageMixin
|
||||
from .base_model import image_attachments_formatter
|
||||
|
||||
class Book(ActivitypubMixin, BookWyrmModel):
|
||||
''' a generic book, which can mean either an edition or a work '''
|
||||
@ -60,15 +61,6 @@ class Book(ActivitypubMixin, BookWyrmModel):
|
||||
''' the activitypub serialization should be a list of author ids '''
|
||||
return [a.remote_id for a in self.authors.all()]
|
||||
|
||||
@property
|
||||
def ap_cover(self):
|
||||
''' an image attachment '''
|
||||
if not self.cover or not hasattr(self.cover, 'url'):
|
||||
return []
|
||||
return [activitypub.Image(
|
||||
url='https://%s%s' % (DOMAIN, self.cover.url),
|
||||
)]
|
||||
|
||||
@property
|
||||
def ap_parent_work(self):
|
||||
''' reference the work via local id not remote '''
|
||||
@ -106,7 +98,10 @@ class Book(ActivitypubMixin, BookWyrmModel):
|
||||
|
||||
ActivityMapping('lccn', 'lccn'),
|
||||
ActivityMapping('editions', 'editions_path'),
|
||||
ActivityMapping('attachment', 'ap_cover'),
|
||||
ActivityMapping(
|
||||
'attachment', 'cover',
|
||||
image_attachments_formatter
|
||||
),
|
||||
]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
Reference in New Issue
Block a user