Mercurial > piecrust2
comparison piecrust/admin/blueprint.py @ 886:dcdec4b951a1
admin: Get the admin panel working again.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Jun 2017 21:13:08 -0700 |
parents | 82509bce94ca |
children | 2b0fa2e4c12f |
comparison
equal
deleted
inserted
replaced
885:13e8b50a2113 | 886:dcdec4b951a1 |
---|---|
1 import time | 1 import time |
2 import logging | 2 import logging |
3 from flask import Blueprint, current_app, g, request | 3 from flask import Blueprint, current_app, g |
4 from .configuration import ( | 4 from .siteinfo import SiteInfo |
5 FoodTruckConfigNotFoundError, get_foodtruck_config) | |
6 from .sites import FoodTruckSites, InvalidSiteError | |
7 | 5 |
8 | 6 |
9 logger = logging.getLogger(__name__) | 7 logger = logging.getLogger(__name__) |
10 | 8 |
11 | 9 |
31 login_manager.login_view = 'FoodTruck.login' | 29 login_manager.login_view = 'FoodTruck.login' |
32 login_manager.user_loader(load_user) | 30 login_manager.user_loader(load_user) |
33 | 31 |
34 | 32 |
35 def record_login_manager(state): | 33 def record_login_manager(state): |
36 if state.app.secret_key == 'temp-key': | 34 if state.app.config['SECRET_KEY'] == 'temp-key': |
37 def _handler(): | 35 def _handler(): |
38 raise FoodTruckConfigNotFoundError() | 36 raise Exception("No secret key has been set!") |
39 | 37 |
40 logger.debug("No secret key found, disabling website login.") | 38 logger.debug("No secret key found, disabling website login.") |
41 login_manager.unauthorized_handler(_handler) | 39 login_manager.unauthorized_handler(_handler) |
42 login_manager.login_view = None | 40 login_manager.login_view = None |
43 | 41 |
90 return getattr(self._something, name) | 88 return getattr(self._something, name) |
91 | 89 |
92 | 90 |
93 @foodtruck_bp.before_request | 91 @foodtruck_bp.before_request |
94 def _setup_foodtruck_globals(): | 92 def _setup_foodtruck_globals(): |
95 def _get_config(): | 93 def _get_site(): |
96 admin_root = current_app.config['FOODTRUCK_ROOT'] | 94 root_dir = current_app.config['FOODTRUCK_ROOT'] |
97 procedural_config = current_app.config['FOODTRUCK_PROCEDURAL_CONFIG'] | 95 url_prefix = current_app.config['FOODTRUCK_URL_PREFIX'] |
98 return get_foodtruck_config(admin_root, procedural_config) | 96 return SiteInfo(root_dir, url_prefix, debug=current_app.debug) |
99 | 97 |
100 def _get_sites(): | 98 g.site = LazySomething(_get_site) |
101 names = g.config.get('sites') | |
102 if not names or not isinstance(names, dict): | |
103 raise InvalidSiteError( | |
104 "No sites are defined in the configuration file.") | |
105 | |
106 current = request.cookies.get('foodtruck_site_name') | |
107 if current is not None and current not in names: | |
108 current = None | |
109 if current is None: | |
110 current = next(iter(names.keys())) | |
111 s = FoodTruckSites(g.config, current) | |
112 return s | |
113 | |
114 def _get_current_site(): | |
115 return g.sites.get() | |
116 | |
117 g.config = LazySomething(_get_config) | |
118 g.sites = LazySomething(_get_sites) | |
119 g.site = LazySomething(_get_current_site) | |
120 | 99 |
121 | 100 |
122 @foodtruck_bp.after_request | 101 @foodtruck_bp.after_request |
123 def _call_after_request_callbacks(response): | 102 def _call_after_request_callbacks(response): |
124 for callback in getattr(g, 'after_request_callbacks', ()): | 103 for callback in getattr(g, 'after_request_callbacks', ()): |