pymove3d.py
author Peter Koppatz <peter@koppatz.com>
Sat, 18 Jan 2014 21:05:22 +0100
changeset 144 3b768d0f09ef
parent 142 6dea01810014
child 145 95d788307e42
permissions -rwxr-xr-x
code revue
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
    topmenue = [('/competition', _('Competition')),
peter@142
    25
                ('/task', _('Task')),
peter@142
    26
                ('/submission', _('Submission')),
peter@142
    27
                ('/coursematerial', _('Coursematerial')),
peter@142
    28
                ]
peter@142
    29
    
peter@142
    30
    return topmenue
peter@142
    31
peter@142
    32
app.jinja_env.globals.update(get_topmenue=get_topmenue)
peter@142
    33
peter@142
    34
peter@1
    35
@babel.localeselector
peter@1
    36
def get_locale():
peter@109
    37
    """ToDo: if translation is completed, switch to en """
rb@118
    38
    return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
peter@1
    39
rb@100
    40
peter@1
    41
@app.route("/")
rb@100
    42
@app.route("/index")
peter@1
    43
def index():
peter@141
    44
    saying, author = get_saying()
peter@141
    45
    return render_template(get_locale() + "/index.html", 
peter@141
    46
                           saying = saying,
peter@141
    47
                           author = author)
peter@1
    48
rb@118
    49
@app.route('/de')
rb@118
    50
def de():
rb@118
    51
    global LANGUAGE_SELECTED
rb@118
    52
    LANGUAGE_SELECTED = "de"
rb@118
    53
    return render_template("/de/index.html")
rb@118
    54
rb@118
    55
@app.route('/en')
rb@118
    56
def en():
rb@118
    57
    global LANGUAGE_SELECTED
rb@118
    58
    LANGUAGE_SELECTED = "en"
rb@118
    59
    return render_template("/en/index.html")
rb@118
    60
rb@100
    61
@app.route("/competition")
peter@1
    62
def competition():
rb@100
    63
    return render_template(get_locale() + "/competition.html", act="competition")
peter@1
    64
rb@100
    65
@app.route("/task")
peter@1
    66
def task():
rb@100
    67
    return render_template(get_locale() + "/task.html", act="task")
peter@1
    68
rb@100
    69
@app.route("/submission")
peter@1
    70
def submission():
rb@100
    71
    return render_template(get_locale() + "/submission.html", act="submission")
peter@1
    72
rb@100
    73
@app.route("/coursematerial")
peter@1
    74
def coursematerial():
rb@100
    75
    return render_template(get_locale() + "/coursematerial.html", act="coursematerial")
peter@1
    76
rb@100
    77
@app.route("/imprint")
peter@88
    78
def imprint():
peter@109
    79
    return render_template(get_locale() + "/imprint.html", act="imprint")
peter@88
    80
rb@100
    81
@app.route("/privacy")
peter@88
    82
def privacy():
rb@100
    83
    return render_template(get_locale() + "/privacy.html", act="privacy")
peter@88
    84
peter@123
    85
@app.route("/competition/2013")
peter@109
    86
def competition_2013():
peter@123
    87
    print get_locale() + "/archive/competitions/2013/index.html"
peter@123
    88
    return render_template(get_locale() + "/archive/competitions/2013/index.html", 
peter@109
    89
                           act="coursematerial")
peter@109
    90
peter@123
    91
@app.route("/competition/2014")
peter@109
    92
def competition_2014():
peter@123
    93
    print get_locale() + "/archive/competitions/2014/index.html"
peter@123
    94
    return render_template(get_locale() + "/archive/competitions/2014/index.html", 
peter@109
    95
                           act="coursematerial")
peter@88
    96
hr@112
    97
@app.route(_("/dates"))
hr@112
    98
def dates():
hr@112
    99
    return render_template(get_locale() + "/dates.html",
hr@112
   100
                           act="dates")
hr@112
   101
hr@112
   102
peter@1
   103
@app.errorhandler(404)
peter@1
   104
def page_not_found(e):
rb@100
   105
    return render_template(get_locale() + "/404.html")
peter@1
   106
peter@1
   107
if __name__ == "__main__":
peter@1
   108
    app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung