eskp.py
author Jens-Uwe Grooss <j.-u.grooss@fz-juelich.de>
Thu, 08 May 2014 13:38:54 +0200
changeset 252 1de16074dd73
parent 250 a4adf5a448f3
child 256 c9d4aa9ec58f
permissions -rwxr-xr-x
B?rbels ?nderungen
ozoneloss-Bild zentriert
interne Links hinzugef?gt
     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_o3lossclams_dates():
    48     menue = [('/ozoneloss/clams/2012', _(u'2012')),
    49              ('/ozoneloss/clams/2011', _(u'2011')),
    50              ('/ozoneloss/clams/2010', _(u'2010')),
    51              ]
    52     return menue
    53 
    54 def get_vpsc_dates():
    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')),
    60              ]
    61     return menue
    62 
    63 app.jinja_env.globals.update(get_o3lossclams_dates=get_o3lossclams_dates)
    64 app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
    65 
    66 @babel.localeselector
    67 def get_locale():
    68     """ToDo: if translation is completed, switch to en """
    69     return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
    70 
    71 
    72 @app.route("/")
    73 @app.route("/index")
    74 def index():
    75     return render_template("/index.html",
    76                            eskp_info=_(u'About ESKP'),
    77                            )
    78 
    79 
    80 @app.route('/ozoneloss/clams/2014')
    81 def y2014():
    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)
    85 
    86 @app.route('/ozoneloss/clams/2013')
    87 def y2013():
    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)
    91 
    92 @app.route('/ozoneloss/clams/2012')
    93 def y2012():
    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)
    97 
    98 @app.route('/ozoneloss/clams/2011')
    99 def y2011():
   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)
   103 
   104 @app.route('/ozoneloss/clams/2010')
   105 def y2010():
   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)
   109 
   110 @app.route('/ozoneloss/vpsc/2014')
   111 def y2014a():
   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)
   116 
   117     return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2014)
   118 
   119 @app.route('/ozoneloss/vpsc/2013')
   120 def y2013a():
   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)
   125 
   126     return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2013)
   127 
   128 @app.route('/ozoneloss/vpsc/2012')
   129 def y2012a():
   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)
   134 
   135     return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2012)
   136 
   137 @app.route('/ozoneloss/vpsc/2011')
   138 def y2011a():
   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)
   143 
   144     return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2011)
   145 
   146 @app.route('/ozoneloss/vpsc/2010')
   147 def y2010a():
   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)
   152 
   153     return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/2014", content=content, content_explanation=explanation, year=2011)
   154 
   155 @app.route('/de')
   156 def de():
   157     global LANGUAGE_SELECTED
   158     LANGUAGE_SELECTED = "de"
   159     saying, author = get_saying()
   160     return render_template("/index.html",
   161                            saying=saying,
   162                            author=author,
   163                            eskp_info=_(u'About ESKP'),
   164                            )
   165 
   166 @app.route('/en')
   167 def en():
   168     saying, author = get_saying()
   169     global LANGUAGE_SELECTED
   170     LANGUAGE_SELECTED = "en"
   171     return render_template("/index.html",
   172                            saying=saying,
   173                            author=author,
   174                            eskp_info=_(u'About ESKP'),
   175                            )
   176 
   177 @app.route("/eskp")
   178 def 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)
   182 
   183 
   184 @app.route("/ozoneloss")
   185 def task():
   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)
   189 
   190 @app.route("/ozoneloss/clams")
   191 def task1():
   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)
   195 
   196 @app.route("/ozoneloss/vpsc")
   197 def task2():
   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)
   201 
   202 @app.route("/iek-7")
   203 def submission():
   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)
   207 
   208 
   209 @app.route("/imprint")
   210 def 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)
   214 
   215 
   216 
   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)
   222 
   223 if __name__ == "__main__":
   224     app.run(host='localhost', port=5014, debug=True)
Impressum Datenschutzerklärung