-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
executable file
·86 lines (62 loc) · 1.97 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
#! /usr/bin/python2.7
# -*- coding: utf-8 -*-
from datetime import datetime
import re
import meinheld
from flask import Flask, render_template, redirect, request, url_for
from flask.ext.assets import Environment as Asset
import members
from settings import BABEL_SETTINGS, DIRLINKS, SERVER_SETTINGS
from utils.i18n import PopongBabel
app = Flask(__name__)
app.debug = SERVER_SETTINGS['debug']
Asset(app)
PopongBabel(app, **BABEL_SETTINGS)
@app.route('/')
def home():
return render_template('main.html')
@app.route('/team')
def team():
return render_template('about.html',
YB=members.YB, CONTRIBUTORS=members.CONTRIBUTORS, partners=members.PARTNERS)
@app.route('/blog/<locale>')
def blog(locale):
return redirect('http://blog.popong.com/%s' % locale)
@app.route('/data')
def data():
return redirect('http://data.popong.com/')
@app.route('/faq')
def faq():
return render_template('faq.html')
@app.route('/sources')
def sources():
return render_template('sources.html')
@app.route('/philosophy')
def philosophy():
return render_template('philosophy.html')
@app.context_processor
def inject_data():
return dict(
dirlinks=DIRLINKS,
thisyear=datetime.today().year,
)
def cmd_args():
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-l', dest='locale',
choices=app.LOCALES + ['auto'],
default='auto')
args = parser.parse_args()
return args
def main():
args = cmd_args()
if args.locale and args.locale != 'auto':
app.babel.locale_selector_func = lambda: args.locale
if SERVER_SETTINGS['type']=='flask':
app.run(SERVER_SETTINGS['host'], SERVER_SETTINGS['port'])
elif SERVER_SETTINGS['type']=='meinheld':
print 'On http://%s:%s/' % (SERVER_SETTINGS['host'], SERVER_SETTINGS['port'])
meinheld.listen((SERVER_SETTINGS['host'], SERVER_SETTINGS['port']))
meinheld.run(app)
if __name__ == '__main__':
main()