Serialize alt text of images

This commit is contained in:
Mouse Reeve
2020-12-17 12:46:05 -08:00
parent 39dc0501a5
commit 530198adea
6 changed files with 34 additions and 12 deletions

View File

@ -53,7 +53,8 @@ class User(OrderedCollectionPageMixin, AbstractUser):
# name is your display name, which you can change at will
name = fields.CharField(max_length=100, default='')
avatar = fields.ImageField(
upload_to='avatars/', blank=True, null=True, activitypub_field='icon')
upload_to='avatars/', blank=True, null=True,
activitypub_field='icon', alt_field='alt_text')
followers = fields.ManyToManyField(
'self',
link_only=True,
@ -90,6 +91,11 @@ class User(OrderedCollectionPageMixin, AbstractUser):
last_active_date = models.DateTimeField(auto_now=True)
manually_approves_followers = fields.BooleanField(default=False)
@property
def alt_text(self):
''' alt text with username '''
return 'avatar for %s' % (self.localname or self.username)
@property
def display_name(self):
''' show the cleanest version of the user's name possible '''