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
     1 # -*- coding: utf-8 -*-
     2 
     3 import os
     4 import codecs
     5 
     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
    13 
    14 LANGUAGE_SELECTED = "de"
    15 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
    16 
    17 # We need the path of this file to find templates to translate
    18 ESKP_PATH = os.path.dirname(os.path.abspath(__file__))
    19 
    20 app = Flask(__name__)
    21 babel = Babel(app)
    22 
    23 app.config['BABEL_DEFAULT_LOCALE'] = 'de'
    24 
    25 
    26 def get_content(filename, overrides=None):
    27     content = u""
    28     filename = os.path.join(ESKP_PATH, filename)
    29     if os.path.isfile(filename):
    30         with codecs.open(filename, 'r', 'utf-8') as f:
    31             rst_data = f.read()
    32         f.close()
    33         content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
    34     return content
    35 
    36 def get_topmenue():
    37     menue = [
    38              ('/', _(u'Home')),
    39              ('/ozoneloss', _(u'Ozoneloss')),
    40              ('/eskp', _(u'ESKP')),
    41              ('/iek-7', _(u'IEK-7')),
    42             ]
    43     return menue
    44 
    45 app.jinja_env.globals.update(get_topmenue=get_topmenue)
    46 
    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')),
    53              ]
    54     return menue
    55 
    56 def get_vpsc_dates():
    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')),
    62              ]
    63     return menue
    64 
    65 app.jinja_env.globals.update(get_ozone_dates=get_ozone_dates)
    66 app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
    67 
    68 @babel.localeselector
    69 def get_locale():
    70     """ToDo: if translation is completed, switch to en """
    71     return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
    72 
    73 
    74 @app.route("/")
    75 @app.route("/index")
    76 def index():
    77     return render_template("/index.html",
    78                            eskp_info=_(u'About ESKP'),
    79                            )
    80 
    81 
    82 @app.route('/ozoneloss/clams/2014')
    83 def y2014():
    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)
    87 
    88 @app.route('/ozoneloss/clams/2013')
    89 def y2013():
    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)
    93 
    94 @app.route('/ozoneloss/clams/2012')
    95 def y2012():
    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)
    99 
   100 @app.route('/ozoneloss/clams/2011')
   101 def y2011():
   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)
   105 
   106 @app.route('/ozoneloss/clams/2010')
   107 def y2010():
   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)
   111 
   112 @app.route('/ozoneloss/vpsc/2014')
   113 def y2014a():
   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)
   117 
   118 @app.route('/ozoneloss/vpsc/2013')
   119 def y2013a():
   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)
   123 
   124 @app.route('/ozoneloss/vpsc/2012')
   125 def y2012a():
   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)
   129 
   130 @app.route('/ozoneloss/vpsc/2011')
   131 def y2011a():
   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)
   135 
   136 @app.route('/ozoneloss/vpsc/2010')
   137 def y2010a():
   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)
   141 
   142 @app.route('/de')
   143 def de():
   144     global LANGUAGE_SELECTED
   145     LANGUAGE_SELECTED = "de"
   146     saying, author = get_saying()
   147     return render_template("/index.html",
   148                            saying=saying,
   149                            author=author,
   150                            eskp_info=_(u'About ESKP'),
   151                            )
   152 
   153 @app.route('/en')
   154 def en():
   155     saying, author = get_saying()
   156     global LANGUAGE_SELECTED
   157     LANGUAGE_SELECTED = "en"
   158     return render_template("/index.html",
   159                            saying=saying,
   160                            author=author,
   161                            eskp_info=_(u'About ESKP'),
   162                            )
   163 
   164 @app.route("/eskp")
   165 def 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)
   169 
   170 @app.route("/ozoneloss")
   171 def task():
   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)
   175 
   176 @app.route("/ozoneloss/clams")
   177 def task1():
   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)
   181 
   182 @app.route("/ozoneloss/vpsc")
   183 def task2():
   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)
   187 
   188 @app.route("/iek-7")
   189 def submission():
   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)
   193 
   194 
   195 @app.route("/imprint")
   196 def 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)
   200 
   201 
   202 
   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)
   208 
   209 if __name__ == "__main__":
   210     app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung