-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
50 lines (40 loc) · 1.53 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
'''
This is the central co-ordinator of the flask server.
It creates the app, configures it, opens the database, and starts the login manager.
It is crucial that the imports from the module are at the very end, to avoid
complications from circular imports.
It only knows where the database lives, because we passed the base directory
in sys.path[0]. As a backup, for Windows development machines, the database
location can be specified in config.py, in the form:
SQLALCHEMY_DATABASE_URI = 'sqlite:///C:\\android\\ZAPScorer\\server\\mj.sqlite'
'''
import pathlib
import sys
# do this before any other imports might mess with sys.path
BASE_DIR = pathlib.Path(sys.path[0])
# imports from framework
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_moment import Moment
# imports from app
from mjserver.config import Config
#%%
app = Flask(__name__, static_folder=str(BASE_DIR / 'static'))
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.config.from_object(Config)
test = str(BASE_DIR / 'mj.sqlite')
if test[0] == '/':
# we are on *nix machine, so override Config value with live path
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + test
app.config['DEBUG'] = True
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'
moment = Moment(app)
# safe to ignore warning about the following imports being unused
from mjserver import api, routes, models, errors