Make alt text a model property

This commit is contained in:
Mouse Reeve
2020-12-17 12:30:49 -08:00
parent 2799ed68e3
commit 39dc0501a5
6 changed files with 43 additions and 46 deletions

View File

@ -58,6 +58,21 @@ class Book(ActivitypubMixin, BookWyrmModel):
objects = InheritanceManager()
@property
def edition_info(self):
''' properties of this edition, as a string '''
items = [
self.physical_format if isinstance(self, models.Edition) else None,
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)
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):