comparison piecrust/admin/blueprint.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 a9f4a6e60b0b
children dcdec4b951a1
comparison
equal deleted inserted replaced
811:c7393ce2dde7 812:82509bce94ca
1 import os
2 import os.path
3 import time 1 import time
4 import logging 2 import logging
5 from flask import Blueprint, current_app, g, request, render_template 3 from flask import Blueprint, current_app, g, request
6 from .configuration import ( 4 from .configuration import (
7 FoodTruckConfigNotFoundError, get_foodtruck_config) 5 FoodTruckConfigNotFoundError, get_foodtruck_config)
8 from .sites import FoodTruckSites, InvalidSiteError 6 from .sites import FoodTruckSites, InvalidSiteError
9 7
10 8
11 logger = logging.getLogger(__name__) 9 logger = logging.getLogger(__name__)
12 10
13 11
14 # Prepare the Login extension. 12 # Prepare the Login extension.
15 from flask.ext.login import LoginManager, UserMixin 13 from flask.ext.login import LoginManager, UserMixin # NOQA
16 14
17 15
18 class User(UserMixin): 16 class User(UserMixin):
19 def __init__(self, uid, pwd): 17 def __init__(self, uid, pwd):
20 self.id = uid 18 self.id = uid
45 43
46 login_manager.init_app(state.app) 44 login_manager.init_app(state.app)
47 45
48 46
49 # Setup Bcrypt. 47 # Setup Bcrypt.
50 from .bcryptfallback import Bcrypt 48 from .bcryptfallback import Bcrypt # NOQA
51 bcrypt_ext = Bcrypt() 49 bcrypt_ext = Bcrypt()
52 50
53 51
54 def record_bcrypt(state): 52 def record_bcrypt(state):
55 if (getattr(Bcrypt, 'is_fallback_bcrypt', None) is True and 53 if (getattr(Bcrypt, 'is_fallback_bcrypt', None) is True and
56 not state.app.config.get('FOODTRUCK_CMDLINE_MODE', False)): 54 not state.app.config.get('FOODTRUCK_CMDLINE_MODE', False)):
57 raise Exception( 55 raise Exception(
58 "You're running FoodTruck outside of `chef`, and will need to " 56 "You're running FoodTruck outside of `chef`, and will need to "
59 "install Flask-Bcrypt to get more proper security.") 57 "install Flask-Bcrypt to get more proper security.")
60 58
61 bcrypt_ext.init_app(state.app) 59 bcrypt_ext.init_app(state.app)
62 state.app.bcrypt = bcrypt_ext 60 state.app.bcrypt = bcrypt_ext
63 61
64 62
65 # Create the FoodTruck blueprint. 63 # Create the FoodTruck blueprint.
66 foodtruck_bp = Blueprint( 64 foodtruck_bp = Blueprint(
67 'FoodTruck', __name__, 65 'FoodTruck', __name__,
68 template_folder='templates', 66 template_folder='templates',
69 static_folder='static') 67 static_folder='static')
70 68
71 foodtruck_bp.record(record_login_manager) 69 foodtruck_bp.record(record_login_manager)
72 foodtruck_bp.record(record_bcrypt) 70 foodtruck_bp.record(record_bcrypt)
73 71
74 72
101 99
102 def _get_sites(): 100 def _get_sites():
103 names = g.config.get('sites') 101 names = g.config.get('sites')
104 if not names or not isinstance(names, dict): 102 if not names or not isinstance(names, dict):
105 raise InvalidSiteError( 103 raise InvalidSiteError(
106 "No sites are defined in the configuration file.") 104 "No sites are defined in the configuration file.")
107 105
108 current = request.cookies.get('foodtruck_site_name') 106 current = request.cookies.get('foodtruck_site_name')
109 if current is not None and current not in names: 107 if current is not None and current not in names:
110 current = None 108 current = None
111 if current is None: 109 if current is None: