migrated art to blueprint
This commit is contained in:
parent
3e1fa1863d
commit
3b2815c87e
1
sarsoo/art/__init__.py
Normal file
1
sarsoo/art/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .art import art_print
|
30
sarsoo/art/art.py
Normal file
30
sarsoo/art/art.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from flask import Blueprint, render_template, abort
|
||||||
|
from jinja2 import TemplateNotFound
|
||||||
|
|
||||||
|
from google.cloud import firestore
|
||||||
|
|
||||||
|
from .db import getTagDicts, getPopulatedTagDict, getPopulatedTagDicts
|
||||||
|
|
||||||
|
staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
|
||||||
|
urlprefix = 'art'
|
||||||
|
|
||||||
|
art_print = Blueprint('art', __name__, template_folder='templates')
|
||||||
|
#db = firestore.Client()
|
||||||
|
|
||||||
|
@art_print.route('/')
|
||||||
|
def root():
|
||||||
|
tags = getTagDicts()
|
||||||
|
print(tags)
|
||||||
|
return render_template('art/index.html', tags = tags, urlprefix = urlprefix)
|
||||||
|
|
||||||
|
@art_print.route('/<tag>')
|
||||||
|
def tag_view(tag):
|
||||||
|
tags = getPopulatedTagDict(tag)
|
||||||
|
return render_template('art/all.html', staticroot = staticbucketurl, tags = [tags])
|
||||||
|
|
||||||
|
@art_print.route('/all')
|
||||||
|
def all():
|
||||||
|
|
||||||
|
sections = getPopulatedTagDicts()
|
||||||
|
|
||||||
|
return render_template('art/all.html', staticroot = staticbucketurl, tags=sections)
|
45
sarsoo/art/db.py
Normal file
45
sarsoo/art/db.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from google.cloud import firestore
|
||||||
|
|
||||||
|
staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
|
||||||
|
|
||||||
|
fs = firestore.Client()
|
||||||
|
|
||||||
|
def getTagDicts():
|
||||||
|
|
||||||
|
art_tags_collection = fs.collection(u'art_tags')
|
||||||
|
|
||||||
|
try:
|
||||||
|
tags = art_tags_collection.get()
|
||||||
|
except google.cloud.exceptions.NotFound:
|
||||||
|
return 'no such document'
|
||||||
|
|
||||||
|
dicts = []
|
||||||
|
for tag in tags:
|
||||||
|
dicts.append(tag.to_dict())
|
||||||
|
|
||||||
|
return dicts
|
||||||
|
|
||||||
|
def getPopulatedTagDict(name):
|
||||||
|
|
||||||
|
name_doc = fs.document(u'art_tags/{}'.format(name))
|
||||||
|
|
||||||
|
tag_dicts = name_doc.get().to_dict()
|
||||||
|
|
||||||
|
image_list = []
|
||||||
|
for image in tag_dicts['art']:
|
||||||
|
image_list.append(image.get().to_dict())
|
||||||
|
tag_dicts['images'] = image_list
|
||||||
|
|
||||||
|
return tag_dicts
|
||||||
|
|
||||||
|
def getPopulatedTagDicts():
|
||||||
|
|
||||||
|
tag_dicts = getTagDicts()
|
||||||
|
|
||||||
|
for tag in tag_dicts:
|
||||||
|
image_list = []
|
||||||
|
for image in tag['art']:
|
||||||
|
image_list.append(image.get().to_dict())
|
||||||
|
tag['images'] = image_list
|
||||||
|
|
||||||
|
return tag_dicts
|
17
sarsoo/art/templates/art/index.html
Normal file
17
sarsoo/art/templates/art/index.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}dev{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% for row in tags|batch(2) %}
|
||||||
|
<div class="row">
|
||||||
|
{% for tag in row %}
|
||||||
|
<div class="col-pad-6 card">
|
||||||
|
<h1>{{ tag.name }}</h1>
|
||||||
|
<p>{{ tag.description }}</p>
|
||||||
|
<a href="/{{ urlprefix }}/{{ tag.doc_name }}" style="width:100%;" class="button">view</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
@ -2,11 +2,15 @@ from flask import Flask, render_template
|
|||||||
from google.cloud import firestore
|
from google.cloud import firestore
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from .art import art_print
|
||||||
|
|
||||||
# Project ID is determined by the GCLOUD_PROJECT environment variable
|
# Project ID is determined by the GCLOUD_PROJECT environment variable
|
||||||
db = firestore.Client()
|
db = firestore.Client()
|
||||||
|
|
||||||
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'), template_folder = "templates")
|
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'), template_folder = "templates")
|
||||||
|
|
||||||
|
app.register_blueprint(art_print, url_prefix='/art')
|
||||||
|
|
||||||
staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
|
staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@ -30,33 +34,6 @@ def main():
|
|||||||
def music():
|
def music():
|
||||||
return render_template('music.html')
|
return render_template('music.html')
|
||||||
|
|
||||||
@app.route('/art')
|
|
||||||
def art():
|
|
||||||
art_collection = db.collection(u'art')
|
|
||||||
art_tags_collection = db.collection(u'art_tags')
|
|
||||||
|
|
||||||
try:
|
|
||||||
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']})
|
|
||||||
|
|
||||||
return render_template('art.html', staticroot = staticbucketurl, tags=sections)
|
|
||||||
|
|
||||||
@app.route('/dev')
|
@app.route('/dev')
|
||||||
def dev():
|
def dev():
|
||||||
return render_template('dev.html')
|
return render_template('dev.html')
|
||||||
|
Loading…
Reference in New Issue
Block a user