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
|
@ -10,8 +10,8 @@ from bookwyrm.models.shelf import Shelf
|
|||
from bookwyrm.models.status import Status
|
||||
from bookwyrm.settings import DOMAIN
|
||||
from bookwyrm.signatures import create_key_pair
|
||||
from .base_model import OrderedCollectionPageMixin
|
||||
from .base_model import ActivityMapping
|
||||
from .base_model import ActivityMapping, OrderedCollectionPageMixin
|
||||
from .base_model import image_formatter
|
||||
|
||||
|
||||
class User(OrderedCollectionPageMixin, AbstractUser):
|
||||
|
@ -78,16 +78,6 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
''' generates url for activitypub followers page '''
|
||||
return '%s/followers' % self.remote_id
|
||||
|
||||
@property
|
||||
def ap_icon(self):
|
||||
''' send default icon if one isn't set '''
|
||||
if self.avatar:
|
||||
url = self.avatar.url
|
||||
else:
|
||||
url = '/static/images/default_avi.jpg'
|
||||
url = 'https://%s%s' % (DOMAIN, url)
|
||||
return activitypub.Image(url=url)
|
||||
|
||||
@property
|
||||
def ap_public_key(self):
|
||||
''' format the public key block for activitypub '''
|
||||
|
@ -122,7 +112,10 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
activity_formatter=lambda x: {'sharedInbox': x},
|
||||
model_formatter=lambda x: x.get('sharedInbox')
|
||||
),
|
||||
ActivityMapping('icon', 'ap_icon'),
|
||||
ActivityMapping(
|
||||
'icon', 'avatar',
|
||||
lambda x: image_formatter(x, '/static/images/default_avi.jpg')
|
||||
),
|
||||
ActivityMapping(
|
||||
'manuallyApprovesFollowers',
|
||||
'manually_approves_followers'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue