adding firestore

This commit is contained in:
aj 2019-02-18 23:20:19 +00:00
parent 8dff201bde
commit 3819a02bfc
4 changed files with 32 additions and 55 deletions

View File

@ -17,3 +17,5 @@
__pycache__/
# Ignored by the build system
/setup.cfg
env

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
env

20
main.py
View File

@ -1,7 +1,12 @@
from flask import Flask, render_template
from google.cloud import firestore
# Project ID is determined by the GCLOUD_PROJECT environment variable
db = firestore.Client()
app = Flask(__name__)
staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
@app.route('/')
def main():
@ -13,13 +18,24 @@ def music():
@app.route('/art')
def art():
return render_template('art.html')
art_collection = db.collection(u'art')
try:
docs = art_collection.get()
except google.cloud.exceptions.NotFound:
return 'no such document'
images = []
for doc in docs:
image = doc.to_dict()
images.append(image)
return render_template('art.html', staticroot = staticbucketurl, images=images)
@app.route('/dev')
def dev():
return render_template('dev.html')
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
# [END gae_python37_app]

View File

@ -1,59 +1,17 @@
{% extends 'base.html' %}
{% block title %}art{% endblock %}
{% block content %}
<div class="row">
<h1 class="sectiontitle">portraits</h1>
</div>
<div class="row">
{% for image in images %}
{% if loop.index0 % 3 == 0 %}<div class="row">{% endif %}
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/freddie.jpg') }}" alt="freddie gibbs" class="col-pad-4">
<p><b>freddie gibbs / piñata</b></p>
<img src="{{ staticroot }}art/{{ image.file_name }}.jpg" alt="{{ image.file_name }}" class="col-pad-4">
<p><b>{{ image.description }}</b></p>
</div>
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/self.jpg') }}" alt="me" class="col-pad-4">
<p><b>self portrait</b></p>
</div>
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/tyler.jpg') }}" alt="tyler, the creator" class="col-pad-4">
<p><b>tyler, the creator</b></p>
</div>
</div>
<div class="row">
<h1 class="sectiontitle">animals</h1>
</div>
<div class="row">
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/gorilla.jpg') }}" alt="gorilla" class="col-pad-4">
<p><b>gorilla</b></p>
</div>
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/zu.jpg') }}" alt="zuma" class="col-pad-4">
<p><b>zuma</b></p>
</div>
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/horse.jpg') }}" alt="temptation of saint anthony" class="col-pad-4">
<p><b>the temptation of saint anthony / salvador dalí</b></p>
</div>
</div>
<div class="row">
<h1 class="sectiontitle">life drawing</h1>
</div>
<div class="row">
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/brownstilllife.jpg') }}" alt="brown" class="col-pad-4">
<p><b>white and brown</b></p>
</div>
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/outlinestilllife.jpg') }}" alt="outline" class="col-pad-4">
<p><b>minimal outline</b></p>
</div>
<div class="card col-pad-4">
<img src="{{ url_for('static', filename='art/redandbluestilllife.jpg') }}" alt="red and blue" class="col-pad-4">
<p><b>red and blue</b></p>
</div>
</div>
{% if loop.index % 3 == 0 or loop.last %}</div>{% endif %}
{% endfor %}
{% endblock %}