Skip to content
Snippets Groups Projects
Commit 9216d0b3 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Add display_name property

parent d2718758
No related branches found
No related tags found
1 merge request!19Page display name
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment