Merge pull request #402 from mouse-reeve/alt-text

Federate cover alt text
This commit is contained in:
Mouse Reeve
2020-12-17 13:22:09 -08:00
committed by GitHub
11 changed files with 78 additions and 57 deletions

View File

@ -52,12 +52,29 @@ 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)
objects = InheritanceManager()
@property
def edition_info(self):
''' properties of this edition, as a string '''
items = [
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)
def save(self, *args, **kwargs):
''' can't be abstract for query reasons, but you shouldn't USE it '''
if not isinstance(self, Edition) and not isinstance(self, Work):