Mercurial > wikked
changeset 315:e07eee5e101a
Consistent Flask config variables. Set that config before creating the app.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 08 Oct 2014 23:22:44 -0700 |
parents | 59dd71d4a69a |
children | 61902f36c789 |
files | wikked/commands/web.py wikked/views/read.py wikked/web.py |
diffstat | 3 files changed, 25 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/wikked/commands/web.py Wed Oct 08 23:22:02 2014 -0700 +++ b/wikked/commands/web.py Wed Oct 08 23:22:44 2014 -0700 @@ -65,23 +65,25 @@ else: setattr(wikked.settings, cname, cval) - # Create/import the app. - from wikked.web import app - # Remove Flask's default logging handler. Since the app is under the # overall Wikked package, logging is handled by the root logger # already. - app.logger.handlers = [] + wikked.settings.WIKI_NO_FLASK_LOGGER = True - # Setup other simpler settings. + # When running from the command line, we only have one web server + # so make it also serve static files. + wikked.settings.WIKI_SERVE_FILES = True if ctx.args.dev: - app.config['DEV_ASSETS'] = True + wikked.settings.WIKI_DEV_ASSETS = True if not ctx.args.noupdate: - app.config['WIKI_AUTO_RELOAD'] = True + wikked.settings.WIKI_AUTO_RELOAD = True ctx.params.wiki_updater = autoreload_wiki_updater + # Create/import the app. + from wikked.web import app + app.wiki_params = ctx.params - if bool(app.config.get('UPDATE_WIKI_ON_START')): + if bool(app.config.get('WIKI_UPDATE_ON_START')): ctx.wiki.updateAll() # Run!
--- a/wikked/views/read.py Wed Oct 08 23:22:02 2014 -0700 +++ b/wikked/views/read.py Wed Oct 08 23:22:44 2014 -0700 @@ -15,7 +15,7 @@ @app.route('/') def home(): tpl_name = 'index.html' - if app.config['DEV_ASSETS']: + if app.config['WIKI_DEV_ASSETS']: tpl_name = 'index-dev.html' return render_template(tpl_name, cache_bust=('?%d' % time.time())); @@ -23,7 +23,7 @@ @app.route('/read/<path:url>') def read(): tpl_name = 'index.html' - if app.config['DEV_ASSETS']: + if app.config['WIKI_DEV_ASSETS']: tpl_name = 'index-dev.html' return render_template(tpl_name, cache_bust=('?%d' % time.time())); @@ -31,7 +31,7 @@ @app.route('/search') def search(): tpl_name = 'index.html' - if app.config['DEV_ASSETS']: + if app.config['WIKI_DEV_ASSETS']: tpl_name = 'index-dev.html' return render_template(tpl_name, cache_bust=('?%d' % time.time()));
--- a/wikked/web.py Wed Oct 08 23:22:02 2014 -0700 +++ b/wikked/web.py Wed Oct 08 23:22:44 2014 -0700 @@ -16,18 +16,24 @@ # Setup some config defaults. -app.config.setdefault('DEV_ASSETS', False) app.config.setdefault('SQL_DEBUG', False) app.config.setdefault('SQL_COMMIT_ON_TEARDOWN', False) app.config.setdefault('WIKI_ROOT', None) -app.config.setdefault('UPDATE_WIKI_ON_START', True) +app.config.setdefault('WIKI_DEV_ASSETS', False) +app.config.setdefault('WIKI_UPDATE_ON_START', True) app.config.setdefault('WIKI_AUTO_RELOAD', False) app.config.setdefault('WIKI_ASYNC_UPDATE', False) -app.config.setdefault('BROKER_URL', 'sqla+sqlite:///%(root)s/.wiki/broker.db') +app.config.setdefault('WIKI_SERVE_FILES', False) +app.config.setdefault('WIKI_BROKER_URL', 'sqla+sqlite:///%(root)s/.wiki/broker.db') +app.config.setdefault('WIKI_NO_FLASK_LOGGER', False) app.config.setdefault('PROFILE', False) app.config.setdefault('PROFILE_DIR', None) +if app.config['WIKI_NO_FLASK_LOGGER']: + app.logger.handlers = [] + + # Find the wiki root, and further configure the app if there's a # config file in there. wiki_root = app.config['WIKI_ROOT'] @@ -42,7 +48,7 @@ # Make the app serve static content and wiki assets in DEBUG mode. -if app.config['DEBUG']: +if app.config['WIKI_DEV_ASSETS'] or app.config['WIKI_SERVE_FILES']: from werkzeug import SharedDataMiddleware import os app.wsgi_app = SharedDataMiddleware(app.wsgi_app, { @@ -149,10 +155,10 @@ from wikked.tasks import celery_app, update_wiki # Configure Celery. - app.config['BROKER_URL'] = app.config['BROKER_URL'] % ( + app.config['WIKI_BROKER_URL'] = app.config['WIKI_BROKER_URL'] % ( {'root': wiki_root}) celery_app.conf.update(app.config) - app.logger.debug("Using Celery broker: %s" % app.config['BROKER_URL']) + app.logger.debug("Using Celery broker: %s" % app.config['WIKI_BROKER_URL']) # Make the wiki use the background update task. def async_updater(wiki):