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

@ -52,7 +52,8 @@ class Book(ActivitypubMixin, BookWyrmModel):
authors = fields.ManyToManyField('Author')
# preformatted authorship string for search and easier display
author_text = models.CharField(max_length=255, blank=True, null=True)
cover = fields.ImageField(upload_to='covers/', blank=True, null=True)
cover = fields.ImageField(
upload_to='covers/', blank=True, null=True, alt_field='alt_text')
first_published_date = fields.DateTimeField(blank=True, null=True)
published_date = fields.DateTimeField(blank=True, null=True)
@ -62,13 +63,14 @@ class Book(ActivitypubMixin, BookWyrmModel):
def edition_info(self):
''' properties of this edition, as a string '''
items = [
self.physical_format if isinstance(self, models.Edition) else None,
self.physical_format,
self.languages[0] + ' language' if self.languages and \
self.languages[0] != 'English' else None,
str(self.published_date.year) if self.published_date else None,
]
return ', '.join(i for i in items if i)
@property
def alt_text(self):
''' image alt test '''
return '%s cover (%s)' % (self.title, self.edition_info)