1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/eskp.py Mon May 05 10:04:09 2014 +0200
1.3 @@ -0,0 +1,178 @@
1.4 +# -*- coding: utf-8 -*-
1.5 +
1.6 +import os
1.7 +import codecs
1.8 +
1.9 +from docutils.core import publish_parts
1.10 +from flask import Flask
1.11 +from flask import render_template
1.12 +from flask import request
1.13 +from flask.ext.babel import gettext as _
1.14 +from flask.ext.babel import Babel
1.15 +from config import LANGUAGES
1.16 +from sayings import get_saying
1.17 +
1.18 +
1.19 +LANGUAGE_SELECTED = "de"
1.20 +#ToDo after engelish is implemented set LANGUAGE_SELECTED = None
1.21 +
1.22 +app = Flask(__name__)
1.23 +babel = Babel(app)
1.24 +
1.25 +app.config['BABEL_DEFAULT_LOCALE'] = 'de'
1.26 +
1.27 +
1.28 +def get_content(filename, overrides=None):
1.29 + content = u""
1.30 + if os.path.isfile(filename):
1.31 + with codecs.open(filename, 'r', 'utf-8') as f:
1.32 + rst_data = f.read()
1.33 + f.close()
1.34 + content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
1.35 + return content
1.36 +
1.37 +def get_topmenue():
1.38 + menue = [('/competition', _(u'Competition')),
1.39 + ('/task', _(u'Task')),
1.40 + ('/coursematerial', _(u'Coursematerial')),
1.41 + ('/submission', _(u'Submission')),
1.42 + ('/prizes', _(u'Prizes')),
1.43 + ]
1.44 + return menue
1.45 +
1.46 +app.jinja_env.globals.update(get_topmenue=get_topmenue)
1.47 +
1.48 +
1.49 +@babel.localeselector
1.50 +def get_locale():
1.51 + """ToDo: if translation is completed, switch to en """
1.52 + return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
1.53 +
1.54 +
1.55 +@app.route("/")
1.56 +@app.route("/index")
1.57 +def index():
1.58 + saying, author = get_saying()
1.59 + return render_template("/index.html",
1.60 + saying=saying,
1.61 + author=author,
1.62 + competition_info=_(u'About Competition'),
1.63 + dates=_(u'Dates'),
1.64 + impressions=_(u'Impressions'))
1.65 +
1.66 +@app.route('/de')
1.67 +def de():
1.68 + global LANGUAGE_SELECTED
1.69 + LANGUAGE_SELECTED = "de"
1.70 + saying, author = get_saying()
1.71 + return render_template("/index.html",
1.72 + saying=saying,
1.73 + author=author,
1.74 + competition_info=_(u'About Competition'),
1.75 + dates=_(u'Dates'),
1.76 + impressions=_(u'Impressions'))
1.77 +
1.78 +@app.route('/en')
1.79 +def en():
1.80 + saying, author = get_saying()
1.81 + global LANGUAGE_SELECTED
1.82 + LANGUAGE_SELECTED = "en"
1.83 + return render_template("/index.html",
1.84 + saying=saying,
1.85 + author=author,
1.86 + competition_info=_(u'About Competition'),
1.87 + dates=_(u'Dates'),
1.88 + impressions=_(u'Impressions'))
1.89 +
1.90 +@app.route("/competition")
1.91 +def competition():
1.92 + filename = os.path.join("templates", get_locale(), "rst", "competition.rst")
1.93 + content = get_content(filename)
1.94 + return render_template("/content.html", act="competition", content=content)
1.95 +
1.96 +@app.route("/task")
1.97 +def task():
1.98 + filename = os.path.join("templates", get_locale(), "rst", "task.rst")
1.99 + content = get_content(filename)
1.100 + return render_template("/content.html", act="task", content=content)
1.101 +
1.102 +@app.route("/submission")
1.103 +def submission():
1.104 + filename = os.path.join("templates", get_locale(), "rst", "submission.rst")
1.105 + content = get_content(filename)
1.106 + return render_template("/content.html", act="submission", content=content)
1.107 +
1.108 +@app.route("/coursematerial")
1.109 +def coursematerial():
1.110 + filename = os.path.join("templates", get_locale(), "rst", "coursematerial.rst")
1.111 + content = get_content(filename)
1.112 + return render_template("/content.html", act="coursematerial", content=content)
1.113 +
1.114 +@app.route("/imprint")
1.115 +def imprint():
1.116 + filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
1.117 + content = get_content(filename)
1.118 + return render_template("/content.html", act="imprint", content=content)
1.119 +
1.120 +@app.route("/privacy")
1.121 +def privacy():
1.122 + filename = os.path.join("templates", get_locale(), "rst", "privacy.rst")
1.123 + overrides = {
1.124 + 'initial_header_level': 2,
1.125 + }
1.126 + content = get_content(filename, overrides=overrides)
1.127 + return render_template("/content.html", act="privacy", content=content)
1.128 +
1.129 +@app.route("/dates")
1.130 +def dates():
1.131 + filename = os.path.join("templates", get_locale(), "rst", "dates.rst")
1.132 + content = get_content(filename)
1.133 + return render_template("/content.html",
1.134 + act="dates", content=content)
1.135 +
1.136 +@app.route("/prizes")
1.137 +def prizes():
1.138 + filename = os.path.join("templates", get_locale(), "rst", "prizes.rst")
1.139 + overrides = {
1.140 + 'initial_header_level': 2,
1.141 + }
1.142 + content = get_content(filename, overrides=overrides)
1.143 + return render_template("/prizes.html",act="prizes", content=content)
1.144 +
1.145 +
1.146 +
1.147 +@app.route("/competition/2013")
1.148 +def competition_2013():
1.149 + competition = _(u'Competition 2013')
1.150 + introduction = _(u'The winners of the programming competition, '
1.151 + u'showed at the PyCon.DE 2013 in Cologne their results. '
1.152 + u'A short presentation inlcuding a movie about their work done.')
1.153 + article = [_(u'Both students presented to the astonished audience of over 250 Python developers their work.'),
1.154 + _(u'A long applause showed up.'
1.155 + u' Valentin had 9 months ago learned Python and Blender discovered earlier. '
1.156 + u'His Skatsimulation even includes 3D sound.'),
1.157 + _(u'The preparatory courses were made by volunteers, such as the '
1.158 + u'employees of the magazine "Time Online" performed. '
1.159 + u'The following blog entry is a little impression of the success of the courses'),
1.160 + ]
1.161 + game_of_life = _(u'Anne a 15 year old girl showed a 3D-Version of the »Game of life«')
1.162 + skat_simulation = _(u'Valentin (13 years) demomstrates his »Skat-Simulation«')
1.163 + awards = _(u'The award ceremony')
1.164 + return render_template("/impressions_2013.html",
1.165 + act="competition_2013",
1.166 + competition=competition,
1.167 + introduction=introduction,
1.168 + article=article,
1.169 + game_of_life=game_of_life,
1.170 + skat_simulation=skat_simulation,
1.171 + awards=awards)
1.172 +
1.173 +
1.174 +@app.errorhandler(404)
1.175 +def page_not_found(e):
1.176 + msg = _(u"Url: %(url)s not found", url=request.url)
1.177 + info = _(u"This information is not available!")
1.178 + return render_template("404.html", msg=msg, info=info)
1.179 +
1.180 +if __name__ == "__main__":
1.181 + app.run(host='localhost', port=5014, debug=True)