예제 #1
0
from web.config import Config
from sqlalchemy.exc import DBAPIError

DEFAULT_ROUTE_AUTHENTICATED = "vehicles"
DEFAULT_ROUTE_NOT_AUTHENTICATED = "login_page"

# Initialize the app
app = Flask(__name__)
app.config.from_object(Config)
Bootstrap(app)
login = LoginManager(app)
protocol = ('https', 'http')[app.config.get('DEBUG') == 'True']

# Initialize the db connection
conn_string = app.config.get('DB_URI')
movr = MovR(conn_string)
region = app.config.get('REGION')
cities = app.config.get('CITY_MAP')[region]

# Update Bootstrap from v3.3.7 to v4.5
app.extensions['bootstrap']['cdns']['bootstrap'] = WebCDN(
    '//getbootstrap.com/docs/4.5/dist/')


# Define user_loader function for LoginManager
@login.user_loader
def load_user(user_id):
    return movr.get_user(user_id=user_id)


# ROUTES
예제 #2
0
_DEFAULT_ROUTE_AUTHENTICATED = "vehicles"
_DEFAULT_ROUTE_NOT_AUTHENTICATED = "login_page"

# Configure the app
app.config.from_object(Config)

if _URL is None:  # No --url flag; check for environment variable DB_URI
    environment_connection_string = app.config.get('DB_URI')
    CONNECTION_STRING = build_sqla_connection_string(
        environment_connection_string)
else:  # url was passed with `--url`
    CONNECTION_STRING = build_sqla_connection_string(_URL)
# Load environment variables from .env file

# Instantiate the movr object defined in movr/movr.py
movr = MovR(CONNECTION_STRING, max_records=_MAX_RECORDS)

app.extensions['bootstrap']['cdns']['bootstrap'] = WebCDN(
    '//getbootstrap.com/docs/4.5/dist/'
)

# Verify connection to database is working.
# Suggest help if common errors are encountered.
test_connection(movr.engine)


# ROUTES
# Home page
@app.route('/', methods=['GET'])
def home_page():
    """