Replace Photo.sorted_tags with jinja filter.

This commit is contained in:
voussoir 2018-04-28 19:05:51 -07:00
parent 50592f0ab4
commit b19682d1a5
4 changed files with 6 additions and 6 deletions

View file

@ -1155,11 +1155,6 @@ class Photo(ObjectBase):
self.__reinit__() self.__reinit__()
def sorted_tags(self):
tags = self.get_tags()
tags.sort(key=lambda x: x.qualified_name())
return tags
class Tag(ObjectBase, GroupableMixin): class Tag(ObjectBase, GroupableMixin):
''' '''

View file

@ -34,6 +34,7 @@ site.jinja_env.trim_blocks = True
site.jinja_env.lstrip_blocks = True site.jinja_env.lstrip_blocks = True
site.jinja_env.filters['bytestring'] = jinja_filters.bytestring site.jinja_env.filters['bytestring'] = jinja_filters.bytestring
site.jinja_env.filters['file_link'] = jinja_filters.file_link site.jinja_env.filters['file_link'] = jinja_filters.file_link
site.jinja_env.filters['sort_by_qualname'] = jinja_filters.sort_by_qualname
site.debug = True site.debug = True
P = etiquette.photodb.PhotoDB() P = etiquette.photodb.PhotoDB()

View file

@ -14,3 +14,7 @@ def file_link(photo, short=False):
return f'/file/{photo.id}{photo.dot_extension}' return f'/file/{photo.id}{photo.dot_extension}'
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}'
def sort_by_qualname(tags):
tags = sorted(tags, key=lambda x: x.qualified_name())
return tags

View file

@ -163,7 +163,7 @@
<input id="add_tag_textbox" type="text" autofocus> <input id="add_tag_textbox" type="text" autofocus>
<button id="add_tag_button" class="green_button" onclick="submit_tag(receive_callback);">add</button> <button id="add_tag_button" class="green_button" onclick="submit_tag(receive_callback);">add</button>
</li> </li>
{% set tags = photo.sorted_tags() %} {% set tags = photo.get_tags()|sort_by_qualname %}
{% for tag in tags %} {% for tag in tags %}
<li> <li>
{{tag_object.tag_object(tag, qualified_name=True, max_len=30, with_alt_description=True, with_alt_qualified_name=True)}}<!-- {{tag_object.tag_object(tag, qualified_name=True, max_len=30, with_alt_description=True, with_alt_qualified_name=True)}}<!--