databased art displaying by tag working
This commit is contained in:
parent
18fe53559b
commit
c8b6d4398d
23
main.py
23
main.py
@ -19,14 +19,31 @@ def music():
|
||||
@app.route('/art')
|
||||
def art():
|
||||
art_collection = db.collection(u'art')
|
||||
#art_tags_collection = db.collection(u'art_tags')
|
||||
art_tags_collection = db.collection(u'art_tags')
|
||||
|
||||
try:
|
||||
pics = art_collection.get()
|
||||
#tags = art_tags_collection.get()
|
||||
tags = art_tags_collection.get()
|
||||
except google.cloud.exceptions.NotFound:
|
||||
return 'no such document'
|
||||
|
||||
sections = []
|
||||
|
||||
for tag in tags:
|
||||
tag_dict = tag.to_dict()
|
||||
query_ref = art_collection.where(u'tag', u'==', u'{}'.format(tag_dict['name']))
|
||||
query = query_ref.get()
|
||||
|
||||
image_list = []
|
||||
|
||||
for image in query:
|
||||
image_list.append(image.to_dict())
|
||||
|
||||
#sections.append({tag_dict['name']: image_list})
|
||||
sections.append({'images': image_list, 'name': tag_dict['name'], 'description': tag_dict['description'], 'index': tag_dict['index']})
|
||||
|
||||
print(sections[0])
|
||||
|
||||
#categories = []
|
||||
#for tag in tags:
|
||||
#taglist = {
|
||||
@ -43,7 +60,7 @@ def art():
|
||||
images.append(doc.to_dict())
|
||||
#categories[categories.index(image['tag'])].append(image)
|
||||
|
||||
return render_template('art.html', staticroot = staticbucketurl, images=images)
|
||||
return render_template('art.html', staticroot = staticbucketurl, images=images, tags=sections)
|
||||
|
||||
@app.route('/dev')
|
||||
def dev():
|
||||
|
@ -4,10 +4,12 @@
|
||||
{% block title %}art{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{#{% for tag in tags %}#}
|
||||
|
||||
{% for row in images|batch(3) %}
|
||||
{% for tag in tags %}
|
||||
<div class="row">
|
||||
<h1 class="sectiontitle">{{ tag.name }}</h1>
|
||||
{% if tag.description %}<p>{{ tag.description }}</p>{% endif %}
|
||||
</div>
|
||||
{% for row in tag.images|batch(3) %}
|
||||
<div class="row">
|
||||
{% for image in row %}
|
||||
{#{% if loop.index0 % 3 == 0 %}<div class="row">{% endif %}#}
|
||||
@ -20,5 +22,5 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{#{% endfor %}#}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user