pymove3d.py
author Stefania Trabucchi <info@trabucchi.de>
Sat, 18 Jan 2014 16:22:05 +0100
changeset 137 805480530d7e
parent 123 9eb7837f7332
child 141 ea70f3d81676
permissions -rwxr-xr-x
new headline added
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@122
    15
LANGUAGE_SELECTED = "de"
rb@122
    16
#ToDo after engelish is implemented set LANGUAGE_SELECTED = None
rb@95
    17
peter@1
    18
app = Flask(__name__)
peter@1
    19
babel = Babel(app)
peter@1
    20
peter@1
    21
@babel.localeselector
peter@1
    22
def get_locale():
peter@109
    23
    """ToDo: if translation is completed, switch to en """
rb@118
    24
    return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
peter@1
    25
rb@100
    26
peter@1
    27
@app.route("/")
rb@100
    28
@app.route("/index")
peter@1
    29
def index():
rb@100
    30
    return render_template(get_locale() + "/index.html")
peter@1
    31
rb@118
    32
@app.route('/de')
rb@118
    33
def de():
rb@118
    34
    global LANGUAGE_SELECTED
rb@118
    35
    LANGUAGE_SELECTED = "de"
rb@118
    36
    return render_template("/de/index.html")
rb@118
    37
rb@118
    38
@app.route('/en')
rb@118
    39
def en():
rb@118
    40
    global LANGUAGE_SELECTED
rb@118
    41
    LANGUAGE_SELECTED = "en"
rb@118
    42
    return render_template("/en/index.html")
rb@118
    43
rb@100
    44
@app.route("/competition")
peter@1
    45
def competition():
rb@100
    46
    return render_template(get_locale() + "/competition.html", act="competition")
peter@1
    47
rb@100
    48
@app.route("/task")
peter@1
    49
def task():
rb@100
    50
    return render_template(get_locale() + "/task.html", act="task")
peter@1
    51
rb@100
    52
@app.route("/submission")
peter@1
    53
def submission():
rb@100
    54
    return render_template(get_locale() + "/submission.html", act="submission")
peter@1
    55
rb@100
    56
@app.route("/coursematerial")
peter@1
    57
def coursematerial():
rb@100
    58
    return render_template(get_locale() + "/coursematerial.html", act="coursematerial")
peter@1
    59
rb@100
    60
@app.route("/imprint")
peter@88
    61
def imprint():
peter@109
    62
    return render_template(get_locale() + "/imprint.html", act="imprint")
peter@88
    63
rb@100
    64
@app.route("/privacy")
peter@88
    65
def privacy():
rb@100
    66
    return render_template(get_locale() + "/privacy.html", act="privacy")
peter@88
    67
peter@123
    68
@app.route("/competition/2013")
peter@109
    69
def competition_2013():
peter@123
    70
    print get_locale() + "/archive/competitions/2013/index.html"
peter@123
    71
    return render_template(get_locale() + "/archive/competitions/2013/index.html", 
peter@109
    72
                           act="coursematerial")
peter@109
    73
peter@123
    74
@app.route("/competition/2014")
peter@109
    75
def competition_2014():
peter@123
    76
    print get_locale() + "/archive/competitions/2014/index.html"
peter@123
    77
    return render_template(get_locale() + "/archive/competitions/2014/index.html", 
peter@109
    78
                           act="coursematerial")
peter@88
    79
hr@112
    80
@app.route(_("/dates"))
hr@112
    81
def dates():
hr@112
    82
    return render_template(get_locale() + "/dates.html",
hr@112
    83
                           act="dates")
hr@112
    84
hr@112
    85
peter@1
    86
@app.errorhandler(404)
peter@1
    87
def page_not_found(e):
rb@100
    88
    return render_template(get_locale() + "/404.html")
peter@1
    89
peter@1
    90
if __name__ == "__main__":
peter@1
    91
    app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung