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')
|
@app.route('/art')
|
||||||
def art():
|
def art():
|
||||||
art_collection = db.collection(u'art')
|
art_collection = db.collection(u'art')
|
||||||
#art_tags_collection = db.collection(u'art_tags')
|
art_tags_collection = db.collection(u'art_tags')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pics = art_collection.get()
|
pics = art_collection.get()
|
||||||
#tags = art_tags_collection.get()
|
tags = art_tags_collection.get()
|
||||||
except google.cloud.exceptions.NotFound:
|
except google.cloud.exceptions.NotFound:
|
||||||
return 'no such document'
|
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 = []
|
#categories = []
|
||||||
#for tag in tags:
|
#for tag in tags:
|
||||||
#taglist = {
|
#taglist = {
|
||||||
@ -43,7 +60,7 @@ def art():
|
|||||||
images.append(doc.to_dict())
|
images.append(doc.to_dict())
|
||||||
#categories[categories.index(image['tag'])].append(image)
|
#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')
|
@app.route('/dev')
|
||||||
def dev():
|
def dev():
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
{% block title %}art{% endblock %}
|
{% block title %}art{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% for tag in tags %}
|
||||||
{#{% for tag in tags %}#}
|
<div class="row">
|
||||||
|
<h1 class="sectiontitle">{{ tag.name }}</h1>
|
||||||
{% for row in images|batch(3) %}
|
{% if tag.description %}<p>{{ tag.description }}</p>{% endif %}
|
||||||
|
</div>
|
||||||
|
{% for row in tag.images|batch(3) %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for image in row %}
|
{% for image in row %}
|
||||||
{#{% if loop.index0 % 3 == 0 %}<div class="row">{% endif %}#}
|
{#{% if loop.index0 % 3 == 0 %}<div class="row">{% endif %}#}
|
||||||
@ -20,5 +22,5 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{#{% endfor %}#}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user