diff --git a/src/documents/models.py b/src/documents/models.py index 5b97f9ebab87a340fa50047ce1d988b6fc5260fe..292624fe5820a5729d7a7377496c84131bd0de81 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -109,6 +109,29 @@ class Page(Document): direction = EnumField(PageDirection, max_length=10, null=True, blank=True) objects = DocumentManager() + @property + def display_name(self): + """ + Generate a pretty display name for a page. + If the folio parsing had failed, will return the raw folio. + """ + if self.page_type is None and self.nb is None and self.direction is None: + if self.folio.strip() == "": + return "Unknown folio" + return self.folio + + text = self.page_type.name if self.page_type is not None else 'Page' + + if self.nb is not None: + text += ' no. {0:d}'.format(self.nb) + else: + text += ', unnumbered' + + if self.direction is not None: + text += ', {}'.format(self.direction.value) + + return text.capitalize() + def save(self, *args, **kwargs): # TODO: move this in Document through introspection self.type = DocumentType.Page