using batch filter instead of modulus if statement

This commit is contained in:
aj 2019-02-19 11:52:25 +00:00
parent ef20bb2200
commit 18fe53559b
2 changed files with 29 additions and 9 deletions

21
main.py
View File

@ -19,16 +19,29 @@ def music():
@app.route('/art')
def art():
art_collection = db.collection(u'art')
#art_tags_collection = db.collection(u'art_tags')
try:
docs = art_collection.get()
pics = art_collection.get()
#tags = art_tags_collection.get()
except google.cloud.exceptions.NotFound:
return 'no such document'
#categories = []
#for tag in tags:
#taglist = {
#tag.to_dict()['name'] : []
#}
#print(tag.to_dict())
#categories.append(taglist)
#print(categories)
images = []
for doc in docs:
image = doc.to_dict()
images.append(image)
for doc in pics:
#image = doc.to_dict()
images.append(doc.to_dict())
#categories[categories.index(image['tag'])].append(image)
return render_template('art.html', staticroot = staticbucketurl, images=images)

View File

@ -5,13 +5,20 @@
{% block content %}
{% for image in images %}
{% if loop.index0 % 3 == 0 %}<div class="row">{% endif %}
{#{% for tag in tags %}#}
{% for row in images|batch(3) %}
<div class="row">
{% for image in row %}
{#{% if loop.index0 % 3 == 0 %}<div class="row">{% endif %}#}
<div class="card col-pad-4">
<img src="{{ staticroot }}art/{{ image.file_name }}.jpg" alt="{{ image.file_name }}" class="col-pad-4">
<p><b>{{ image.description }}</b></p>
</div>
{% if loop.index % 3 == 0 or loop.last %}</div>{% endif %}
{#{% if loop.index % 3 == 0 or loop.last %}</div>{% endif %}#}
{% endfor %}
</div>
{% endfor %}
{#{% endfor %}#}
{% endblock %}