Return more sets from backend, do sorting on frontend.

It's better semantically for these items coming out of the backend
to be sets. Sorted lists are only relevant to human consumption at the
frontend.
master
voussoir 2020-09-20 13:16:52 -07:00
parent 317fa3b51d
commit f56da72881
4 changed files with 6 additions and 17 deletions

View File

@ -172,12 +172,7 @@ class GroupableMixin(metaclass=abc.ABCMeta):
[self.id] [self.id]
) )
child_ids = [row[0] for row in child_rows] child_ids = [row[0] for row in child_rows]
children = self.group_getter_many(child_ids) children = set(self.group_getter_many(child_ids))
if isinstance(self, Tag):
children = sorted(children, key=lambda x: x.name)
else:
children = sorted(children, key=lambda x: x.id)
return children return children
def get_parents(self): def get_parents(self):
@ -417,8 +412,8 @@ class Album(ObjectBase, GroupableMixin):
'SELECT directory FROM album_associated_directories WHERE albumid == ?', 'SELECT directory FROM album_associated_directories WHERE albumid == ?',
[self.id] [self.id]
) )
directories = [x[0] for x in directory_rows] directories = (x[0] for x in directory_rows)
directories = [pathclass.Path(x) for x in directories] directories = set(pathclass.Path(x) for x in directories)
return directories return directories
def get_photos(self): def get_photos(self):
@ -428,8 +423,7 @@ class Album(ObjectBase, GroupableMixin):
[self.id] [self.id]
) )
photo_ids = [row[0] for row in generator] photo_ids = [row[0] for row in generator]
photos = self.photodb.get_photos_by_id(photo_ids) photos = set(self.photodb.get_photos_by_id(photo_ids))
photos = sorted(photos, key=lambda x: x.basename.lower())
return photos return photos
def has_any_associated_directory(self): def has_any_associated_directory(self):

View File

@ -43,11 +43,6 @@ def file_link(photo, short=False):
basename = jinja2.filters.do_urlencode(photo.basename) basename = jinja2.filters.do_urlencode(photo.basename)
return f'/file/{photo.id}/{basename}' return f'/file/{photo.id}/{basename}'
@filter_function
def sort_tags(tags):
tags = sorted(tags, key=lambda x: x.name)
return tags
@filter_function @filter_function
def timestamp_to_8601(timestamp): def timestamp_to_8601(timestamp):
return datetime.datetime.utcfromtimestamp(timestamp).isoformat(' ') + ' UTC' return datetime.datetime.utcfromtimestamp(timestamp).isoformat(' ') + ' UTC'

View File

@ -256,7 +256,7 @@ const ALBUM_ID = undefined;
<div id="hierarchy_photos" class="panel"> <div id="hierarchy_photos" class="panel">
<h3>{{photos|length}} Photos</h3> <h3>{{photos|length}} Photos</h3>
<div id="photo_list"> <div id="photo_list">
{% for photo in photos %} {% for photo in photos|sort(attribute='basename', case_sensitive=False) %}
{{photo_card.create_photo_card(photo, view=view)}} {{photo_card.create_photo_card(photo, view=view)}}
{% endfor %} {% endfor %}
</div> </div>

View File

@ -143,7 +143,7 @@
<input type="text" id="add_tag_textbox" class="entry_with_history entry_with_tagname_replacements" list="tag_autocomplete_datalist"> <input type="text" id="add_tag_textbox" class="entry_with_history entry_with_tagname_replacements" list="tag_autocomplete_datalist">
<button id="add_tag_button" class="green_button" onclick="return add_photo_tag_form();">add</button> <button id="add_tag_button" class="green_button" onclick="return add_photo_tag_form();">add</button>
</li> </li>
{% set tags = photo.get_tags()|sort_tags %} {% set tags = photo.get_tags()|sort(attribute='name') %}
{% for tag in tags %} {% for tag in tags %}
<li> <li>
{{tag_object.tag_object(tag, with_alt_description=True)}}<!-- {{tag_object.tag_object(tag, with_alt_description=True)}}<!--