|
@@ -27,17 +27,12 @@ from flaskbb._compat import iteritems, string_types
|
|
from flaskbb.extensions import (alembic, allows, babel, cache, celery, csrf,
|
|
from flaskbb.extensions import (alembic, allows, babel, cache, celery, csrf,
|
|
db, debugtoolbar, limiter, login_manager, mail,
|
|
db, debugtoolbar, limiter, login_manager, mail,
|
|
redis_store, themes, whooshee)
|
|
redis_store, themes, whooshee)
|
|
-from .auth import views as auth_views
|
|
|
|
-from .forum import views as forum_views
|
|
|
|
-from .management import views as management_views
|
|
|
|
from flaskbb.plugins import spec
|
|
from flaskbb.plugins import spec
|
|
from flaskbb.plugins.manager import FlaskBBPluginManager
|
|
from flaskbb.plugins.manager import FlaskBBPluginManager
|
|
from flaskbb.plugins.models import PluginRegistry
|
|
from flaskbb.plugins.models import PluginRegistry
|
|
from flaskbb.plugins.utils import remove_zombie_plugins_from_db, template_hook
|
|
from flaskbb.plugins.utils import remove_zombie_plugins_from_db, template_hook
|
|
# models
|
|
# models
|
|
from flaskbb.user.models import Guest, User
|
|
from flaskbb.user.models import Guest, User
|
|
-# views
|
|
|
|
-from flaskbb.user.views import user
|
|
|
|
# various helpers
|
|
# various helpers
|
|
from flaskbb.utils.helpers import (app_config_from_env, crop_title,
|
|
from flaskbb.utils.helpers import (app_config_from_env, crop_title,
|
|
format_date, forum_is_unread,
|
|
format_date, forum_is_unread,
|
|
@@ -58,6 +53,10 @@ from flaskbb.utils.search import (ForumWhoosheer, PostWhoosheer,
|
|
from flaskbb.utils.settings import flaskbb_config
|
|
from flaskbb.utils.settings import flaskbb_config
|
|
from flaskbb.utils.translations import FlaskBBDomain
|
|
from flaskbb.utils.translations import FlaskBBDomain
|
|
|
|
|
|
|
|
+from .auth import views as auth_views
|
|
|
|
+from .forum import views as forum_views
|
|
|
|
+from .management import views as management_views
|
|
|
|
+from .user import views as user_views
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@@ -78,9 +77,7 @@ def create_app(config=None, instance_path=None):
|
|
"""
|
|
"""
|
|
|
|
|
|
app = Flask(
|
|
app = Flask(
|
|
- "flaskbb",
|
|
|
|
- instance_path=instance_path,
|
|
|
|
- instance_relative_config=True
|
|
|
|
|
|
+ "flaskbb", instance_path=instance_path, instance_relative_config=True
|
|
)
|
|
)
|
|
|
|
|
|
# instance folders are not automatically created by flask
|
|
# instance folders are not automatically created by flask
|
|
@@ -149,14 +146,15 @@ def configure_celery_app(app, celery):
|
|
TaskBase = celery.Task
|
|
TaskBase = celery.Task
|
|
|
|
|
|
class ContextTask(TaskBase):
|
|
class ContextTask(TaskBase):
|
|
|
|
+
|
|
def __call__(self, *args, **kwargs):
|
|
def __call__(self, *args, **kwargs):
|
|
with app.app_context():
|
|
with app.app_context():
|
|
return TaskBase.__call__(self, *args, **kwargs)
|
|
return TaskBase.__call__(self, *args, **kwargs)
|
|
|
|
+
|
|
celery.Task = ContextTask
|
|
celery.Task = ContextTask
|
|
|
|
|
|
|
|
|
|
def configure_blueprints(app):
|
|
def configure_blueprints(app):
|
|
- app.register_blueprint(user, url_prefix=app.config["USER_URL_PREFIX"])
|
|
|
|
app.pluggy.hook.flaskbb_load_blueprints(app=app)
|
|
app.pluggy.hook.flaskbb_load_blueprints(app=app)
|
|
|
|
|
|
|
|
|
|
@@ -243,9 +241,9 @@ def configure_template_filters(app):
|
|
('can_ban_user', CanBanUser),
|
|
('can_ban_user', CanBanUser),
|
|
]
|
|
]
|
|
|
|
|
|
- filters.update([
|
|
|
|
- (name, partial(perm, request=request)) for name, perm in permissions
|
|
|
|
- ])
|
|
|
|
|
|
+ filters.update(
|
|
|
|
+ [(name, partial(perm, request=request)) for name, perm in permissions]
|
|
|
|
+ )
|
|
|
|
|
|
# these create closures
|
|
# these create closures
|
|
filters['can_moderate'] = TplCanModerate(request)
|
|
filters['can_moderate'] = TplCanModerate(request)
|
|
@@ -291,6 +289,7 @@ def configure_before_handlers(app):
|
|
db.session.commit()
|
|
db.session.commit()
|
|
|
|
|
|
if app.config["REDIS_ENABLED"]:
|
|
if app.config["REDIS_ENABLED"]:
|
|
|
|
+
|
|
@app.before_request
|
|
@app.before_request
|
|
def mark_current_user_online():
|
|
def mark_current_user_online():
|
|
if current_user.is_authenticated:
|
|
if current_user.is_authenticated:
|
|
@@ -417,8 +416,11 @@ def load_plugins(app):
|
|
plugins = PluginRegistry.query.all()
|
|
plugins = PluginRegistry.query.all()
|
|
|
|
|
|
except (OperationalError, ProgrammingError) as exc:
|
|
except (OperationalError, ProgrammingError) as exc:
|
|
- logger.debug("Database is not setup correctly or has not been "
|
|
|
|
- "setup yet.", exc_info=exc)
|
|
|
|
|
|
+ logger.debug(
|
|
|
|
+ "Database is not setup correctly or has not been "
|
|
|
|
+ "setup yet.",
|
|
|
|
+ exc_info=exc
|
|
|
|
+ )
|
|
# load plugins even though the database isn't setup correctly
|
|
# load plugins even though the database isn't setup correctly
|
|
# i.e. when creating the initial database and wanting to install
|
|
# i.e. when creating the initial database and wanting to install
|
|
# the plugins migration as well
|
|
# the plugins migration as well
|
|
@@ -435,7 +437,8 @@ def load_plugins(app):
|
|
loaded_names = set([p[0] for p in app.pluggy.list_name_plugin()])
|
|
loaded_names = set([p[0] for p in app.pluggy.list_name_plugin()])
|
|
registered_names = set([p.name for p in plugins])
|
|
registered_names = set([p.name for p in plugins])
|
|
unregistered = [
|
|
unregistered = [
|
|
- PluginRegistry(name=name) for name in loaded_names - registered_names
|
|
|
|
|
|
+ PluginRegistry(name=name)
|
|
|
|
+ for name in loaded_names - registered_names
|
|
# ignore internal FlaskBB modules
|
|
# ignore internal FlaskBB modules
|
|
if not name.startswith('flaskbb.') and name != 'flaskbb'
|
|
if not name.startswith('flaskbb.') and name != 'flaskbb'
|
|
]
|
|
]
|