1 # -*- coding: utf-8 -*-
6 from docutils.core import publish_parts
7 from flask import Flask, Response
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'
25 def get_content(filename, overrides=None):
27 filename = os.path.join(ESKP_PATH, filename)
28 if os.path.isfile(filename):
29 with codecs.open(filename, 'r', 'utf-8') as f:
32 content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
37 ('/ozoneloss', _(u'Ozoneloss')),
38 ('/eskp', _(u'ESKP')),
39 ('/iek-7', _(u'IEK-7')),
43 app.jinja_env.globals.update(get_topmenue=get_topmenue)
45 def get_o3lossclams_dates():
46 menue = [('/ozoneloss/clams/2012', _(u'2012')),
47 ('/ozoneloss/clams/2011', _(u'2011')),
48 ('/ozoneloss/clams/2010', _(u'2010')),
53 menue = [('/ozoneloss/vpsc/2014', _(u'2014')),
54 ('/ozoneloss/vpsc/2013', _(u'2013')),
55 ('/ozoneloss/vpsc/2012', _(u'2012')),
56 ('/ozoneloss/vpsc/2011', _(u'2011')),
57 ('/ozoneloss/vpsc/2010', _(u'2010')),
61 app.jinja_env.globals.update(get_o3lossclams_dates=get_o3lossclams_dates)
62 app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
64 def author_info(name, filename):
65 content = get_content(filename)
66 html = render_template("/author_info.html", act="author", title=name, content=content, exit=_(u"Close"))
72 """ToDo: if translation is completed, switch to en """
73 return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
79 return render_template("/index.html",
80 eskp_info=_(u'About ESKP'),
84 @app.route('/ozoneloss/clams/<year>')
85 def ozoneloss_clams_year(year):
86 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
87 content = get_content(filename)
88 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/%s" % year, content=content, year=year)
91 @app.route('/ozoneloss/vpsc/<year>')
92 def ozoneloss_vspc_year(year):
93 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
94 content = get_content(filename)
95 filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
96 explanation = get_content(filename)
98 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/%s" % year, content=content,
99 content_explanation=explanation, year=year)
103 global LANGUAGE_SELECTED
104 LANGUAGE_SELECTED = "de"
105 return render_template("/index.html",
106 eskp_info=_(u'About ESKP'),
111 global LANGUAGE_SELECTED
112 LANGUAGE_SELECTED = "en"
113 return render_template("/index.html",
114 eskp_info=_(u'About ESKP'),
119 filename = os.path.join("templates", get_locale(), "rst", "eskp.rst")
120 content = get_content(filename)
121 return render_template("/eskp.html", act="eskp", content=content)
124 @app.route("/ozoneloss")
126 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
127 content = get_content(filename)
128 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_author.rst")
129 author = author_info(_(u"Ozoneloss"), filename)
130 return render_template("/ozoneloss.html", act="ozoneloss", content=content,
131 author=author, contact = u"Dr. Jens-Uwe Grooß", publications=u"Publications" )
133 @app.route("/ozoneloss/clams")
134 def ozoneloss_clams():
135 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
136 content = get_content(filename)
137 return render_template("/ozoneloss_clams.html", act="ozoneloss/clams", content=content)
139 @app.route("/ozoneloss/vpsc")
140 def ozoneloss_vspc():
141 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
142 content = get_content(filename)
143 return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc", content=content)
147 filename = os.path.join("templates", get_locale(), "rst", "iek-7.rst")
148 content = get_content(filename)
149 filename = os.path.join("templates", get_locale(), "rst", "iek-7_author.rst")
150 author = author_info(_(u"IEK-7"), filename)
151 return render_template("/iek-7.html", act="iek-7", content=content,
152 author=author, contact = u"Sandra Stein")
155 @app.route("/imprint")
157 filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
158 content = get_content(filename)
159 return render_template("/content.html", act="imprint", content=content)
165 @app.errorhandler(404)
166 def page_not_found(e):
167 msg = _(u"Url: %(url)s not found", url=request.url)
168 info = _(u"This information is not available!")
169 return render_template("404.html", msg=msg, info=info)
171 if __name__ == "__main__":
172 app.run(host='localhost', port=5014, debug=True)