pymove3d.py
author Stefania Trabucchi <info@trabucchi.de>
Sat, 25 Jan 2014 13:48:15 +0100
changeset 220 bd72e855edae
parent 217 2c7c55d66ec1
child 222 fe169c748b0c
permissions -rwxr-xr-x
footer sponsor imageslider changed
     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               ('/submission', _(u'Submission')),
    38               ('/coursematerial', _(u'Coursematerial')),
    39             ]
    40     return menue
    41 
    42 app.jinja_env.globals.update(get_topmenue=get_topmenue)
    43 
    44 
    45 @babel.localeselector
    46 def get_locale():
    47     """ToDo: if translation is completed, switch to en """
    48     return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
    49 
    50 
    51 @app.route("/")
    52 @app.route("/index")
    53 def index():
    54     saying, author = get_saying()
    55     return render_template("/index.html",
    56                            saying=saying,
    57                            author=author,
    58                            competition_info=_(u'About Competition'),
    59                            dates=_(u'Dates'),
    60                            impressions=_(u'Impressions'))
    61 
    62 @app.route('/de')
    63 def de():
    64     global LANGUAGE_SELECTED
    65     LANGUAGE_SELECTED = "de"
    66     saying, author = get_saying()
    67     return render_template("/index.html",
    68                            saying=saying,
    69                            author=author,
    70                            competition_info=_(u'About Competition'),
    71                            dates=_(u'Dates'),
    72                            impressions=_(u'Impressions'))
    73 
    74 @app.route('/en')
    75 def en():
    76     saying, author = get_saying()
    77     global LANGUAGE_SELECTED
    78     LANGUAGE_SELECTED = "en"
    79     return render_template("/index.html",
    80                            saying=saying,
    81                            author=author,
    82                            competition_info=_(u'About Competition'),
    83                            dates=_(u'Dates'),
    84                            impressions=_(u'Impressions'))
    85 
    86 @app.route("/competition")
    87 def competition():
    88     filename = os.path.join("templates", get_locale(), "rst", "competition.rst")
    89     content = get_content(filename)
    90     return render_template("/content.html", act="competition", content=content)
    91 
    92 @app.route("/task")
    93 def task():
    94     filename = os.path.join("templates", get_locale(), "rst", "task.rst")
    95     content = get_content(filename)
    96     return render_template("/content.html", act="task", content=content)
    97 
    98 @app.route("/submission")
    99 def submission():
   100     filename = os.path.join("templates", get_locale(), "rst", "submission.rst")
   101     content = get_content(filename)
   102     return render_template("/content.html", act="submission", content=content)
   103 
   104 @app.route("/coursematerial")
   105 def coursematerial():
   106     filename = os.path.join("templates", get_locale(), "rst", "coursematerial.rst")
   107     content = get_content(filename)
   108     return render_template("/content.html", act="coursematerial", content=content)
   109 
   110 @app.route("/imprint")
   111 def imprint():
   112     filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
   113     content = get_content(filename)
   114     return render_template("/content.html", act="imprint", content=content)
   115 
   116 @app.route("/privacy")
   117 def privacy():
   118     filename = os.path.join("templates", get_locale(), "rst", "privacy.rst")
   119     overrides = {
   120                  'initial_header_level': 2,
   121                 }
   122     content = get_content(filename, overrides=overrides)
   123     return render_template("/content.html", act="privacy", content=content)
   124 
   125 @app.route("/dates")
   126 def dates():
   127     filename = os.path.join("templates", get_locale(), "rst", "dates.rst")
   128     content = get_content(filename)
   129     return render_template("/content.html",
   130                            act="dates", content=content)
   131 
   132 @app.route("/competition/2013")
   133 def competition_2013():
   134     competition = _(u'Competition 2013')
   135     introduction = _(u'The winners of the programming competition, '
   136                      u'showed at the PyCon.DE 2013 in Cologne their results. '
   137                      u'A short presentation inlcuding a movie about their work done.')
   138     article = [_(u'Both students presented to the astonished audience of over 250 Python developers their work.'),
   139                _(u'A long applause showed up.'
   140                  u' Valentin had 9 months ago learned Python and Blender discovered earlier. '
   141                  u'His Skatsimulation even includes 3D sound.'),
   142                _(u'The preparatory courses were made by volunteers, such as the '
   143                  u'employees of the magazine "Time Online" performed. '
   144                  u'The following blog entry is a little impression of the success of the courses'),
   145               ]
   146     game_of_life = _(u'Anne a 15 year old girl showed a 3D-Version of the »Game of life«')
   147     skat_simulation = _(u'Valentin (13 years) demomstrates his »Skat-Simulation«')
   148     awards = _(u'The award ceremony')
   149     return render_template("/impressions_2013.html",
   150                            act="competition_2013",
   151                            competition=competition,
   152                            introduction=introduction,
   153                            article=article,
   154                            game_of_life=game_of_life,
   155                            skat_simulation=skat_simulation,
   156                            awards=awards)
   157 
   158 
   159 @app.errorhandler(404)
   160 def page_not_found(e):
   161     msg = _(u"Url: %(url)s not found", url=request.url)
   162     info = _(u"This information is not available!")
   163     return render_template("404.html", msg=msg, info=info)
   164 
   165 if __name__ == "__main__":
   166     app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung