diff --git a/app.py b/app.py index 93977a5..7e60efe 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ import datetime import os +import re from datetime import date import connexion @@ -54,8 +55,7 @@ else: app.config.root_path = app.instance_path app.config.from_pyfile('config.py', silent=True) -BASE_HREF = app.config['BASE_HREF'] -conn.add_api('api.yml', base_path=BASE_HREF + '/pb') +conn.add_api('api.yml', base_path=app.config['BASE_HREF'] + 'pb') db = SQLAlchemy(app) migrate = Migrate(app, db) ma = Marshmallow(app) @@ -83,7 +83,7 @@ def has_no_empty_params(rule): return len(defaults) >= len(arguments) -@app.route(BASE_HREF + '/site_map') +@app.route(app.config['BASE_HREF'] + '/site_map') def site_map(): links = [] for rule in app.url_map.iter_rules(): @@ -103,7 +103,7 @@ from models import Study, RequiredDocument, Investigator, StudySchema, RequiredD StudyDetails, StudyDetailsSchema -@app.route(BASE_HREF + '/', methods=['GET', 'POST']) +@app.route(app.config['BASE_HREF'] + '/', methods=['GET', 'POST']) def index(): # display results studies = db.session.query(Study).order_by(Study.DATE_MODIFIED.desc()).all() @@ -111,7 +111,7 @@ def index(): return render_template('index.html', table=table, BASE_HREF=app.config['BASE_HREF']) -@app.route(BASE_HREF + '/new_study', methods=['GET', 'POST']) +@app.route(app.config['BASE_HREF'] + '/new_study', methods=['GET', 'POST']) def new_study(): form = StudyForm(request.form) action = "/new_study" @@ -129,7 +129,7 @@ def new_study(): description_map=description_map) -@app.route(BASE_HREF + '/study/', methods=['GET', 'POST']) +@app.route(app.config['BASE_HREF'] + '/study/', methods=['GET', 'POST']) def edit_study(study_id): study = db.session.query(Study).filter(Study.STUDYID == study_id).first() form = StudyForm(request.form, obj=study) @@ -150,7 +150,7 @@ def edit_study(study_id): description_map={}) -@app.route(BASE_HREF + '/investigator/', methods=['GET', 'POST']) +@app.route(app.config['BASE_HREF'] + '/investigator/', methods=['GET', 'POST']) def new_investigator(study_id): form = InvestigatorForm(request.form) action = "/investigator/" + study_id @@ -170,14 +170,14 @@ def new_investigator(study_id): description_map={}) -@app.route(BASE_HREF + '/del_investigator/', methods=['GET']) +@app.route(app.config['BASE_HREF'] + '/del_investigator/', methods=['GET']) def del_investigator(inv_id): db.session.query(Investigator).filter(Investigator.id == inv_id).delete() db.session.commit() return redirect('/') -@app.route(BASE_HREF + '/del_study/', methods=['GET']) +@app.route(app.config['BASE_HREF'] + '/del_study/', methods=['GET']) def del_study(study_id): db.session.query(RequiredDocument).filter(RequiredDocument.STUDYID == study_id).delete() db.session.query(Investigator).filter(Investigator.STUDYID == study_id).delete() @@ -212,7 +212,7 @@ def _update_study(study, form): db.session.commit() -@app.route(BASE_HREF + '/study_details/', methods=['GET', 'POST']) +@app.route(app.config['BASE_HREF'] + '/study_details/', methods=['GET', 'POST']) def study_details(study_id): study_details = db.session.query(StudyDetails).filter(StudyDetails.STUDYID == study_id).first() if not study_details: diff --git a/config/default.py b/config/default.py index 3b70fbf..82e133d 100644 --- a/config/default.py +++ b/config/default.py @@ -1,3 +1,4 @@ +import re import os from os import environ @@ -8,7 +9,9 @@ FLASK_PORT = environ.get('PORT0') or environ.get('FLASK_PORT', default="5001") CORS_ENABLED = False DEVELOPMENT = environ.get('DEVELOPMENT', default="true") == "true" TESTING = environ.get('TESTING', default="false") == "true" -BASE_HREF = environ.get('BASE_HREF', default="/") + +# Add trailing slash to base path +BASE_HREF = re.sub(r'//', '/', '/%s/' % environ.get('BASE_HREF', default="/").strip('/')) DB_HOST = environ.get('DB_HOST', default="localhost") DB_PORT = environ.get('DB_PORT', default="5432") @@ -25,3 +28,4 @@ print('=== USING DEFAULT CONFIG: ===') print('DB_HOST = ', DB_HOST) print('DEVELOPMENT = ', DEVELOPMENT) print('TESTING = ', TESTING) +print('BASE_HREF = ', BASE_HREF)