begin to start app backend

This commit is contained in:
Xevion
2020-08-01 16:29:04 -05:00
parent aab24d486d
commit dadaa3b5ee
408 changed files with 91 additions and 0 deletions

12
requirements.txt Normal file
View File

@@ -0,0 +1,12 @@
Flask~=1.1.2
python-dotenv~=0.14.0
libsass~=0.20.0
gunicorn~=20.0.4
Flask-WTF~=0.14.3
# flask-sqlalchemy~=2.4.4
# psycopg2~=2.8.5
# Flask-Migrate~=2.5.3
# SQLAlchemy~=1.3.18
# alembic~=1.4.2
click~=7.1.2
Werkzeug~=1.0.1

79
the_office/create_app.py Normal file
View File

@@ -0,0 +1,79 @@
"""
create_app.py
The create_app function used to create and initialize the app with all of it's extensions and settings.
"""
from flask import Flask, render_template
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_wtf.csrf import CSRFProtect
from sassutils.wsgi import SassMiddleware
from werkzeug.exceptions import HTTPException
from flask_static_digest import FlaskStaticDigest
from the_office.config import configs
# flask_static_digest = FlaskStaticDigest()
db = SQLAlchemy()
csrf = CSRFProtect()
migrate = Migrate()
def create_app(env=None):
"""
The create_app function used to create and initialize the app with all of it's extensions and settings.
"""
app = Flask(__name__)
# Add Sass middleware (black magic)
app.wsgi_app = SassMiddleware(app.wsgi_app, {
'unimatch': ('static/sass', 'static/css', '/static/css', False)
})
# Load configuration values
if not env:
env = app.config['ENV']
app.config.from_object(configs[env])
# Fixes poor whitespace rendering in templates
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
# Initialize Flask extensions
db.init_app(app)
csrf.init_app(app)
migrate.init_app(app, db)
# flask_static_digest.init_app(app)
# CLI commands setup
@app.shell_context_processor
def shell_context():
"""Provides specific Flask components to the shell."""
return {'app': app, 'db': db}
# Custom error handler page (all errors)
@app.errorhandler(HTTPException)
def handle_exception(e):
"""Error handler, sends users to a custom error page template."""
return render_template('error.html', exception=e), e.code
@app.context_processor
def inject_debug():
"""
Allows for testing for debug mode in jinja2 templates.
"""
return dict(debug=app.debug)
# noinspection PyUnresolvedReferences
from unimatch import models
with app.app_context():
db.create_all()
# noinspection PyUnresolvedReferences
from unimatch import routes
# Register custom commands
from unimatch import commands
app.cli.add_command(commands.load_colleges)
return app

Some files were not shown because too many files have changed in this diff Show More