peter@1
|
1 |
from flask import Flask
|
peter@1
|
2 |
from flask import render_template
|
peter@1
|
3 |
from flask import request
|
peter@1
|
4 |
from flask import abort, redirect, url_for
|
peter@1
|
5 |
import os
|
peter@1
|
6 |
from flask import send_from_directory
|
peter@1
|
7 |
import logging
|
peter@1
|
8 |
from logging import Formatter
|
peter@1
|
9 |
|
rb@95
|
10 |
from flask.ext.babel import gettext as _
|
peter@1
|
11 |
from flask.ext.babel import Babel
|
peter@1
|
12 |
|
rb@95
|
13 |
from config import LANGUAGES
|
peter@141
|
14 |
from sayings import get_saying
|
peter@142
|
15 |
from jinja2 import Environment, FileSystemLoader
|
rb@95
|
16 |
|
rb@122
|
17 |
LANGUAGE_SELECTED = "de"
|
rb@122
|
18 |
#ToDo after engelish is implemented set LANGUAGE_SELECTED = None
|
rb@95
|
19 |
|
peter@1
|
20 |
app = Flask(__name__)
|
peter@1
|
21 |
babel = Babel(app)
|
peter@1
|
22 |
|
peter@142
|
23 |
def get_topmenue():
|
peter@142
|
24 |
|
peter@142
|
25 |
topmenue = [('/competition', _('Competition')),
|
peter@142
|
26 |
('/task', _('Task')),
|
peter@142
|
27 |
('/submission', _('Submission')),
|
peter@142
|
28 |
('/coursematerial', _('Coursematerial')),
|
peter@142
|
29 |
]
|
peter@142
|
30 |
|
peter@142
|
31 |
return topmenue
|
peter@142
|
32 |
|
peter@142
|
33 |
app.jinja_env.globals.update(get_topmenue=get_topmenue)
|
peter@142
|
34 |
|
peter@142
|
35 |
|
peter@1
|
36 |
@babel.localeselector
|
peter@1
|
37 |
def get_locale():
|
peter@109
|
38 |
"""ToDo: if translation is completed, switch to en """
|
rb@118
|
39 |
return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
|
peter@1
|
40 |
|
rb@100
|
41 |
|
peter@1
|
42 |
@app.route("/")
|
rb@100
|
43 |
@app.route("/index")
|
peter@1
|
44 |
def index():
|
peter@141
|
45 |
saying, author = get_saying()
|
peter@141
|
46 |
return render_template(get_locale() + "/index.html",
|
peter@141
|
47 |
saying = saying,
|
peter@141
|
48 |
author = author)
|
peter@1
|
49 |
|
rb@118
|
50 |
@app.route('/de')
|
rb@118
|
51 |
def de():
|
rb@118
|
52 |
global LANGUAGE_SELECTED
|
rb@118
|
53 |
LANGUAGE_SELECTED = "de"
|
rb@118
|
54 |
return render_template("/de/index.html")
|
rb@118
|
55 |
|
rb@118
|
56 |
@app.route('/en')
|
rb@118
|
57 |
def en():
|
rb@118
|
58 |
global LANGUAGE_SELECTED
|
rb@118
|
59 |
LANGUAGE_SELECTED = "en"
|
rb@118
|
60 |
return render_template("/en/index.html")
|
rb@118
|
61 |
|
rb@100
|
62 |
@app.route("/competition")
|
peter@1
|
63 |
def competition():
|
rb@100
|
64 |
return render_template(get_locale() + "/competition.html", act="competition")
|
peter@1
|
65 |
|
rb@100
|
66 |
@app.route("/task")
|
peter@1
|
67 |
def task():
|
rb@100
|
68 |
return render_template(get_locale() + "/task.html", act="task")
|
peter@1
|
69 |
|
rb@100
|
70 |
@app.route("/submission")
|
peter@1
|
71 |
def submission():
|
rb@100
|
72 |
return render_template(get_locale() + "/submission.html", act="submission")
|
peter@1
|
73 |
|
rb@100
|
74 |
@app.route("/coursematerial")
|
peter@1
|
75 |
def coursematerial():
|
rb@100
|
76 |
return render_template(get_locale() + "/coursematerial.html", act="coursematerial")
|
peter@1
|
77 |
|
rb@100
|
78 |
@app.route("/imprint")
|
peter@88
|
79 |
def imprint():
|
peter@109
|
80 |
return render_template(get_locale() + "/imprint.html", act="imprint")
|
peter@88
|
81 |
|
rb@100
|
82 |
@app.route("/privacy")
|
peter@88
|
83 |
def privacy():
|
rb@100
|
84 |
return render_template(get_locale() + "/privacy.html", act="privacy")
|
peter@88
|
85 |
|
peter@123
|
86 |
@app.route("/competition/2013")
|
peter@109
|
87 |
def competition_2013():
|
peter@123
|
88 |
print get_locale() + "/archive/competitions/2013/index.html"
|
peter@123
|
89 |
return render_template(get_locale() + "/archive/competitions/2013/index.html",
|
peter@109
|
90 |
act="coursematerial")
|
peter@109
|
91 |
|
peter@123
|
92 |
@app.route("/competition/2014")
|
peter@109
|
93 |
def competition_2014():
|
peter@123
|
94 |
print get_locale() + "/archive/competitions/2014/index.html"
|
peter@123
|
95 |
return render_template(get_locale() + "/archive/competitions/2014/index.html",
|
peter@109
|
96 |
act="coursematerial")
|
peter@88
|
97 |
|
hr@112
|
98 |
@app.route(_("/dates"))
|
hr@112
|
99 |
def dates():
|
hr@112
|
100 |
return render_template(get_locale() + "/dates.html",
|
hr@112
|
101 |
act="dates")
|
hr@112
|
102 |
|
hr@112
|
103 |
|
peter@1
|
104 |
@app.errorhandler(404)
|
peter@1
|
105 |
def page_not_found(e):
|
rb@100
|
106 |
return render_template(get_locale() + "/404.html")
|
peter@1
|
107 |
|
peter@1
|
108 |
if __name__ == "__main__":
|
peter@1
|
109 |
app.run(host='localhost', port=5014, debug=True)
|