rb@217
|
1 |
# -*- coding: utf-8 -*-
|
rb@217
|
2 |
|
rb@186
|
3 |
import os
|
rb@186
|
4 |
import codecs
|
rb@186
|
5 |
|
rb@186
|
6 |
from docutils.core import publish_parts
|
peter@1
|
7 |
from flask import Flask
|
peter@1
|
8 |
from flask import render_template
|
peter@1
|
9 |
from flask import request
|
rb@95
|
10 |
from flask.ext.babel import gettext as _
|
peter@1
|
11 |
from flask.ext.babel import Babel
|
rb@95
|
12 |
from config import LANGUAGES
|
rb@161
|
13 |
|
rb@122
|
14 |
LANGUAGE_SELECTED = "de"
|
rb@122
|
15 |
#ToDo after engelish is implemented set LANGUAGE_SELECTED = None
|
rb@95
|
16 |
|
rb@246
|
17 |
# We need the path of this file to find templates to translate
|
rb@246
|
18 |
ESKP_PATH = os.path.dirname(os.path.abspath(__file__))
|
rb@246
|
19 |
|
peter@1
|
20 |
app = Flask(__name__)
|
peter@1
|
21 |
babel = Babel(app)
|
peter@1
|
22 |
|
peter@145
|
23 |
app.config['BABEL_DEFAULT_LOCALE'] = 'de'
|
peter@145
|
24 |
|
rb@186
|
25 |
|
rb@214
|
26 |
def get_content(filename, overrides=None):
|
rb@162
|
27 |
content = u""
|
rb@246
|
28 |
filename = os.path.join(ESKP_PATH, filename)
|
rb@162
|
29 |
if os.path.isfile(filename):
|
rb@162
|
30 |
with codecs.open(filename, 'r', 'utf-8') as f:
|
rb@162
|
31 |
rst_data = f.read()
|
rb@162
|
32 |
f.close()
|
rb@214
|
33 |
content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
|
rb@162
|
34 |
return content
|
rb@162
|
35 |
|
peter@142
|
36 |
def get_topmenue():
|
rb@238
|
37 |
menue = [
|
j@247
|
38 |
('/', _(u'Home')),
|
rb@238
|
39 |
('/ozoneloss', _(u'Ozoneloss')),
|
rb@238
|
40 |
('/eskp', _(u'ESKP')),
|
rb@238
|
41 |
('/iek-7', _(u'IEK-7')),
|
rb@186
|
42 |
]
|
peter@145
|
43 |
return menue
|
peter@142
|
44 |
|
peter@142
|
45 |
app.jinja_env.globals.update(get_topmenue=get_topmenue)
|
peter@142
|
46 |
|
j@250
|
47 |
def get_o3lossclams_dates():
|
j@250
|
48 |
menue = [('/ozoneloss/clams/2012', _(u'2012')),
|
j@249
|
49 |
('/ozoneloss/clams/2011', _(u'2011')),
|
j@249
|
50 |
('/ozoneloss/clams/2010', _(u'2010')),
|
j@249
|
51 |
]
|
j@249
|
52 |
return menue
|
j@249
|
53 |
|
j@249
|
54 |
def get_vpsc_dates():
|
j@249
|
55 |
menue = [('/ozoneloss/vpsc/2014', _(u'2014')),
|
j@249
|
56 |
('/ozoneloss/vpsc/2013', _(u'2013')),
|
j@249
|
57 |
('/ozoneloss/vpsc/2012', _(u'2012')),
|
j@249
|
58 |
('/ozoneloss/vpsc/2011', _(u'2011')),
|
j@249
|
59 |
('/ozoneloss/vpsc/2010', _(u'2010')),
|
rb@241
|
60 |
]
|
rb@241
|
61 |
return menue
|
rb@241
|
62 |
|
j@250
|
63 |
app.jinja_env.globals.update(get_o3lossclams_dates=get_o3lossclams_dates)
|
j@249
|
64 |
app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
|
peter@142
|
65 |
|
peter@1
|
66 |
@babel.localeselector
|
peter@1
|
67 |
def get_locale():
|
peter@109
|
68 |
"""ToDo: if translation is completed, switch to en """
|
rb@118
|
69 |
return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
|
peter@1
|
70 |
|
rb@100
|
71 |
|
peter@1
|
72 |
@app.route("/")
|
rb@100
|
73 |
@app.route("/index")
|
peter@1
|
74 |
def index():
|
rb@213
|
75 |
return render_template("/index.html",
|
rb@233
|
76 |
eskp_info=_(u'About ESKP'),
|
rb@233
|
77 |
)
|
peter@1
|
78 |
|
rb@241
|
79 |
|
j@249
|
80 |
@app.route('/ozoneloss/clams/2014')
|
rb@241
|
81 |
def y2014():
|
j@249
|
82 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
|
rb@241
|
83 |
content = get_content(filename)
|
j@249
|
84 |
return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2014", content=content, year=2014)
|
rb@241
|
85 |
|
j@249
|
86 |
@app.route('/ozoneloss/clams/2013')
|
rb@241
|
87 |
def y2013():
|
j@249
|
88 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
|
rb@241
|
89 |
content = get_content(filename)
|
j@249
|
90 |
return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2013", content=content, year=2013)
|
rb@241
|
91 |
|
j@249
|
92 |
@app.route('/ozoneloss/clams/2012')
|
rb@241
|
93 |
def y2012():
|
j@249
|
94 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
|
rb@241
|
95 |
content = get_content(filename)
|
j@249
|
96 |
return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2012", content=content, year=2012)
|
rb@241
|
97 |
|
j@249
|
98 |
@app.route('/ozoneloss/clams/2011')
|
rb@241
|
99 |
def y2011():
|
j@249
|
100 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
|
rb@241
|
101 |
content = get_content(filename)
|
j@249
|
102 |
return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2011", content=content, year=2011)
|
rb@241
|
103 |
|
j@249
|
104 |
@app.route('/ozoneloss/clams/2010')
|
rb@241
|
105 |
def y2010():
|
j@249
|
106 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
|
rb@241
|
107 |
content = get_content(filename)
|
j@249
|
108 |
return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2010", content=content, year=2010)
|
j@249
|
109 |
|
j@249
|
110 |
@app.route('/ozoneloss/vpsc/2014')
|
j@249
|
111 |
def y2014a():
|
j@249
|
112 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
|
j@249
|
113 |
content = get_content(filename)
|
j@250
|
114 |
filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
|
j@250
|
115 |
explanation = get_content(filename)
|
j@250
|
116 |
|
j@250
|
117 |
return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2014)
|
j@249
|
118 |
|
j@249
|
119 |
@app.route('/ozoneloss/vpsc/2013')
|
j@249
|
120 |
def y2013a():
|
j@249
|
121 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
|
j@249
|
122 |
content = get_content(filename)
|
j@250
|
123 |
filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
|
j@250
|
124 |
explanation = get_content(filename)
|
j@250
|
125 |
|
j@250
|
126 |
return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2013)
|
j@249
|
127 |
|
j@249
|
128 |
@app.route('/ozoneloss/vpsc/2012')
|
j@249
|
129 |
def y2012a():
|
j@249
|
130 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
|
j@249
|
131 |
content = get_content(filename)
|
j@250
|
132 |
filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
|
j@250
|
133 |
explanation = get_content(filename)
|
j@250
|
134 |
|
j@250
|
135 |
return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2012)
|
j@249
|
136 |
|
j@249
|
137 |
@app.route('/ozoneloss/vpsc/2011')
|
j@249
|
138 |
def y2011a():
|
j@249
|
139 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
|
j@249
|
140 |
content = get_content(filename)
|
j@250
|
141 |
filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
|
j@250
|
142 |
explanation = get_content(filename)
|
j@250
|
143 |
|
j@250
|
144 |
return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2011)
|
j@249
|
145 |
|
j@249
|
146 |
@app.route('/ozoneloss/vpsc/2010')
|
j@249
|
147 |
def y2010a():
|
j@249
|
148 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
|
j@249
|
149 |
content = get_content(filename)
|
j@250
|
150 |
filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
|
j@250
|
151 |
explanation = get_content(filename)
|
j@250
|
152 |
|
j@250
|
153 |
return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2011)
|
rb@241
|
154 |
|
rb@118
|
155 |
@app.route('/de')
|
rb@118
|
156 |
def de():
|
rb@118
|
157 |
global LANGUAGE_SELECTED
|
rb@118
|
158 |
LANGUAGE_SELECTED = "de"
|
peter@146
|
159 |
saying, author = get_saying()
|
peter@160
|
160 |
return render_template("/index.html",
|
rb@186
|
161 |
saying=saying,
|
rb@186
|
162 |
author=author,
|
rb@233
|
163 |
eskp_info=_(u'About ESKP'),
|
rb@233
|
164 |
)
|
rb@118
|
165 |
|
rb@118
|
166 |
@app.route('/en')
|
rb@118
|
167 |
def en():
|
peter@146
|
168 |
saying, author = get_saying()
|
rb@118
|
169 |
global LANGUAGE_SELECTED
|
rb@118
|
170 |
LANGUAGE_SELECTED = "en"
|
peter@160
|
171 |
return render_template("/index.html",
|
rb@186
|
172 |
saying=saying,
|
rb@186
|
173 |
author=author,
|
rb@233
|
174 |
eskp_info=_(u'About ESKP'),
|
rb@233
|
175 |
)
|
rb@118
|
176 |
|
rb@233
|
177 |
@app.route("/eskp")
|
rb@233
|
178 |
def eskp():
|
rb@233
|
179 |
filename = os.path.join("templates", get_locale(), "rst", "eskp.rst")
|
rb@162
|
180 |
content = get_content(filename)
|
rb@233
|
181 |
return render_template("/content.html", act="eskp", content=content)
|
peter@1
|
182 |
|
rb@233
|
183 |
@app.route("/ozoneloss")
|
peter@1
|
184 |
def task():
|
rb@233
|
185 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
|
rb@165
|
186 |
content = get_content(filename)
|
j@247
|
187 |
return render_template("/ozoneloss.html", act="ozoneloss", content=content)
|
j@247
|
188 |
|
j@249
|
189 |
@app.route("/ozoneloss/clams")
|
j@247
|
190 |
def task1():
|
j@249
|
191 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
|
j@247
|
192 |
content = get_content(filename)
|
j@249
|
193 |
return render_template("/ozoneloss_clams.html", act="ozoneloss/clams", content=content)
|
j@249
|
194 |
|
j@249
|
195 |
@app.route("/ozoneloss/vpsc")
|
j@249
|
196 |
def task2():
|
j@249
|
197 |
filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
|
j@249
|
198 |
content = get_content(filename)
|
j@249
|
199 |
return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc", content=content)
|
peter@1
|
200 |
|
rb@233
|
201 |
@app.route("/iek-7")
|
peter@1
|
202 |
def submission():
|
rb@233
|
203 |
filename = os.path.join("templates", get_locale(), "rst", "iek-7.rst")
|
rb@167
|
204 |
content = get_content(filename)
|
rb@170
|
205 |
return render_template("/content.html", act="submission", content=content)
|
peter@1
|
206 |
|
peter@1
|
207 |
|
rb@100
|
208 |
@app.route("/imprint")
|
peter@88
|
209 |
def imprint():
|
rb@163
|
210 |
filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
|
rb@163
|
211 |
content = get_content(filename)
|
rb@170
|
212 |
return render_template("/content.html", act="imprint", content=content)
|
peter@88
|
213 |
|
peter@109
|
214 |
|
peter@88
|
215 |
|
peter@1
|
216 |
@app.errorhandler(404)
|
peter@1
|
217 |
def page_not_found(e):
|
rb@213
|
218 |
msg = _(u"Url: %(url)s not found", url=request.url)
|
rb@157
|
219 |
info = _(u"This information is not available!")
|
rb@157
|
220 |
return render_template("404.html", msg=msg, info=info)
|
peter@1
|
221 |
|
peter@1
|
222 |
if __name__ == "__main__":
|
peter@1
|
223 |
app.run(host='localhost', port=5014, debug=True)
|