-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·107 lines (85 loc) · 2.91 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
"""
Example application views.
Note that `render_template` is wrapped with `make_response` in all application
routes. While not necessary for most Flask apps, it is required in the
App Template for static publishing.
"""
import app_config
import logging
import oauth
import static
from flask import Flask, make_response, render_template, redirect
from render_utils import make_context, smarty_filter, urlencode_filter
from werkzeug.debug import DebuggedApplication
from helpers import *
app = Flask(__name__)
app.debug = app_config.DEBUG
app.add_template_filter(smarty_filter, name='smarty')
app.add_template_filter(urlencode_filter, name='urlencode')
app.jinja_env.filters['format_zip'] = format_zip
app.jinja_env.filters['status_color'] = get_location_status_color_by_slug
app.jinja_env.filters['status_updated'] = get_location_status_updated_by_slug
logging.basicConfig(format=app_config.LOG_FORMAT)
logger = logging.getLogger(__name__)
logger.setLevel(app_config.LOG_LEVEL)
@app.route('/')
@oauth.oauth_required
def index():
"""
Example view demonstrating rendering a simple HTML page.
"""
context = make_context()
return make_response(render_template('index.html', **context))
@app.route('/location')
@app.route('/location/')
@app.route('/locations')
@app.route('/locations/')
def table_redirect():
"""
redirect people looking for a list of locations to the main page
"""
return redirect( '/', code='303' ) # 303 See Other
@app.route('/table.html')
def table():
"""
the pym-child table
"""
context = make_context()
return make_response(render_template('table.html', **context))
@app.route('/embedding.html')
def embedding():
"""
instructions on embedding this item
"""
context = make_context()
return make_response(render_template('embedding.html', **context))
@app.route('/embedding.html')
def embedding():
"""
instructions on embedding this item
"""
context = make_context()
return make_response(render_template('embedding.html', **context))
location_ids = get_location_ids()
for slug in location_ids: # 'id' is a __builtin__
@app.route('/location/%s/' % slug)
def location():
context = make_context()
from flask import request
slug = request.path.split('/')[2]
context['location'] = get_location_by_slug(slug)
context['history'] = get_location_history_by_slug(slug)
context['status'] = get_location_status_by_slug(slug)
return make_response( render_template( 'location.html', **context ) )
app.register_blueprint(static.static)
app.register_blueprint(oauth.oauth)
# Enable Werkzeug debug pages
if app_config.DEBUG:
wsgi_app = DebuggedApplication(app, evalex=False)
else:
wsgi_app = app
# Catch attempts to run the app directly
if __name__ == '__main__':
logging.error('This command has been removed! Please run "fab app" instead!')