Add Album.@display_name to remove duplicate logic elsewhere

This commit is contained in:
voussoir 2017-03-10 17:08:38 -08:00
parent f797e3fb55
commit defa23eff3
5 changed files with 13 additions and 15 deletions

View file

@ -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.

View file

@ -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')

View file

@ -3,7 +3,7 @@
<head>
{% import "photo_card.html" as photo_card %}
{% import "header.html" as header %}
<title>Album {{album.title}}</title>
<title>Album {{album.display_name}}</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="/static/common.css">
@ -28,7 +28,7 @@ p
<p>{{album.description}}</p>
{% set parent=album.parent() %}
{% if parent %}
<h3>Parent: <a href="/album/{{parent.id}}">{{parent.id + " " + parent.title}}</a></h3>
<h3>Parent: <a href="/album/{{parent.id}}">{{parent.display_name}}</a></h3>
{% else %}
<h3>Parent: <a href="/albums">Albums</a></h3>
{% endif %}
@ -37,12 +37,7 @@ p
<h3>Sub-albums</h3>
<ul>
{% for sub_album in sub_albums|sort(attribute='title') %}
<li><a href="/album/{{sub_album.id}}">
{% if sub_album.title %}
{{sub_album.title}}
{% else %}
{{sub_album.id}}
{% endif %}</a>
<li><a href="/album/{{sub_album.id}}">{{sub_album.display_name}}</a>
</li>
{% endfor %}
</ul>

View file

@ -19,12 +19,7 @@
{{header.make_header(session=session)}}
<div id="content_body">
{% for album in albums %}
{% if album.title %}
{% set title=album.id + " " + album.title %}
{% else %}
{% set title=album.id %}
{% endif %}
<div><a href="/album/{{album.id}}">{{album.id + " " + album.title}}</a></div>
<div><a href="/album/{{album.id}}">{{album.display_name}}</a></div>
{% endfor %}
</div>
</body>

View file

@ -181,7 +181,7 @@
<h4>Albums containing this photo</h4>
<ul id="containing albums">
{% for album in albums %}
<li><a href="/album/{{album.id}}">{{album.title}}</a></li>
<li><a href="/album/{{album.id}}">{{album.display_name}}</a></li>
{% endfor %}
{% endif %}
</ul>