annotate foodtruck/blueprint.py @ 772:3885421c29a3

admin: Make the whole FoodTruck site into a blueprint. This makes it possible to use an app factory, which makes it easier to write unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 03 Jul 2016 07:54:54 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
772
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import time
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import logging
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 from flask import Blueprint, current_app, g, request, render_template
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 from .configuration import (
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 FoodTruckConfigNotFoundError, get_foodtruck_config)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 from .sites import FoodTruckSites, InvalidSiteError
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 logger = logging.getLogger(__name__)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 # Prepare the Login extension.
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 from flask.ext.login import LoginManager, UserMixin
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 class User(UserMixin):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 def __init__(self, uid, pwd):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 self.id = uid
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 self.password = pwd
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 def load_user(user_id):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 admin_id = g.config.get('security/username')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 if admin_id == user_id:
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 admin_pwd = g.config.get('security/password')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 return User(admin_id, admin_pwd)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 return None
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 login_manager = LoginManager()
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 login_manager.login_view = 'login'
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 login_manager.user_loader(load_user)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 def record_login_manager(state):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 if state.app.secret_key == 'temp-key':
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 def _handler():
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 raise FoodTruckConfigNotFoundError()
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 logger.debug("No secret key found, disabling website login.")
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 login_manager.unauthorized_handler(_handler)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 login_manager.login_view = None
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 # Setup Bcrypt.
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 from foodtruck.bcryptfallback import Bcrypt
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 bcrypt_ext = Bcrypt()
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 def record_bcrypt(state):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 if (getattr(Bcrypt, 'is_fallback_bcrypt', None) is True and
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 not state.app.config.get('FOODTRUCK_CMDLINE_MODE', False)):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 raise Exception(
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 "You're running FoodTruck outside of `chef`, and will need to "
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 "install Flask-Bcrypt to get more proper security.")
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 # Create the FoodTruck blueprint.
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 foodtruck_bp = Blueprint(
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 'FoodTruck', __name__,
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 template_folder='templates',
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 static_folder='static')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 foodtruck_bp.record(record_login_manager)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 foodtruck_bp.record(record_bcrypt)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 def after_this_request(f):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 if not hasattr(g, 'after_request_callbacks'):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 g.after_request_callbacks = []
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 g.after_request_callbacks.append(f)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 return f
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 class LazySomething(object):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 def __init__(self, factory):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 self._factory = factory
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 self._something = None
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 def __getattr__(self, name):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 if self._something is not None:
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 return getattr(self._something, name)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 self._something = self._factory()
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 return getattr(self._something, name)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 @foodtruck_bp.before_request
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 def _setup_foodtruck_globals():
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 def _get_config():
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 admin_root = current_app.config['FOODTRUCK_ROOT']
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 procedural_config = current_app.config['FOODTRUCK_PROCEDURAL_CONFIG']
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 return get_foodtruck_config(admin_root, procedural_config)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 def _get_sites():
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 names = g.config.get('sites')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 if not names or not isinstance(names, dict):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 raise InvalidSiteError(
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 "No sites are defined in the configuration file.")
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 current = request.cookies.get('foodtruck_site_name')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 if current is not None and current not in names:
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 current = None
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 if current is None:
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 current = next(iter(names.keys()))
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 s = FoodTruckSites(g.config, current)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 return s
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 def _get_current_site():
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 return g.sites.get()
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 g.config = LazySomething(_get_config)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 g.sites = LazySomething(_get_sites)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 g.site = LazySomething(_get_current_site)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 @foodtruck_bp.after_request
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 def _call_after_request_callbacks(response):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 for callback in getattr(g, 'after_request_callbacks', ()):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 callback(response)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 return response
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 @foodtruck_bp.errorhandler
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 def _on_error(ex):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 logging.exception(ex)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 @foodtruck_bp.app_template_filter('iso8601')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 def timestamp_to_iso8601(t):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 t = time.localtime(t)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 return time.strftime('%Y-%m-%dT%H:%M:%SZ', t)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 @foodtruck_bp.app_template_filter('datetime')
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 def timestamp_to_datetime(t, fmt=None):
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 fmt = fmt or '%x'
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 t = time.localtime(t)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 return time.strftime(fmt, t)
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 import foodtruck.views.create # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 import foodtruck.views.dashboard # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 import foodtruck.views.edit # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 import foodtruck.views.menu # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 import foodtruck.views.preview # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 import foodtruck.views.publish # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 import foodtruck.views.sources # NOQA
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151
3885421c29a3 admin: Make the whole FoodTruck site into a blueprint.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152