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_o3lossclams_dates():
48 menue = [('/ozoneloss/clams/2012', _(u'2012')),
49 ('/ozoneloss/clams/2011', _(u'2011')),
50 ('/ozoneloss/clams/2010', _(u'2010')),
55 menue = [('/ozoneloss/vpsc/2014', _(u'2014')),
56 ('/ozoneloss/vpsc/2013', _(u'2013')),
57 ('/ozoneloss/vpsc/2012', _(u'2012')),
58 ('/ozoneloss/vpsc/2011', _(u'2011')),
59 ('/ozoneloss/vpsc/2010', _(u'2010')),
63 app.jinja_env.globals.update(get_o3lossclams_dates=get_o3lossclams_dates)
64 app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
68 """ToDo: if translation is completed, switch to en """
69 return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
75 return render_template("/index.html",
76 eskp_info=_(u'About ESKP'),
80 @app.route('/ozoneloss/clams/2014')
82 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
83 content = get_content(filename)
84 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2014", content=content, year=2014)
86 @app.route('/ozoneloss/clams/2013')
88 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
89 content = get_content(filename)
90 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2013", content=content, year=2013)
92 @app.route('/ozoneloss/clams/2012')
94 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
95 content = get_content(filename)
96 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2012", content=content, year=2012)
98 @app.route('/ozoneloss/clams/2011')
100 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
101 content = get_content(filename)
102 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2011", content=content, year=2011)
104 @app.route('/ozoneloss/clams/2010')
106 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
107 content = get_content(filename)
108 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2010", content=content, year=2010)
110 @app.route('/ozoneloss/vpsc/2014')
112 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
113 content = get_content(filename)
114 filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
115 explanation = get_content(filename)
117 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2014)
119 @app.route('/ozoneloss/vpsc/2013')
121 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
122 content = get_content(filename)
123 filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
124 explanation = get_content(filename)
126 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2013)
128 @app.route('/ozoneloss/vpsc/2012')
130 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
131 content = get_content(filename)
132 filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
133 explanation = get_content(filename)
135 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2012)
137 @app.route('/ozoneloss/vpsc/2011')
139 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
140 content = get_content(filename)
141 filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
142 explanation = get_content(filename)
144 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2011)
146 @app.route('/ozoneloss/vpsc/2010')
148 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
149 content = get_content(filename)
150 filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
151 explanation = get_content(filename)
153 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2011)
157 global LANGUAGE_SELECTED
158 LANGUAGE_SELECTED = "de"
159 saying, author = get_saying()
160 return render_template("/index.html",
163 eskp_info=_(u'About ESKP'),
168 saying, author = get_saying()
169 global LANGUAGE_SELECTED
170 LANGUAGE_SELECTED = "en"
171 return render_template("/index.html",
174 eskp_info=_(u'About ESKP'),
179 filename = os.path.join("templates", get_locale(), "rst", "eskp.rst")
180 content = get_content(filename)
181 return render_template("/eskp.html", act="eskp", content=content)
184 @app.route("/ozoneloss")
186 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
187 content = get_content(filename)
188 return render_template("/ozoneloss.html", act="ozoneloss", content=content)
190 @app.route("/ozoneloss/clams")
192 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
193 content = get_content(filename)
194 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams", content=content)
196 @app.route("/ozoneloss/vpsc")
198 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
199 content = get_content(filename)
200 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc", content=content)
204 filename = os.path.join("templates", get_locale(), "rst", "iek-7.rst")
205 content = get_content(filename)
206 return render_template("/iek-7.html", act="submission", content=content)
209 @app.route("/imprint")
211 filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
212 content = get_content(filename)
213 return render_template("/content.html", act="imprint", content=content)
217 @app.errorhandler(404)
218 def page_not_found(e):
219 msg = _(u"Url: %(url)s not found", url=request.url)
220 info = _(u"This information is not available!")
221 return render_template("404.html", msg=msg, info=info)
223 if __name__ == "__main__":
224 app.run(host='localhost', port=5014, debug=True)