2020-03-23 13:57:19 -04:00
|
|
|
import os
|
2020-05-25 15:21:29 -04:00
|
|
|
import yaml
|
2020-02-17 11:43:26 -05:00
|
|
|
|
2020-01-08 15:57:00 -05:00
|
|
|
import connexion
|
2020-05-25 15:21:29 -04:00
|
|
|
from flask_cors import CORS
|
2020-02-26 12:17:37 -05:00
|
|
|
from flask_assets import Environment, Bundle
|
2020-02-17 16:21:18 -05:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
from flask_marshmallow import Marshmallow
|
2020-02-17 11:43:26 -05:00
|
|
|
from flask_migrate import Migrate
|
2020-01-08 15:57:00 -05:00
|
|
|
|
|
|
|
PROTOCOLS = {}
|
|
|
|
|
|
|
|
|
2020-05-25 15:21:29 -04:00
|
|
|
connexion_app = connexion.FlaskApp('Protocol Builder', specification_dir='pb')
|
|
|
|
app = connexion_app.app
|
2020-01-08 15:57:00 -05:00
|
|
|
|
2020-03-23 13:57:19 -04:00
|
|
|
app.config.from_object('config.default')
|
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
|
|
|
|
if "TESTING" in os.environ and os.environ["TESTING"] == "true":
|
|
|
|
app.config.from_object('config.testing')
|
2020-03-23 17:05:34 -04:00
|
|
|
app.config.from_pyfile('config/testing.py')
|
2020-03-23 13:57:19 -04:00
|
|
|
else:
|
|
|
|
app.config.root_path = app.instance_path
|
|
|
|
app.config.from_pyfile('config.py', silent=True)
|
|
|
|
|
2020-05-25 15:21:29 -04:00
|
|
|
# Convert list of allowed origins to list of regexes
|
|
|
|
origins_re = [r"^https?:\/\/%s(.*)" % o.replace('.', '\.') for o in app.config['CORS_ALLOW_ORIGINS']]
|
|
|
|
cors = CORS(connexion_app.app, origins=origins_re)
|
|
|
|
|
2020-02-14 15:19:30 -05:00
|
|
|
db = SQLAlchemy(app)
|
2020-08-12 19:15:16 -04:00
|
|
|
""":type: sqlalchemy.orm.SQLAlchemy"""
|
|
|
|
|
|
|
|
session = db.session
|
|
|
|
""":type: sqlalchemy.orm.Session"""
|
|
|
|
|
2020-02-17 11:43:26 -05:00
|
|
|
migrate = Migrate(app, db)
|
2020-02-17 16:21:18 -05:00
|
|
|
ma = Marshmallow(app)
|
2020-05-24 23:05:57 -04:00
|
|
|
|
2021-04-09 10:00:24 -04:00
|
|
|
connexion_app.add_api('api.yml', base_path='/v2.0')
|
|
|
|
|
2020-05-24 23:05:57 -04:00
|
|
|
# Set the path of the static directory
|
|
|
|
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
APP_STATIC = os.path.join(APP_ROOT, 'static')
|
|
|
|
BASE_HREF = app.config['APPLICATION_ROOT'].strip('/')
|
|
|
|
app.static_folder = APP_STATIC
|
|
|
|
app.static_url_path = app.config['APPLICATION_ROOT'] + 'static'
|
|
|
|
|
|
|
|
print('app.static_folder', app.static_folder)
|
|
|
|
print('app.static_url_path', app.static_url_path)
|
|
|
|
|
2020-02-26 12:17:37 -05:00
|
|
|
assets = Environment(app)
|
2020-05-24 23:05:57 -04:00
|
|
|
assets.init_app(app)
|
2020-02-26 12:17:37 -05:00
|
|
|
assets.url = app.static_url_path
|
2020-05-24 23:05:57 -04:00
|
|
|
scss = Bundle(
|
|
|
|
'scss/app.scss',
|
|
|
|
filters='pyscss',
|
|
|
|
output='app.css'
|
|
|
|
)
|
2020-02-26 12:17:37 -05:00
|
|
|
assets.register('app_scss', scss)
|
2020-02-17 16:21:18 -05:00
|
|
|
|
2020-02-18 09:25:29 -05:00
|
|
|
# Loads all the descriptions from the API so we can display them in the editor.
|
2020-02-17 16:21:18 -05:00
|
|
|
description_map = {}
|
2020-05-24 18:30:57 -04:00
|
|
|
with open(r'pb/api.yml') as file:
|
2020-02-17 16:21:18 -05:00
|
|
|
api_config = yaml.load(file, Loader=yaml.FullLoader)
|
|
|
|
study_detail_properties = api_config['components']['schemas']['StudyDetail']['properties']
|
|
|
|
for schema in api_config['components']['schemas']:
|
|
|
|
for field, values in api_config['components']['schemas'][schema]['properties'].items():
|
|
|
|
description_map[field] = values['description']
|
2020-01-08 15:57:00 -05:00
|
|
|
|
2020-02-17 16:21:18 -05:00
|
|
|
|
|
|
|
# **************************
|
2021-05-12 11:54:46 -04:00
|
|
|
# LOAD ROUTES
|
2020-02-17 16:21:18 -05:00
|
|
|
# **************************
|
2021-05-12 11:54:46 -04:00
|
|
|
import pb.routes
|
|
|
|
|
2020-01-08 15:57:00 -05:00
|
|
|
|
2021-05-12 11:54:46 -04:00
|
|
|
# **************************
|
|
|
|
# FLASK COMMANDS
|
|
|
|
# **************************
|
2020-04-17 11:27:12 -04:00
|
|
|
|
2020-08-12 19:15:16 -04:00
|
|
|
@app.cli.command()
|
|
|
|
def load_example_data():
|
|
|
|
"""Load example data into the database."""
|
|
|
|
from example_data import ExampleDataLoader
|
|
|
|
ExampleDataLoader().clean_db()
|
|
|
|
ExampleDataLoader().load_all()
|
|
|
|
|
|
|
|
|
|
|
|
@app.cli.command()
|
|
|
|
def load_example_sponsors():
|
|
|
|
"""Load example data into the database."""
|
|
|
|
from example_data import ExampleDataLoader
|
|
|
|
ExampleDataLoader().load_sponsors()
|
|
|
|
|
2020-01-08 16:05:16 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
# run our standalone gevent server
|
2020-02-26 12:17:37 -05:00
|
|
|
app.run(port=4200)
|