pymove3d.py
author Reimar Bauer <rb.proj AT googlemail DOT com>
Sun, 19 Jan 2014 09:45:22 +0100
changeset 155 8651d8ab829a
parent 154 9da3c136a16f
child 157 750903e3cfc0
permissions -rwxr-xr-x
creation of mo files added to Makefile
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@145
    23
app.config['BABEL_DEFAULT_LOCALE'] = 'de'
peter@145
    24
peter@142
    25
def get_topmenue():
rb@154
    26
    menue =  [('/competition', _(u'Competition')),
rb@154
    27
              ('/task', _(u'Task')),
rb@154
    28
              ('/submission', _(u'Submission')),
rb@154
    29
              ('/coursematerial', _(u'Coursematerial')),
peter@145
    30
              ]
peter@145
    31
    return menue
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"
peter@146
    54
    saying, author = get_saying()
peter@146
    55
    return render_template("/de/index.html",
peter@146
    56
                           saying = saying,
peter@146
    57
                           author = author)
rb@118
    58
rb@118
    59
@app.route('/en')
rb@118
    60
def en():
peter@146
    61
    saying, author = get_saying()
rb@118
    62
    global LANGUAGE_SELECTED
rb@118
    63
    LANGUAGE_SELECTED = "en"
peter@146
    64
    return render_template("/en/index.html",
peter@146
    65
                           saying = saying,
peter@146
    66
                           author = author)
rb@118
    67
rb@100
    68
@app.route("/competition")
peter@1
    69
def competition():
rb@100
    70
    return render_template(get_locale() + "/competition.html", act="competition")
peter@1
    71
rb@100
    72
@app.route("/task")
peter@1
    73
def task():
rb@100
    74
    return render_template(get_locale() + "/task.html", act="task")
peter@1
    75
rb@100
    76
@app.route("/submission")
peter@1
    77
def submission():
rb@100
    78
    return render_template(get_locale() + "/submission.html", act="submission")
peter@1
    79
rb@100
    80
@app.route("/coursematerial")
peter@1
    81
def coursematerial():
rb@100
    82
    return render_template(get_locale() + "/coursematerial.html", act="coursematerial")
peter@1
    83
rb@100
    84
@app.route("/imprint")
peter@88
    85
def imprint():
peter@109
    86
    return render_template(get_locale() + "/imprint.html", act="imprint")
peter@88
    87
rb@100
    88
@app.route("/privacy")
peter@88
    89
def privacy():
rb@100
    90
    return render_template(get_locale() + "/privacy.html", act="privacy")
peter@88
    91
peter@123
    92
@app.route("/competition/2013")
peter@109
    93
def competition_2013():
peter@123
    94
    print get_locale() + "/archive/competitions/2013/index.html"
peter@123
    95
    return render_template(get_locale() + "/archive/competitions/2013/index.html", 
peter@109
    96
                           act="coursematerial")
peter@109
    97
peter@123
    98
@app.route("/competition/2014")
peter@109
    99
def competition_2014():
peter@123
   100
    print get_locale() + "/archive/competitions/2014/index.html"
peter@123
   101
    return render_template(get_locale() + "/archive/competitions/2014/index.html", 
peter@109
   102
                           act="coursematerial")
peter@88
   103
rb@152
   104
@app.route("/dates")
hr@112
   105
def dates():
hr@112
   106
    return render_template(get_locale() + "/dates.html",
hr@112
   107
                           act="dates")
hr@112
   108
hr@112
   109
peter@1
   110
@app.errorhandler(404)
peter@1
   111
def page_not_found(e):
rb@100
   112
    return render_template(get_locale() + "/404.html")
peter@1
   113
peter@1
   114
if __name__ == "__main__":
peter@1
   115
    app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung