From c8b6d4398d7eead6677fa54d25bca275e6fbdedf Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 19 Feb 2019 14:11:06 +0000 Subject: [PATCH] databased art displaying by tag working --- main.py | 25 +++++++++++++++++++++---- templates/art.html | 12 +++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) 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.name }}

+ {% if tag.description %}

{{ tag.description }}

{% endif %} +
+ {% for row in tag.images|batch(3) %}
{% for image in row %} {#{% if loop.index0 % 3 == 0 %}
{% endif %}#} @@ -20,5 +22,5 @@
{% endfor %} -{#{% endfor %}#} +{% endfor %} {% endblock %}