diff --git a/main.py b/main.py index 11a53a3..43c704e 100644 --- a/main.py +++ b/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(): diff --git a/templates/art.html b/templates/art.html index d767325..55045d3 100644 --- a/templates/art.html +++ b/templates/art.html @@ -4,10 +4,12 @@ {% block title %}art{% endblock %} {% block content %} - -{#{% for tag in tags %}#} - - {% for row in images|batch(3) %} +{% for tag in tags %} +
{{ tag.description }}
{% endif %} +