Browse Source

Use Flask-And-Redis so you can configure redis easier.
Also the Debugtoolbar extensions supports now the init_app method for initializing the extensions

sh4nks 11 years ago
parent
commit
30163a71a9
3 changed files with 25 additions and 35 deletions
  1. 16 29
      flaskbb/app.py
  2. 6 3
      flaskbb/configs/default.py
  3. 3 3
      flaskbb/extensions.py

+ 16 - 29
flaskbb/app.py

@@ -14,7 +14,6 @@ import datetime
 
 
 from flask import Flask, render_template, request
 from flask import Flask, render_template, request
 from flask.ext.login import current_user
 from flask.ext.login import current_user
-from flask_debugtoolbar import DebugToolbarExtension
 
 
 # Import the user blueprint
 # Import the user blueprint
 from flaskbb.user.views import user
 from flaskbb.user.views import user
@@ -26,7 +25,8 @@ from flaskbb.admin.views import admin
 # Import the forum blueprint
 # Import the forum blueprint
 from flaskbb.forum.views import forum
 from flaskbb.forum.views import forum
 
 
-from flaskbb.extensions import db, login_manager, mail, cache
+from flaskbb.extensions import (db, login_manager, mail, cache, redis,
+                                debugtoolbar)
 from flaskbb.utils.helpers import (format_date, time_since, crop_title,
 from flaskbb.utils.helpers import (format_date, time_since, crop_title,
                                    can_post_reply, can_post_topic,
                                    can_post_reply, can_post_topic,
                                    can_delete_topic, can_delete_post, is_online,
                                    can_delete_topic, can_delete_post, is_online,
@@ -53,9 +53,17 @@ def create_app(config=None, blueprints=None):
     # Initialize the app
     # Initialize the app
     app = Flask("flaskbb")
     app = Flask("flaskbb")
 
 
-    configure_app(app, config)
+    # Use the default config and override it afterwards
+    app.config.from_object('flaskbb.configs.default.DefaultConfig')
+    # Update the config
+    app.config.from_object(config)
+    # try to update the config via the environment variable
+    app.config.from_envvar("FLASKBB_SETTINGS", silent=True)
+
+    for blueprint, url_prefix in blueprints:
+        app.register_blueprint(blueprint, url_prefix=url_prefix)
+
     configure_extensions(app)
     configure_extensions(app)
-    configure_blueprints(app, blueprints)
     configure_template_filters(app)
     configure_template_filters(app)
     configure_before_handlers(app)
     configure_before_handlers(app)
     configure_errorhandlers(app)
     configure_errorhandlers(app)
@@ -64,21 +72,6 @@ def create_app(config=None, blueprints=None):
     return app
     return app
 
 
 
 
-def configure_app(app, config):
-    """
-    Configures the app. If no configuration file is choosen,
-    the app will use the example configuration.
-    """
-
-    # Get the configuration file
-    if config is None:
-        from flaskbb.configs.default import DefaultConfig
-        app.config.from_object(DefaultConfig)
-        app.logger.info("No configuration specified. Using the Default config")
-    else:
-        app.config.from_object(config)
-
-
 def configure_extensions(app):
 def configure_extensions(app):
     """
     """
     Configures the extensions
     Configures the extensions
@@ -94,7 +87,10 @@ def configure_extensions(app):
     cache.init_app(app)
     cache.init_app(app)
 
 
     # Flask-Debugtoolbar
     # Flask-Debugtoolbar
-    DebugToolbarExtension(app)
+    debugtoolbar.init_app(app)
+
+    # Flask-And-Redis
+    redis.init_app(app)
 
 
     # Flask-Login
     # Flask-Login
     login_manager.login_view = app.config["LOGIN_VIEW"]
     login_manager.login_view = app.config["LOGIN_VIEW"]
@@ -120,15 +116,6 @@ def configure_extensions(app):
     login_manager.init_app(app)
     login_manager.init_app(app)
 
 
 
 
-def configure_blueprints(app, blueprints):
-    """
-    Configures the blueprints
-    """
-
-    for blueprint, url_prefix in blueprints:
-        app.register_blueprint(blueprint, url_prefix=url_prefix)
-
-
 def configure_template_filters(app):
 def configure_template_filters(app):
     """
     """
     Configures the template filters
     Configures the template filters

+ 6 - 3
flaskbb/configs/default.py

@@ -1,9 +1,9 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 """
 """
-    flaskbb.configs.base
-    ~~~~~~~~~~~~~~~~~~~~
+    flaskbb.configs.default
+    ~~~~~~~~~~~~~~~~~~~~~~~
 
 
-    This is the base configuration for FlaskBB that every site should have.
+    This is the default configuration for FlaskBB that every site should have.
     You can override these configuration variables in another class.
     You can override these configuration variables in another class.
 
 
     :copyright: (c) 2013 by the FlaskBB Team.
     :copyright: (c) 2013 by the FlaskBB Team.
@@ -92,6 +92,9 @@ class DefaultConfig(object):
 
 
     # This is really handy if do not have an redis instance like on windows
     # This is really handy if do not have an redis instance like on windows
     USE_REDIS = True
     USE_REDIS = True
+    REDIS_HOST = 'localhost'
+    REDIS_PORT = 6379
+    REDIS_DB = 0
 
 
     # The days for how long the forum should deal with unread topics
     # The days for how long the forum should deal with unread topics
     # 0 - Disable it
     # 0 - Disable it

+ 3 - 3
flaskbb/extensions.py

@@ -8,12 +8,12 @@
     :copyright: (c) 2013 by the FlaskBB Team.
     :copyright: (c) 2013 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
     :license: BSD, see LICENSE for more details.
 """
 """
-from redis import Redis
 from flask.ext.sqlalchemy import SQLAlchemy
 from flask.ext.sqlalchemy import SQLAlchemy
 from flask.ext.login import LoginManager
 from flask.ext.login import LoginManager
 from flask.ext.mail import Mail
 from flask.ext.mail import Mail
 from flask.ext.cache import Cache
 from flask.ext.cache import Cache
-#from flask.ext.debugtoolbar import DebugToolbarExtension
+from flask.ext.debugtoolbar import DebugToolbarExtension
+from flask.ext.redis import Redis
 
 
 # Database
 # Database
 db = SQLAlchemy()
 db = SQLAlchemy()
@@ -31,4 +31,4 @@ cache = Cache()
 redis = Redis()
 redis = Redis()
 
 
 # Debugtoolbar
 # Debugtoolbar
-#toolbar = DebugToolbarExtension()
+debugtoolbar = DebugToolbarExtension()