Skip to content

Commit

Permalink
Moving the Flask templates from
Browse files Browse the repository at this point in the history
https://github.com/google/tech-exchange-sds-student
to a new forkable repository of their own
  • Loading branch information
minh-t-nguyen committed Mar 10, 2022
1 parent c6e16e7 commit c98482a
Show file tree
Hide file tree
Showing 25 changed files with 669 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# tech-exchange-sds-templates
# Tech Exchange Software Development Studio Templates

Clone this repository to get started building flask applications.

There are two subdirectories:

* [Flask Template](flask-template/): A simple Flask template
* [Flask + MongoDB Template](flask-mongo-template): A Flask + MongoDB template
1 change: 1 addition & 0 deletions flask-mongo-template/.flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLASK_DEBUG=1
140 changes: 140 additions & 0 deletions flask-mongo-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Many thanks to the GitHub team

# 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/
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
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# 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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
1 change: 1 addition & 0 deletions flask-mongo-template/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app
52 changes: 52 additions & 0 deletions flask-mongo-template/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ---- YOUR APP STARTS HERE ----
# -- Import section --
from flask import Flask
from flask import render_template
from flask import request, redirect
from seed_library import seed_books
from flask_pymongo import PyMongo
from model import genres

# -- Initialization section --
app = Flask(__name__)

# name of database
app.config['MONGO_DBNAME'] = 'database'

# URI of database
app.config['MONGO_URI'] = "mongodb+srv://feedbackLoop:[email protected]/database?retryWrites=true&w=majority"

#Initialize PyMongo
mongo = PyMongo(app)

# Comment out this create_collection method after you run the app for the first time
# mongo.db.create_collection('library')

# -- Routes section --
# INDEX Route
@app.route('/')
@app.route('/index')
def index():
books = []
return render_template('index.html', books = books)


# NEW BOOK Route
@app.route('/new')
def new_book():
return render_template('new_book.html', genres = genres)

16 changes: 16 additions & 0 deletions flask-mongo-template/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# master list of genres
genres = ["comedy","crime","fantasy","romance","science-fiction","speculative-fiction","literature","non-fiction"]
3 changes: 3 additions & 0 deletions flask-mongo-template/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Flask + MongoDB Template

Clone this repository to get started building a Flask app with a MongoDB database.
4 changes: 4 additions & 0 deletions flask-mongo-template/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Flask==2.0.2
gunicorn==19.9.0
flask-pymongo==3.12.1
dnspython==2.1.0
2 changes: 2 additions & 0 deletions flask-mongo-template/run-variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export FLASK_APP=app.py
export FLASK_DEBUG=1
1 change: 1 addition & 0 deletions flask-mongo-template/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.7
21 changes: 21 additions & 0 deletions flask-mongo-template/seed_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#list of books for local database
seed_books = [
{"title":"The Fifth Season", "author":"N.K Jemisin", "genre":"fantasy", "publication":2015},
{"title":"Annihilation", "author":"Jeff VanderMeer", "genre":"science-fiction", "publication":2014},
{"title":"Ancillary Justics", "author":"Ann Leckie", "genre":"science-fiction", "publication":2013},
{"title":"Oryx and Crake", "author":"Margaret Atwood", "genre":"speculative-fiction", "publication":2003},
]
16 changes: 16 additions & 0 deletions flask-mongo-template/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

34 changes: 34 additions & 0 deletions flask-mongo-template/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!doctype html>
<!--
Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html>
<head>
<title>Book Recommendations</title>
</head>
<body>

<h1>Recommendations</h1>
<div class="book-list">
<ul>
{% for book in books %}
<li>{{ book.title }} by {{ book.author }}</li>
{% endfor %}
</ul>
</div>

</body>
</html>
45 changes: 45 additions & 0 deletions flask-mongo-template/templates/new_book.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!doctype html>
<!--
Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html>
<head>
<title>Submit a Recommendation!</title>
</head>
<body>
<h1>Submit a Recommendation!</h1>
<form method="post" action="/new">
<label for="title">Title:</label>
<input type="text" name="title" value="">

<label for="author">Author:</label>
<input type="text" name="author" value="">

<label for="genre">Genre:</label>
<select id="genre" name="genre">
{% for genre in genres%}
<option value='{{genre}}'>{{ genre }}</option>
{% endfor %}
</select>

<label for="publication">Year of Publication:</label>
<input type="number" name="publication" value="">

<input type="submit" value="Submit">
</form>
<p><a href="/">Cancel</a></p>
</body>
</html>
1 change: 1 addition & 0 deletions flask-template/.flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLASK_DEBUG=1
Loading

0 comments on commit c98482a

Please sign in to comment.