Add jinja_filters.py with bytestring.

This commit is contained in:
voussoir 2018-04-15 00:59:54 -07:00
parent 4fcb524211
commit c1fd863999
3 changed files with 13 additions and 2 deletions

View file

@ -9,6 +9,7 @@ from voussoirkit import bytestring
from voussoirkit import pathclass from voussoirkit import pathclass
from . import caching from . import caching
from . import jinja_filters
from . import jsonify from . import jsonify
from . import sessions from . import sessions
@ -31,6 +32,7 @@ site.config.update(
site.jinja_env.add_extension('jinja2.ext.do') site.jinja_env.add_extension('jinja2.ext.do')
site.jinja_env.trim_blocks = True 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.debug = True site.debug = True
P = etiquette.photodb.PhotoDB() P = etiquette.photodb.PhotoDB()

View file

@ -0,0 +1,9 @@
import etiquette
import voussoirkit.bytestring
def bytestring(x):
try:
return voussoirkit.bytestring.bytestring(x)
except Exception:
return '??? b'

View file

@ -108,13 +108,13 @@ p
Download: Download:
{% if has_local_photos %} {% if has_local_photos %}
<a href="/album/{{album.id}}.zip?recursive=no"> <a href="/album/{{album.id}}.zip?recursive=no">
These files ({{album.sum_bytes(recurse=False, string=True)}}) These files ({{album.sum_bytes(recurse=False)|bytestring }})
</a> </a>
{% endif %} {% endif %}
{% if has_local_photos and has_child_photos %}&mdash;{% endif %} {% if has_local_photos and has_child_photos %}&mdash;{% endif %}
{% if has_child_photos %} {% if has_child_photos %}
<a href="/album/{{album.id}}.zip?recursive=yes"> <a href="/album/{{album.id}}.zip?recursive=yes">
Include children ({{album.sum_bytes(recurse=True, string=True)}}) Include children ({{album.sum_bytes(recurse=True)|bytestring }})
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}