Formatter for converting model images to AP Images
Replaces reduntant properties on user and book models
This commit is contained in:
parent
dab0aeffb2
commit
5526b4773e
3 changed files with 33 additions and 23 deletions
|
@ -261,3 +261,25 @@ def tag_formatter(items, name_field, activity_type):
|
|||
type=activity_type
|
||||
))
|
||||
return tags
|
||||
|
||||
|
||||
def image_formatter(image, default_path=None):
|
||||
''' convert images into activitypub json '''
|
||||
if image:
|
||||
url = image.url
|
||||
elif default_path:
|
||||
url = default_path
|
||||
else:
|
||||
return None
|
||||
url = 'https://%s%s' % (DOMAIN, url)
|
||||
return activitypub.Image(url=url)
|
||||
|
||||
|
||||
def image_attachments_formatter(images):
|
||||
''' create a list of image attachemnts '''
|
||||
if not isinstance(images, list):
|
||||
images = [images]
|
||||
attachments = []
|
||||
for image in images:
|
||||
attachments.append(image_formatter(image))
|
||||
return attachments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue