eskp.py
author Jens-Uwe Grooss <j.-u.grooss@fz-juelich.de>
Wed, 07 May 2014 17:01:53 +0200
changeset 249 3b60bc570d8a
parent 247 6a8a901ba550
child 250 a4adf5a448f3
permissions -rwxr-xr-x
Bilder erneuert, aufgeteilt in VOSC und O3/DO3 (ClaMS)
Seiten und Texte entsprechend angepasst
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
rb@241
    47
def get_ozone_dates():
j@249
    48
    menue = [('/ozoneloss/clams/2014', _(u'2014')),
j@249
    49
             ('/ozoneloss/clams/2013', _(u'2013')),
j@249
    50
             ('/ozoneloss/clams/2012', _(u'2012')),
j@249
    51
             ('/ozoneloss/clams/2011', _(u'2011')),
j@249
    52
             ('/ozoneloss/clams/2010', _(u'2010')),
j@249
    53
             ]
j@249
    54
    return menue
j@249
    55
j@249
    56
def get_vpsc_dates():
j@249
    57
    menue = [('/ozoneloss/vpsc/2014', _(u'2014')),
j@249
    58
             ('/ozoneloss/vpsc/2013', _(u'2013')),
j@249
    59
             ('/ozoneloss/vpsc/2012', _(u'2012')),
j@249
    60
             ('/ozoneloss/vpsc/2011', _(u'2011')),
j@249
    61
             ('/ozoneloss/vpsc/2010', _(u'2010')),
rb@241
    62
             ]
rb@241
    63
    return menue
rb@241
    64
rb@241
    65
app.jinja_env.globals.update(get_ozone_dates=get_ozone_dates)
j@249
    66
app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
peter@142
    67
peter@1
    68
@babel.localeselector
peter@1
    69
def get_locale():
peter@109
    70
    """ToDo: if translation is completed, switch to en """
rb@118
    71
    return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
peter@1
    72
rb@100
    73
peter@1
    74
@app.route("/")
rb@100
    75
@app.route("/index")
peter@1
    76
def index():
rb@213
    77
    return render_template("/index.html",
rb@233
    78
                           eskp_info=_(u'About ESKP'),
rb@233
    79
                           )
peter@1
    80
rb@241
    81
j@249
    82
@app.route('/ozoneloss/clams/2014')
rb@241
    83
def y2014():
j@249
    84
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
rb@241
    85
    content = get_content(filename)
j@249
    86
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2014", content=content, year=2014)
rb@241
    87
j@249
    88
@app.route('/ozoneloss/clams/2013')
rb@241
    89
def y2013():
j@249
    90
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
rb@241
    91
    content = get_content(filename)
j@249
    92
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2013", content=content, year=2013)
rb@241
    93
j@249
    94
@app.route('/ozoneloss/clams/2012')
rb@241
    95
def y2012():
j@249
    96
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
rb@241
    97
    content = get_content(filename)
j@249
    98
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2012", content=content, year=2012)
rb@241
    99
j@249
   100
@app.route('/ozoneloss/clams/2011')
rb@241
   101
def y2011():
j@249
   102
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
rb@241
   103
    content = get_content(filename)
j@249
   104
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2011", content=content, year=2011)
rb@241
   105
j@249
   106
@app.route('/ozoneloss/clams/2010')
rb@241
   107
def y2010():
j@249
   108
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
rb@241
   109
    content = get_content(filename)
j@249
   110
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/2010", content=content, year=2010)
j@249
   111
j@249
   112
@app.route('/ozoneloss/vpsc/2014')
j@249
   113
def y2014a():
j@249
   114
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
j@249
   115
    content = get_content(filename)
j@249
   116
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, year=2014)
j@249
   117
j@249
   118
@app.route('/ozoneloss/vpsc/2013')
j@249
   119
def y2013a():
j@249
   120
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
j@249
   121
    content = get_content(filename)
j@249
   122
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2013", content=content, year=2013)
j@249
   123
j@249
   124
@app.route('/ozoneloss/vpsc/2012')
j@249
   125
def y2012a():
j@249
   126
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
j@249
   127
    content = get_content(filename)
j@249
   128
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2012", content=content, year=2012)
j@249
   129
j@249
   130
@app.route('/ozoneloss/vpsc/2011')
j@249
   131
def y2011a():
j@249
   132
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
j@249
   133
    content = get_content(filename)
j@249
   134
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2011", content=content, year=2011)
j@249
   135
j@249
   136
@app.route('/ozoneloss/vpsc/2010')
j@249
   137
def y2010a():
j@249
   138
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
j@249
   139
    content = get_content(filename)
j@249
   140
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2010", content=content, year=2010)
rb@241
   141
rb@118
   142
@app.route('/de')
rb@118
   143
def de():
rb@118
   144
    global LANGUAGE_SELECTED
rb@118
   145
    LANGUAGE_SELECTED = "de"
peter@146
   146
    saying, author = get_saying()
peter@160
   147
    return render_template("/index.html",
rb@186
   148
                           saying=saying,
rb@186
   149
                           author=author,
rb@233
   150
                           eskp_info=_(u'About ESKP'),
rb@233
   151
                           )
rb@118
   152
rb@118
   153
@app.route('/en')
rb@118
   154
def en():
peter@146
   155
    saying, author = get_saying()
rb@118
   156
    global LANGUAGE_SELECTED
rb@118
   157
    LANGUAGE_SELECTED = "en"
peter@160
   158
    return render_template("/index.html",
rb@186
   159
                           saying=saying,
rb@186
   160
                           author=author,
rb@233
   161
                           eskp_info=_(u'About ESKP'),
rb@233
   162
                           )
rb@118
   163
rb@233
   164
@app.route("/eskp")
rb@233
   165
def eskp():
rb@233
   166
    filename = os.path.join("templates", get_locale(), "rst", "eskp.rst")
rb@162
   167
    content = get_content(filename)
rb@233
   168
    return render_template("/content.html", act="eskp", content=content)
peter@1
   169
rb@233
   170
@app.route("/ozoneloss")
peter@1
   171
def task():
rb@233
   172
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
rb@165
   173
    content = get_content(filename)
j@247
   174
    return render_template("/ozoneloss.html", act="ozoneloss", content=content)
j@247
   175
j@249
   176
@app.route("/ozoneloss/clams")
j@247
   177
def task1():
j@249
   178
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
j@247
   179
    content = get_content(filename)
j@249
   180
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams", content=content)
j@249
   181
j@249
   182
@app.route("/ozoneloss/vpsc")
j@249
   183
def task2():
j@249
   184
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
j@249
   185
    content = get_content(filename)
j@249
   186
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc", content=content)
peter@1
   187
rb@233
   188
@app.route("/iek-7")
peter@1
   189
def submission():
rb@233
   190
    filename = os.path.join("templates", get_locale(), "rst", "iek-7.rst")
rb@167
   191
    content = get_content(filename)
rb@170
   192
    return render_template("/content.html", act="submission", content=content)
peter@1
   193
peter@1
   194
rb@100
   195
@app.route("/imprint")
peter@88
   196
def imprint():
rb@163
   197
    filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
rb@163
   198
    content = get_content(filename)
rb@170
   199
    return render_template("/content.html", act="imprint", content=content)
peter@88
   200
peter@109
   201
peter@88
   202
peter@1
   203
@app.errorhandler(404)
peter@1
   204
def page_not_found(e):
rb@213
   205
    msg = _(u"Url: %(url)s not found", url=request.url)
rb@157
   206
    info = _(u"This information is not available!")
rb@157
   207
    return render_template("404.html", msg=msg, info=info)
peter@1
   208
peter@1
   209
if __name__ == "__main__":
peter@1
   210
    app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung