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
|
rb@95
|
14 |
|
rb@118
|
15 |
LANGUAGE_SELECTED = None
|
rb@95
|
16 |
|
peter@1
|
17 |
app = Flask(__name__)
|
peter@1
|
18 |
babel = Babel(app)
|
peter@1
|
19 |
|
peter@1
|
20 |
@babel.localeselector
|
peter@1
|
21 |
def get_locale():
|
peter@109
|
22 |
"""ToDo: if translation is completed, switch to en """
|
rb@118
|
23 |
return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
|
peter@1
|
24 |
|
rb@100
|
25 |
|
peter@1
|
26 |
@app.route("/")
|
rb@100
|
27 |
@app.route("/index")
|
peter@1
|
28 |
def index():
|
rb@100
|
29 |
return render_template(get_locale() + "/index.html")
|
peter@1
|
30 |
|
rb@118
|
31 |
@app.route('/de')
|
rb@118
|
32 |
def de():
|
rb@118
|
33 |
global LANGUAGE_SELECTED
|
rb@118
|
34 |
LANGUAGE_SELECTED = "de"
|
rb@118
|
35 |
return render_template("/de/index.html")
|
rb@118
|
36 |
|
rb@118
|
37 |
@app.route('/en')
|
rb@118
|
38 |
def en():
|
rb@118
|
39 |
global LANGUAGE_SELECTED
|
rb@118
|
40 |
LANGUAGE_SELECTED = "en"
|
rb@118
|
41 |
return render_template("/en/index.html")
|
rb@118
|
42 |
|
rb@100
|
43 |
@app.route("/competition")
|
peter@1
|
44 |
def competition():
|
rb@100
|
45 |
return render_template(get_locale() + "/competition.html", act="competition")
|
peter@1
|
46 |
|
rb@100
|
47 |
@app.route("/task")
|
peter@1
|
48 |
def task():
|
rb@100
|
49 |
return render_template(get_locale() + "/task.html", act="task")
|
peter@1
|
50 |
|
rb@100
|
51 |
@app.route("/submission")
|
peter@1
|
52 |
def submission():
|
rb@100
|
53 |
return render_template(get_locale() + "/submission.html", act="submission")
|
peter@1
|
54 |
|
rb@100
|
55 |
@app.route("/coursematerial")
|
peter@1
|
56 |
def coursematerial():
|
rb@100
|
57 |
return render_template(get_locale() + "/coursematerial.html", act="coursematerial")
|
peter@1
|
58 |
|
rb@100
|
59 |
@app.route("/imprint")
|
peter@88
|
60 |
def imprint():
|
peter@109
|
61 |
return render_template(get_locale() + "/imprint.html", act="imprint")
|
peter@88
|
62 |
|
rb@100
|
63 |
@app.route("/privacy")
|
peter@88
|
64 |
def privacy():
|
rb@100
|
65 |
return render_template(get_locale() + "/privacy.html", act="privacy")
|
peter@88
|
66 |
|
hr@112
|
67 |
|
peter@109
|
68 |
@app.route(_("/competition-2013"))
|
peter@109
|
69 |
def competition_2013():
|
hr@112
|
70 |
return render_template(get_locale() + "/archive/competitions/2013/comptetition_2013.html",
|
peter@109
|
71 |
act="coursematerial")
|
peter@109
|
72 |
|
peter@109
|
73 |
@app.route(_("/competition-2014"))
|
peter@109
|
74 |
def competition_2014():
|
hr@112
|
75 |
return render_template(get_locale() + "archive/competitions/2014/competition_2014.html",
|
peter@109
|
76 |
act="coursematerial")
|
peter@88
|
77 |
|
hr@112
|
78 |
@app.route(_("/dates"))
|
hr@112
|
79 |
def dates():
|
hr@112
|
80 |
return render_template(get_locale() + "/dates.html",
|
hr@112
|
81 |
act="dates")
|
hr@112
|
82 |
|
hr@112
|
83 |
|
peter@1
|
84 |
@app.errorhandler(404)
|
peter@1
|
85 |
def page_not_found(e):
|
rb@100
|
86 |
return render_template(get_locale() + "/404.html")
|
peter@1
|
87 |
|
peter@1
|
88 |
if __name__ == "__main__":
|
peter@1
|
89 |
app.run(host='localhost', port=5014, debug=True)
|
peter@1
|
90 |
|
peter@1
|
91 |
|