From 3e1fa1863d4980ff9136ff984d39d49f3ca8f6a0 Mon Sep 17 00:00:00 2001 From: aj Date: Thu, 21 Feb 2019 20:47:12 +0000 Subject: [PATCH] initial blueprint layout change --- .gitignore | 117 ++++++++++++++++++++- main.py | 65 +----------- sarsoo/__init__.py | 1 + sarsoo/sarsoo.py | 66 ++++++++++++ {templates => sarsoo/templates}/art.html | 0 {templates => sarsoo/templates}/base.html | 0 {templates => sarsoo/templates}/dev.html | 0 {templates => sarsoo/templates}/index.html | 0 {templates => sarsoo/templates}/music.html | 0 9 files changed, 186 insertions(+), 63 deletions(-) create mode 100644 sarsoo/__init__.py create mode 100644 sarsoo/sarsoo.py rename {templates => sarsoo/templates}/art.html (100%) rename {templates => sarsoo/templates}/base.html (100%) rename {templates => sarsoo/templates}/dev.html (100%) rename {templates => sarsoo/templates}/index.html (100%) rename {templates => sarsoo/templates}/music.html (100%) diff --git a/.gitignore b/.gitignore index 0a764a4..ed464f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,116 @@ -env +# Byte-compiled / optimized / DLL files +*/__pycache__/* +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/main.py b/main.py index e4e4e7c..9fc8d31 100644 --- a/main.py +++ b/main.py @@ -1,65 +1,6 @@ -from flask import Flask, render_template -from google.cloud import firestore +from sarsoo import app -# 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(): - - index_doc = db.collection(u'pages').document(u'index') - doc = index_doc.get() - index_dict = doc.to_dict() - - splashtext = index_dict['splash_text'] - - art = [] - for image in index_dict['art']: - art.append(image.get().to_dict()) - - print(index_dict['art'][0].get().to_dict()) - - return render_template('index.html', staticroot = staticbucketurl, splash = splashtext, art=art) - -@app.route('/music') -def music(): - 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') -def dev(): - return render_template('dev.html') +app = app if __name__ == '__main__': - app.run(host='127.0.0.1', port=8080, debug=True) -# [END gae_python37_app] + app.run() diff --git a/sarsoo/__init__.py b/sarsoo/__init__.py new file mode 100644 index 0000000..baab4a9 --- /dev/null +++ b/sarsoo/__init__.py @@ -0,0 +1 @@ +from .sarsoo import app diff --git a/sarsoo/sarsoo.py b/sarsoo/sarsoo.py new file mode 100644 index 0000000..fce591d --- /dev/null +++ b/sarsoo/sarsoo.py @@ -0,0 +1,66 @@ +from flask import Flask, render_template +from google.cloud import firestore +import os + +# Project ID is determined by the GCLOUD_PROJECT environment variable +db = firestore.Client() + +app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'), template_folder = "templates") + +staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/' + +@app.route('/') +def main(): + + index_doc = db.collection(u'pages').document(u'index') + doc = index_doc.get() + index_dict = doc.to_dict() + + splashtext = index_dict['splash_text'] + + art = [] + for image in index_dict['art']: + art.append(image.get().to_dict()) + + print(index_dict['art'][0].get().to_dict()) + + return render_template('index.html', staticroot = staticbucketurl, splash = splashtext, art=art) + +@app.route('/music') +def music(): + 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') +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] diff --git a/templates/art.html b/sarsoo/templates/art.html similarity index 100% rename from templates/art.html rename to sarsoo/templates/art.html diff --git a/templates/base.html b/sarsoo/templates/base.html similarity index 100% rename from templates/base.html rename to sarsoo/templates/base.html diff --git a/templates/dev.html b/sarsoo/templates/dev.html similarity index 100% rename from templates/dev.html rename to sarsoo/templates/dev.html diff --git a/templates/index.html b/sarsoo/templates/index.html similarity index 100% rename from templates/index.html rename to sarsoo/templates/index.html diff --git a/templates/music.html b/sarsoo/templates/music.html similarity index 100% rename from templates/music.html rename to sarsoo/templates/music.html