eskp.py
author Reimar Bauer <rb.proj AT googlemail DOT com>
Mon, 05 May 2014 10:04:09 +0200
changeset 232 ec1bb552ce55
parent 226 pymove3d.py@a49b43868b34
child 233 c97120328e9c
permissions -rwxr-xr-x
fork of pymoved3D 231:63405034e061 for initialisation of eskp
     1 # -*- coding: utf-8 -*-
     2 
     3 import os
     4 import codecs
     5 
     6 from docutils.core import publish_parts
     7 from flask import Flask
     8 from flask import render_template
     9 from flask import request
    10 from flask.ext.babel import gettext as _
    11 from flask.ext.babel import Babel
    12 from config import LANGUAGES
    13 from sayings import get_saying
    14 
    15 
    16 LANGUAGE_SELECTED = "de"
    17 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
    18 
    19 app = Flask(__name__)
    20 babel = Babel(app)
    21 
    22 app.config['BABEL_DEFAULT_LOCALE'] = 'de'
    23 
    24 
    25 def get_content(filename, overrides=None):
    26     content = u""
    27     if os.path.isfile(filename):
    28         with codecs.open(filename, 'r', 'utf-8') as f:
    29             rst_data = f.read()
    30         f.close()
    31         content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
    32     return content
    33 
    34 def get_topmenue():
    35     menue = [('/competition', _(u'Competition')),
    36               ('/task', _(u'Task')),
    37               ('/coursematerial', _(u'Coursematerial')),
    38               ('/submission', _(u'Submission')),
    39               ('/prizes', _(u'Prizes')),
    40             ]
    41     return menue
    42 
    43 app.jinja_env.globals.update(get_topmenue=get_topmenue)
    44 
    45 
    46 @babel.localeselector
    47 def get_locale():
    48     """ToDo: if translation is completed, switch to en """
    49     return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
    50 
    51 
    52 @app.route("/")
    53 @app.route("/index")
    54 def index():
    55     saying, author = get_saying()
    56     return render_template("/index.html",
    57                            saying=saying,
    58                            author=author,
    59                            competition_info=_(u'About Competition'),
    60                            dates=_(u'Dates'),
    61                            impressions=_(u'Impressions'))
    62 
    63 @app.route('/de')
    64 def de():
    65     global LANGUAGE_SELECTED
    66     LANGUAGE_SELECTED = "de"
    67     saying, author = get_saying()
    68     return render_template("/index.html",
    69                            saying=saying,
    70                            author=author,
    71                            competition_info=_(u'About Competition'),
    72                            dates=_(u'Dates'),
    73                            impressions=_(u'Impressions'))
    74 
    75 @app.route('/en')
    76 def en():
    77     saying, author = get_saying()
    78     global LANGUAGE_SELECTED
    79     LANGUAGE_SELECTED = "en"
    80     return render_template("/index.html",
    81                            saying=saying,
    82                            author=author,
    83                            competition_info=_(u'About Competition'),
    84                            dates=_(u'Dates'),
    85                            impressions=_(u'Impressions'))
    86 
    87 @app.route("/competition")
    88 def competition():
    89     filename = os.path.join("templates", get_locale(), "rst", "competition.rst")
    90     content = get_content(filename)
    91     return render_template("/content.html", act="competition", content=content)
    92 
    93 @app.route("/task")
    94 def task():
    95     filename = os.path.join("templates", get_locale(), "rst", "task.rst")
    96     content = get_content(filename)
    97     return render_template("/content.html", act="task", content=content)
    98 
    99 @app.route("/submission")
   100 def submission():
   101     filename = os.path.join("templates", get_locale(), "rst", "submission.rst")
   102     content = get_content(filename)
   103     return render_template("/content.html", act="submission", content=content)
   104 
   105 @app.route("/coursematerial")
   106 def coursematerial():
   107     filename = os.path.join("templates", get_locale(), "rst", "coursematerial.rst")
   108     content = get_content(filename)
   109     return render_template("/content.html", act="coursematerial", content=content)
   110 
   111 @app.route("/imprint")
   112 def imprint():
   113     filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
   114     content = get_content(filename)
   115     return render_template("/content.html", act="imprint", content=content)
   116 
   117 @app.route("/privacy")
   118 def privacy():
   119     filename = os.path.join("templates", get_locale(), "rst", "privacy.rst")
   120     overrides = {
   121                  'initial_header_level': 2,
   122                 }
   123     content = get_content(filename, overrides=overrides)
   124     return render_template("/content.html", act="privacy", content=content)
   125 
   126 @app.route("/dates")
   127 def dates():
   128     filename = os.path.join("templates", get_locale(), "rst", "dates.rst")
   129     content = get_content(filename)
   130     return render_template("/content.html",
   131                            act="dates", content=content)
   132 
   133 @app.route("/prizes")
   134 def prizes():
   135     filename = os.path.join("templates", get_locale(), "rst", "prizes.rst")
   136     overrides = {
   137                  'initial_header_level': 2,
   138                 }
   139     content = get_content(filename, overrides=overrides)
   140     return render_template("/prizes.html",act="prizes", content=content)
   141 
   142 
   143 
   144 @app.route("/competition/2013")
   145 def competition_2013():
   146     competition = _(u'Competition 2013')
   147     introduction = _(u'The winners of the programming competition, '
   148                      u'showed at the PyCon.DE 2013 in Cologne their results. '
   149                      u'A short presentation inlcuding a movie about their work done.')
   150     article = [_(u'Both students presented to the astonished audience of over 250 Python developers their work.'),
   151                _(u'A long applause showed up.'
   152                  u' Valentin had 9 months ago learned Python and Blender discovered earlier. '
   153                  u'His Skatsimulation even includes 3D sound.'),
   154                _(u'The preparatory courses were made by volunteers, such as the '
   155                  u'employees of the magazine "Time Online" performed. '
   156                  u'The following blog entry is a little impression of the success of the courses'),
   157               ]
   158     game_of_life = _(u'Anne a 15 year old girl showed a 3D-Version of the »Game of life«')
   159     skat_simulation = _(u'Valentin (13 years) demomstrates his »Skat-Simulation«')
   160     awards = _(u'The award ceremony')
   161     return render_template("/impressions_2013.html",
   162                            act="competition_2013",
   163                            competition=competition,
   164                            introduction=introduction,
   165                            article=article,
   166                            game_of_life=game_of_life,
   167                            skat_simulation=skat_simulation,
   168                            awards=awards)
   169 
   170 
   171 @app.errorhandler(404)
   172 def page_not_found(e):
   173     msg = _(u"Url: %(url)s not found", url=request.url)
   174     info = _(u"This information is not available!")
   175     return render_template("404.html", msg=msg, info=info)
   176 
   177 if __name__ == "__main__":
   178     app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung