From defa23eff37fe083317b7a0ab35566ecbac8cf4a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 10 Mar 2017 17:08:38 -0800 Subject: [PATCH] Add Album.@display_name to remove duplicate logic elsewhere --- etiquette/objects.py | 7 +++++++ etiquette_site.py | 1 + templates/album.html | 11 +++-------- templates/albums.html | 7 +------ templates/photo.html | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 7cf6bb1..73f2d91 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -260,6 +260,13 @@ class Album(ObjectBase, GroupableMixin): self.photodb.log.debug('Committing - delete album') self.photodb.commit() + @property + def display_name(self): + if self.title: + return self.title + else: + return self.id + def edit(self, title=None, description=None, *, commit=True): ''' Change the title or description. Leave None to keep current value. diff --git a/etiquette_site.py b/etiquette_site.py index d4361c9..852e52a 100644 --- a/etiquette_site.py +++ b/etiquette_site.py @@ -350,6 +350,7 @@ def get_album_zip(albumid): def get_albums_core(): albums = P.get_albums() albums = [a for a in albums if a.parent() is None] + albums.sort(key=lambda x: x.display_name.lower()) return albums @site.route('/albums') diff --git a/templates/album.html b/templates/album.html index 3a5704c..d9163ba 100644 --- a/templates/album.html +++ b/templates/album.html @@ -3,7 +3,7 @@ {% import "photo_card.html" as photo_card %} {% import "header.html" as header %} - Album {{album.title}} + Album {{album.display_name}} @@ -28,7 +28,7 @@ p

{{album.description}}

{% set parent=album.parent() %} {% if parent %} -

Parent: {{parent.id + " " + parent.title}}

+

Parent: {{parent.display_name}}

{% else %}

Parent: Albums

{% endif %} @@ -37,12 +37,7 @@ p

Sub-albums

diff --git a/templates/albums.html b/templates/albums.html index bfb8677..6d0c365 100644 --- a/templates/albums.html +++ b/templates/albums.html @@ -19,12 +19,7 @@ {{header.make_header(session=session)}}
{% for album in albums %} - {% if album.title %} - {% set title=album.id + " " + album.title %} - {% else %} - {% set title=album.id %} - {% endif %} -
{{album.id + " " + album.title}}
+
{{album.display_name}}
{% endfor %}
diff --git a/templates/photo.html b/templates/photo.html index b30fb5e..3f2464b 100644 --- a/templates/photo.html +++ b/templates/photo.html @@ -181,7 +181,7 @@

Albums containing this photo