This repository was archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.py
More file actions
47 lines (41 loc) · 1.32 KB
/
app.py
File metadata and controls
47 lines (41 loc) · 1.32 KB
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
from flask import Flask
from flask.ext.security import Security, SQLAlchemyUserDatastore
from flask.ext.babel import Babel
from scan import settings
from celery import Celery
from core.database.models import db, User, Role
from flask.ext.cache import Cache
from core.web.main_views import main_views
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
def create_app():
app = Flask(__name__, template_folder='templates')
app.config.from_object('scan.settings')
db.app = app
db.init_app(app)
return app
def create_test_app():
app = create_app()
app.config.from_object('scan.test_settings')
db.app = app
db.init_app(app)
return app
app = create_app()
app.register_blueprint(main_views)
cache = Cache(app)
babel = Babel(app)
celery = make_celery(app)
if __name__ == '__main__':
db.create_all(app=app)
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)
app.run(debug=settings.DEBUG, host="0.0.0.0")