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
14 LANGUAGE_SELECTED = "de"
15 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
17 # We need the path of this file to find templates to translate
18 ESKP_PATH = os.path.dirname(os.path.abspath(__file__))
23 app.config['BABEL_DEFAULT_LOCALE'] = 'de'
26 def get_content(filename, overrides=None):
28 filename = os.path.join(ESKP_PATH, filename)
29 if os.path.isfile(filename):
30 with codecs.open(filename, 'r', 'utf-8') as f:
33 content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
39 ('/ozoneloss', _(u'Ozoneloss')),
40 ('/eskp', _(u'ESKP')),
41 ('/iek-7', _(u'IEK-7')),
45 app.jinja_env.globals.update(get_topmenue=get_topmenue)
47 def get_ozone_dates():
48 menue = [('/ozoneloss/clams/2014', _(u'2014')),
49 ('/ozoneloss/clams/2013', _(u'2013')),
50 ('/ozoneloss/clams/2012', _(u'2012')),
51 ('/ozoneloss/clams/2011', _(u'2011')),
52 ('/ozoneloss/clams/2010', _(u'2010')),
57 menue = [('/ozoneloss/vpsc/2014', _(u'2014')),
58 ('/ozoneloss/vpsc/2013', _(u'2013')),
59 ('/ozoneloss/vpsc/2012', _(u'2012')),
60 ('/ozoneloss/vpsc/2011', _(u'2011')),
61 ('/ozoneloss/vpsc/2010', _(u'2010')),
65 app.jinja_env.globals.update(get_ozone_dates=get_ozone_dates)
66 app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
70 """ToDo: if translation is completed, switch to en """
71 return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
77 return render_template("/index.html",
78 eskp_info=_(u'About ESKP'),
82 @app.route('/ozoneloss/clams/2014')
84 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
85 content = get_content(filename)
86 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2014", content=content, year=2014)
88 @app.route('/ozoneloss/clams/2013')
90 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
91 content = get_content(filename)
92 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2013", content=content, year=2013)
94 @app.route('/ozoneloss/clams/2012')
96 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
97 content = get_content(filename)
98 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2012", content=content, year=2012)
100 @app.route('/ozoneloss/clams/2011')
102 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
103 content = get_content(filename)
104 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2011", content=content, year=2011)
106 @app.route('/ozoneloss/clams/2010')
108 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
109 content = get_content(filename)
110 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2010", content=content, year=2010)
112 @app.route('/ozoneloss/vpsc/2014')
114 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
115 content = get_content(filename)
116 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, year=2014)
118 @app.route('/ozoneloss/vpsc/2013')
120 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
121 content = get_content(filename)
122 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2013", content=content, year=2013)
124 @app.route('/ozoneloss/vpsc/2012')
126 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
127 content = get_content(filename)
128 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2012", content=content, year=2012)
130 @app.route('/ozoneloss/vpsc/2011')
132 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
133 content = get_content(filename)
134 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2011", content=content, year=2011)
136 @app.route('/ozoneloss/vpsc/2010')
138 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
139 content = get_content(filename)
140 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2010", content=content, year=2010)
144 global LANGUAGE_SELECTED
145 LANGUAGE_SELECTED = "de"
146 saying, author = get_saying()
147 return render_template("/index.html",
150 eskp_info=_(u'About ESKP'),
155 saying, author = get_saying()
156 global LANGUAGE_SELECTED
157 LANGUAGE_SELECTED = "en"
158 return render_template("/index.html",
161 eskp_info=_(u'About ESKP'),
166 filename = os.path.join("templates", get_locale(), "rst", "eskp.rst")
167 content = get_content(filename)
168 return render_template("/content.html", act="eskp", content=content)
170 @app.route("/ozoneloss")
172 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
173 content = get_content(filename)
174 return render_template("/ozoneloss.html", act="ozoneloss", content=content)
176 @app.route("/ozoneloss/clams")
178 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
179 content = get_content(filename)
180 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams", content=content)
182 @app.route("/ozoneloss/vpsc")
184 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
185 content = get_content(filename)
186 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc", content=content)
190 filename = os.path.join("templates", get_locale(), "rst", "iek-7.rst")
191 content = get_content(filename)
192 return render_template("/content.html", act="submission", content=content)
195 @app.route("/imprint")
197 filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
198 content = get_content(filename)
199 return render_template("/content.html", act="imprint", content=content)
203 @app.errorhandler(404)
204 def page_not_found(e):
205 msg = _(u"Url: %(url)s not found", url=request.url)
206 info = _(u"This information is not available!")
207 return render_template("404.html", msg=msg, info=info)
209 if __name__ == "__main__":
210 app.run(host='localhost', port=5014, debug=True)