1 # -*- coding: utf-8 -*-
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
16 LANGUAGE_SELECTED = "de"
17 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
22 app.config['BABEL_DEFAULT_LOCALE'] = 'de'
25 def get_content(filename, overrides=None):
27 if os.path.isfile(filename):
28 with codecs.open(filename, 'r', 'utf-8') as f:
31 content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
35 menue = [('/competition', _(u'Competition')),
36 ('/task', _(u'Task')),
37 ('/submission', _(u'Submission')),
38 ('/coursematerial', _(u'Coursematerial')),
42 app.jinja_env.globals.update(get_topmenue=get_topmenue)
47 """ToDo: if translation is completed, switch to en """
48 return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
54 saying, author = get_saying()
55 return render_template("/index.html",
58 competition_info=_(u'About Competition'),
60 impressions=_(u'Impressions'))
64 global LANGUAGE_SELECTED
65 LANGUAGE_SELECTED = "de"
66 saying, author = get_saying()
67 return render_template("/index.html",
70 competition_info=_(u'About Competition'),
72 impressions=_(u'Impressions'))
76 saying, author = get_saying()
77 global LANGUAGE_SELECTED
78 LANGUAGE_SELECTED = "en"
79 return render_template("/index.html",
82 competition_info=_(u'About Competition'),
84 impressions=_(u'Impressions'))
86 @app.route("/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)
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)
98 @app.route("/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)
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)
110 @app.route("/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)
116 @app.route("/privacy")
118 filename = os.path.join("templates", get_locale(), "rst", "privacy.rst")
120 'initial_header_level': 2,
122 content = get_content(filename, overrides=overrides)
123 return render_template("/content.html", act="privacy", content=content)
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)
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'),
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,
154 game_of_life=game_of_life,
155 skat_simulation=skat_simulation,
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)
165 if __name__ == "__main__":
166 app.run(host='localhost', port=5014, debug=True)