Skip to content
Snippets Groups Projects
Commit 2e99502a authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'pretty-folio' into 'master'

Page display name

See merge request !19
parents d2718758 31f63564
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
......
......@@ -64,6 +64,7 @@ class PageLightSerializer(serializers.ModelSerializer):
'page_type',
'nb',
'direction',
'display_name',
'images',
)
......@@ -187,7 +188,7 @@ class PageZoneCanvasManifestSerializer(serializers.BaseSerializer):
return {
"@id": page.build_absolute_url(self.context['request'], 'api:canvas-manifest'),
"@type": "sc:Canvas",
"label": page.folio,
"label": page.display_name,
"height": zone.box.height,
"width": zone.box.width,
"images": [
......
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