Mercurial > piecrust2
comparison piecrust/admin/web.py @ 812:82509bce94ca
internal: PEP8 fixup for admin panel code.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Dec 2016 22:20:18 -0800 |
parents | 8f2d32f90095 |
children | dcdec4b951a1 |
comparison
equal
deleted
inserted
replaced
811:c7393ce2dde7 | 812:82509bce94ca |
---|---|
1 import os.path | 1 import os.path |
2 import logging | 2 import logging |
3 from flask import Flask | 3 from flask import Flask, render_template |
4 from werkzeug import SharedDataMiddleware | 4 from werkzeug import SharedDataMiddleware |
5 from .blueprint import foodtruck_bp | 5 from .blueprint import foodtruck_bp |
6 from .configuration import FoodTruckConfigNotFoundError | 6 from .configuration import FoodTruckConfigNotFoundError |
7 from .sites import InvalidSiteError | 7 from .sites import InvalidSiteError |
8 | 8 |
18 app.config.update(extra_settings) | 18 app.config.update(extra_settings) |
19 | 19 |
20 admin_root = app.config.setdefault('FOODTRUCK_ROOT', os.getcwd()) | 20 admin_root = app.config.setdefault('FOODTRUCK_ROOT', os.getcwd()) |
21 config_path = os.path.join(admin_root, 'app.cfg') | 21 config_path = os.path.join(admin_root, 'app.cfg') |
22 | 22 |
23 # If we're being run as the `chef admin run` command, from inside a PieCrust | 23 # If we're being run as the `chef admin run` command, from inside a |
24 # website, do a few things differently. | 24 # PieCrust website, do a few things differently. |
25 app.config['FOODTRUCK_PROCEDURAL_CONFIG'] = None | 25 app.config['FOODTRUCK_PROCEDURAL_CONFIG'] = None |
26 if (app.config.get('FOODTRUCK_CMDLINE_MODE', False) and | 26 if (app.config.get('FOODTRUCK_CMDLINE_MODE', False) and |
27 os.path.isfile(os.path.join(admin_root, 'config.yml'))): | 27 os.path.isfile(os.path.join(admin_root, 'config.yml'))): |
28 app.secret_key = os.urandom(22) | 28 app.secret_key = os.urandom(22) |
29 app.config['LOGIN_DISABLED'] = True | 29 app.config['LOGIN_DISABLED'] = True |
30 app.config['FOODTRUCK_PROCEDURAL_CONFIG'] = { | 30 app.config['FOODTRUCK_PROCEDURAL_CONFIG'] = { |
31 'sites': { | 31 'sites': { |
32 'local': admin_root} | 32 'local': admin_root} |
33 } | 33 } |
34 | 34 |
35 # Add a special route for the `.well-known` directory. | 35 # Add a special route for the `.well-known` directory. |
36 app.wsgi_app = SharedDataMiddleware( | 36 app.wsgi_app = SharedDataMiddleware( |
37 app.wsgi_app, | 37 app.wsgi_app, |
38 {'/.well-known': os.path.join(admin_root, '.well-known')}) | 38 {'/.well-known': os.path.join(admin_root, '.well-known')}) |
39 | 39 |
40 if os.path.isfile(config_path): | 40 if os.path.isfile(config_path): |
41 app.config.from_pyfile(config_path) | 41 app.config.from_pyfile(config_path) |
42 | 42 |
43 if app.config['DEBUG']: | 43 if app.config['DEBUG']: |
48 def _on_config_missing(ex): | 48 def _on_config_missing(ex): |
49 return render_template('install.html') | 49 return render_template('install.html') |
50 | 50 |
51 @app.errorhandler(InvalidSiteError) | 51 @app.errorhandler(InvalidSiteError) |
52 def _on_invalid_site(ex): | 52 def _on_invalid_site(ex): |
53 data = {'error': "The was an error with your configuration file: %s" % | 53 data = {'error': |
54 "The was an error with your configuration file: %s" % | |
54 str(ex)} | 55 str(ex)} |
55 return render_template('error.html', **data) | 56 return render_template('error.html', **data) |
56 | 57 |
57 _missing_secret_key = False | |
58 if not app.secret_key: | 58 if not app.secret_key: |
59 # If there's no secret key, create a temp one but mark the app as not | 59 # If there's no secret key, create a temp one but mark the app as not |
60 # correctly installed so it shows the installation information page. | 60 # correctly installed so it shows the installation information page. |
61 app.secret_key = 'temp-key' | 61 app.secret_key = 'temp-key' |
62 _missing_secret_key = True | |
63 | 62 |
64 # Register extensions and blueprints. | 63 # Register extensions and blueprints. |
65 app.register_blueprint(foodtruck_bp) | 64 app.register_blueprint(foodtruck_bp) |
66 | 65 |
67 logger.debug("Created FoodTruck app with admin root: %s" % admin_root) | 66 logger.debug("Created FoodTruck app with admin root: %s" % admin_root) |