using batch filter instead of modulus if statement
This commit is contained in:
parent
ef20bb2200
commit
18fe53559b
21
main.py
21
main.py
@ -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)
|
||||
|
||||
|
@ -4,14 +4,21 @@
|
||||
{% block title %}art{% endblock %}
|
||||
|
||||
{% 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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user