| 
rb@217
 | 
     1  | 
# -*- coding: utf-8 -*-
  | 
| 
rb@280
 | 
     2  | 
import logging
  | 
| 
rb@217
 | 
     3  | 
  | 
| 
rb@186
 | 
     4  | 
import os
  | 
| 
rb@186
 | 
     5  | 
import codecs
  | 
| 
rb@275
 | 
     6  | 
import vobject
  | 
| 
rb@275
 | 
     7  | 
import StringIO
  | 
| 
rb@275
 | 
     8  | 
  | 
| 
rb@275
 | 
     9  | 
import qrcode
  | 
| 
rb@186
 | 
    10  | 
  | 
| 
rb@186
 | 
    11  | 
from docutils.core import publish_parts
  | 
| 
rb@275
 | 
    12  | 
from flask import Flask
  | 
| 
peter@1
 | 
    13  | 
from flask import render_template
  | 
| 
peter@1
 | 
    14  | 
from flask import request
  | 
| 
rb@95
 | 
    15  | 
from flask.ext.babel import gettext as _
  | 
| 
peter@1
 | 
    16  | 
from flask.ext.babel import Babel
  | 
| 
rb@95
 | 
    17  | 
from config import LANGUAGES
  | 
| 
rb@161
 | 
    18  | 
  | 
| 
rb@275
 | 
    19  | 
import base64
  | 
| 
rb@275
 | 
    20  | 
  | 
| 
rb@122
 | 
    21  | 
LANGUAGE_SELECTED = "de"
  | 
| 
icg179@496
 | 
    22  | 
# ToDo after engelish is implemented set LANGUAGE_SELECTED = None
  | 
| 
rb@95
 | 
    23  | 
  | 
| 
rb@246
 | 
    24  | 
# We need the path of this file to find templates to translate
  | 
| 
rb@246
 | 
    25  | 
ESKP_PATH = os.path.dirname(os.path.abspath(__file__))
  | 
| 
icg179@496
 | 
    26  | 
logging.basicConfig(filename=os.path.join(ESKP_PATH, 'eskp-app.log'), level=logging.DEBUG)
  | 
| 
rb@246
 | 
    27  | 
  | 
| 
peter@1
 | 
    28  | 
app = Flask(__name__)
  | 
| 
peter@1
 | 
    29  | 
babel = Babel(app)
  | 
| 
peter@1
 | 
    30  | 
  | 
| 
peter@145
 | 
    31  | 
app.config['BABEL_DEFAULT_LOCALE'] = 'de'
  | 
| 
peter@145
 | 
    32  | 
  | 
| 
rb@275
 | 
    33  | 
  | 
| 
rb@275
 | 
    34  | 
def get_vcard(filename):
  | 
| 
rb@281
 | 
    35  | 
    filename = os.path.join(ESKP_PATH, filename)
  | 
| 
rb@275
 | 
    36  | 
    with codecs.open(filename, 'r', 'utf-8') as f:
  | 
| 
icg179@496
 | 
    37  | 
        vcard = f.read()
  | 
| 
rb@275
 | 
    38  | 
    return vobject.readOne(vcard)
  | 
| 
rb@275
 | 
    39  | 
  | 
| 
rb@275
 | 
    40  | 
  | 
| 
rb@214
 | 
    41  | 
def get_content(filename, overrides=None):
  | 
| 
rb@162
 | 
    42  | 
    content = u""
  | 
| 
rb@246
 | 
    43  | 
    filename = os.path.join(ESKP_PATH, filename)
  | 
| 
rb@162
 | 
    44  | 
    if os.path.isfile(filename):
  | 
| 
rb@162
 | 
    45  | 
        with codecs.open(filename, 'r', 'utf-8') as f:
  | 
| 
rb@162
 | 
    46  | 
            rst_data = f.read()
  | 
| 
rb@214
 | 
    47  | 
        content = publish_parts(rst_data, writer_name='html', settings_overrides=overrides)['html_body']
  | 
| 
rb@162
 | 
    48  | 
    return content
  | 
| 
rb@162
 | 
    49  | 
  | 
| 
icg179@496
 | 
    50  | 
  | 
| 
icg179@496
 | 
    51  | 
def get_newest_date():
  | 
| 
icg179@496
 | 
    52  | 
    files = os.listdir(os.path.join(ESKP_PATH, 'static/images/uvmap'))
  | 
| 
icg179@496
 | 
    53  | 
    getdates = get_valid_dates(files)
  | 
| 
icg179@496
 | 
    54  | 
    newest_date = getdates[-1]
  | 
| 
icg179@496
 | 
    55  | 
  | 
| 
icg179@496
 | 
    56  | 
    return newest_date
  | 
| 
icg179@496
 | 
    57  | 
  | 
| 
icg179@496
 | 
    58  | 
  | 
| 
peter@142
 | 
    59  | 
def get_topmenue():
  | 
| 
icg179@496
 | 
    60  | 
    newest_date = get_newest_date()
  | 
| 
rb@238
 | 
    61  | 
    menue = [
  | 
| 
icg179@496
 | 
    62  | 
        ('/ozoneloss', _(u'Ozoneloss'),
 | 
| 
icg179@496
 | 
    63  | 
         (('/ozoneloss', _(u'overview')),
 | 
| 
icg179@496
 | 
    64  | 
          ('/ozoneloss/clams/2016', _(u'calculations')),
 | 
| 
icg179@496
 | 
    65  | 
          ('/ozoneloss/vpsc/2016', _(u'estimations')),
 | 
| 
icg179@496
 | 
    66  | 
          ('/ozoneloss/uvi', _(u'uv increase')),
 | 
| 
icg179@496
 | 
    67  | 
          ('/ozoneloss/uvmap/' + newest_date, _(u'uv index map')))),
 | 
| 
icg179@496
 | 
    68  | 
        ('/eskp', _(u'ESKP'), (None, None)),
 | 
| 
icg179@496
 | 
    69  | 
        ('/iek-7', _(u'IEK-7'), (None, None))
 | 
| 
icg179@496
 | 
    70  | 
    ]
  | 
| 
peter@145
 | 
    71  | 
    return menue
  | 
| 
peter@142
 | 
    72  | 
  | 
| 
icg179@496
 | 
    73  | 
  | 
| 
peter@142
 | 
    74  | 
app.jinja_env.globals.update(get_topmenue=get_topmenue)
  | 
| 
peter@142
 | 
    75  | 
  | 
| 
icg179@496
 | 
    76  | 
  | 
| 
j@250
 | 
    77  | 
def get_o3lossclams_dates():
  | 
| 
rb@302
 | 
    78  | 
    menue = [
  | 
| 
j@441
 | 
    79  | 
        ('/ozoneloss/clams/2016', _(u'2016')),
 | 
| 
j@380
 | 
    80  | 
        ('/ozoneloss/clams/2015', _(u'2015')),
 | 
| 
j@380
 | 
    81  | 
        ('/ozoneloss/clams/2012', _(u'2012')),
 | 
| 
j@380
 | 
    82  | 
        ('/ozoneloss/clams/2011', _(u'2011')),
 | 
| 
j@380
 | 
    83  | 
        ('/ozoneloss/clams/2010', _(u'2010')),
 | 
| 
icg179@496
 | 
    84  | 
    ]
  | 
| 
j@249
 | 
    85  | 
    return menue
  | 
| 
j@249
 | 
    86  | 
  | 
| 
icg179@496
 | 
    87  | 
  | 
| 
icg179@496
 | 
    88  | 
def get_valid_dates(files):
  | 
| 
icg179@496
 | 
    89  | 
    dates = []
  | 
| 
icg179@496
 | 
    90  | 
  | 
| 
icg179@496
 | 
    91  | 
    for file in files:
  | 
| 
icg179@496
 | 
    92  | 
        if file.endswith('.png') and file.find('uvi') >= 0:
 | 
| 
icg179@496
 | 
    93  | 
            date = file[-12:-6]
  | 
| 
icg179@496
 | 
    94  | 
            dates.append(date)
  | 
| 
icg179@496
 | 
    95  | 
    dates.sort()
  | 
| 
icg179@496
 | 
    96  | 
    for date in dates:
  | 
| 
icg179@496
 | 
    97  | 
        i = 0
  | 
| 
icg179@496
 | 
    98  | 
        for param in ['uvi', 'o3col', 'do3col']:
  | 
| 
icg179@496
 | 
    99  | 
            testfile = 'clams_' + param + '_' + date + '12.png'
  | 
| 
icg179@496
 | 
   100  | 
            if files.count(testfile) > 0:
  | 
| 
icg179@496
 | 
   101  | 
                i = i + 1
  | 
| 
icg179@496
 | 
   102  | 
        if i <> 3:
  | 
| 
icg179@496
 | 
   103  | 
            dates.remove(date)
  | 
| 
icg179@496
 | 
   104  | 
    return dates
  | 
| 
icg179@496
 | 
   105  | 
  | 
| 
icg179@496
 | 
   106  | 
  | 
| 
icg179@496
 | 
   107  | 
def get_o3lossuvmap_dates(date_show):
  | 
| 
icg179@496
 | 
   108  | 
  | 
| 
icg179@496
 | 
   109  | 
    files = os.listdir(os.path.join(ESKP_PATH,'static/images/uvmap'))
  | 
| 
icg179@496
 | 
   110  | 
    dates = get_valid_dates(files)
  | 
| 
icg179@496
 | 
   111  | 
    ndates = len(dates)
  | 
| 
icg179@496
 | 
   112  | 
    ind = dates.index(date_show)
  | 
| 
icg179@496
 | 
   113  | 
    if ind ==0 :
  | 
| 
icg179@496
 | 
   114  | 
        chosendates = [dates[ind+1]]
  | 
| 
icg179@496
 | 
   115  | 
    elif ind >= ndates - 1:
  | 
| 
icg179@496
 | 
   116  | 
        chosendates= [dates[ind-1]]
  | 
| 
icg179@496
 | 
   117  | 
    else:
  | 
| 
icg179@496
 | 
   118  | 
        chosendates = [dates[ind-1], dates[ind+1]]
  | 
| 
icg179@496
 | 
   119  | 
    menue = []
  | 
| 
icg179@496
 | 
   120  | 
    for date in chosendates:
  | 
| 
icg179@496
 | 
   121  | 
        text_date = date[-2:] + '.' + date[-4:-2] + '.'
  | 
| 
icg179@496
 | 
   122  | 
        menue.append(('/ozoneloss/uvmap/' + date, _(text_date)))
 | 
| 
icg179@496
 | 
   123  | 
    return menue
  | 
| 
icg179@496
 | 
   124  | 
  | 
| 
icg179@496
 | 
   125  | 
  | 
| 
j@249
 | 
   126  | 
def get_vpsc_dates():
  | 
| 
rb@302
 | 
   127  | 
    menue = [
  | 
| 
j@441
 | 
   128  | 
        ('/ozoneloss/vpsc/2016', _(u'2016')),
 | 
| 
j@380
 | 
   129  | 
        ('/ozoneloss/vpsc/2015', _(u'2015')),
 | 
| 
j@380
 | 
   130  | 
        ('/ozoneloss/vpsc/2014', _(u'2014')),
 | 
| 
j@380
 | 
   131  | 
        ('/ozoneloss/vpsc/2013', _(u'2013')),
 | 
| 
j@380
 | 
   132  | 
        ('/ozoneloss/vpsc/2012', _(u'2012')),
 | 
| 
j@380
 | 
   133  | 
        ('/ozoneloss/vpsc/2011', _(u'2011')),
 | 
| 
j@380
 | 
   134  | 
        ('/ozoneloss/vpsc/2010', _(u'2010')),
 | 
| 
icg179@496
 | 
   135  | 
    ]
  | 
| 
rb@241
 | 
   136  | 
    return menue
  | 
| 
rb@241
 | 
   137  | 
  | 
| 
icg179@496
 | 
   138  | 
  | 
| 
j@250
 | 
   139  | 
app.jinja_env.globals.update(get_o3lossclams_dates=get_o3lossclams_dates)
  | 
| 
j@249
 | 
   140  | 
app.jinja_env.globals.update(get_vpsc_dates=get_vpsc_dates)
  | 
| 
icg179@496
 | 
   141  | 
app.jinja_env.globals.update(get_o3lossuvmap_dates=get_o3lossuvmap_dates)
  | 
| 
peter@142
 | 
   142  | 
  | 
| 
rb@267
 | 
   143  | 
  | 
| 
rb@267
 | 
   144  | 
def modal_info(template, act, title, filename):
  | 
| 
rb@264
 | 
   145  | 
    content = get_content(filename)
  | 
| 
rb@267
 | 
   146  | 
    html = render_template(template, act=act, title=title, content=content, exit=_(u"Close"))
  | 
| 
rb@264
 | 
   147  | 
    return html
  | 
| 
rb@264
 | 
   148  | 
  | 
| 
rb@264
 | 
   149  | 
  | 
| 
peter@1
 | 
   150  | 
@babel.localeselector
  | 
| 
peter@1
 | 
   151  | 
def get_locale():
  | 
| 
peter@109
 | 
   152  | 
    """ToDo: if translation is completed, switch to en """
  | 
| 
rb@118
 | 
   153  | 
    return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
  | 
| 
peter@1
 | 
   154  | 
  | 
| 
rb@100
 | 
   155  | 
  | 
| 
peter@1
 | 
   156  | 
@app.route("/")
 | 
| 
rb@100
 | 
   157  | 
@app.route("/index")
 | 
| 
peter@1
 | 
   158  | 
def index():
  | 
| 
rb@213
 | 
   159  | 
    return render_template("/index.html",
 | 
| 
rb@233
 | 
   160  | 
                           eskp_info=_(u'About ESKP'),
  | 
| 
rb@233
 | 
   161  | 
                           )
  | 
| 
peter@1
 | 
   162  | 
  | 
| 
rb@241
 | 
   163  | 
  | 
| 
rb@257
 | 
   164  | 
@app.route('/ozoneloss/clams/<year>')
 | 
| 
rb@257
 | 
   165  | 
def ozoneloss_clams_year(year):
  | 
| 
j@249
 | 
   166  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
 | 
| 
rb@241
 | 
   167  | 
    content = get_content(filename)
  | 
| 
rb@257
 | 
   168  | 
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams/%s" % year, content=content, year=year)
 | 
| 
rb@241
 | 
   169  | 
  | 
| 
rb@241
 | 
   170  | 
  | 
| 
icg179@496
 | 
   171  | 
@app.route('/ozoneloss/uvmap/<date>')
 | 
| 
icg179@496
 | 
   172  | 
def ozoneloss_uvmap_date(date):
  | 
| 
icg179@496
 | 
   173  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_uvmap.rst")
 | 
| 
icg179@496
 | 
   174  | 
    content = get_content(filename)
  | 
| 
icg179@496
 | 
   175  | 
    return render_template("/ozoneloss_uvmap.html", act="ozoneloss/uvmap/%s" % date, content=content, date=date)
 | 
| 
icg179@496
 | 
   176  | 
  | 
| 
icg179@496
 | 
   177  | 
  | 
| 
rb@257
 | 
   178  | 
@app.route('/ozoneloss/vpsc/<year>')
 | 
| 
rb@257
 | 
   179  | 
def ozoneloss_vspc_year(year):
  | 
| 
j@249
 | 
   180  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
 | 
| 
j@249
 | 
   181  | 
    content = get_content(filename)
  | 
| 
j@250
 | 
   182  | 
    filename = os.path.join("templates", get_locale(), "rst", "explanation_vpsc.rst")
 | 
| 
j@250
 | 
   183  | 
    explanation = get_content(filename)
  | 
| 
j@250
 | 
   184  | 
  | 
| 
rb@257
 | 
   185  | 
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc/%s" % year, content=content,
 | 
| 
rb@257
 | 
   186  | 
                           content_explanation=explanation, year=year)
  | 
| 
rb@241
 | 
   187  | 
  | 
| 
j@317
 | 
   188  | 
  | 
| 
rb@118
 | 
   189  | 
@app.route('/de')
 | 
| 
rb@118
 | 
   190  | 
def de():
  | 
| 
rb@118
 | 
   191  | 
    global LANGUAGE_SELECTED
  | 
| 
rb@118
 | 
   192  | 
    LANGUAGE_SELECTED = "de"
  | 
| 
peter@160
 | 
   193  | 
    return render_template("/index.html",
 | 
| 
rb@233
 | 
   194  | 
                           eskp_info=_(u'About ESKP'),
  | 
| 
rb@233
 | 
   195  | 
                           )
  | 
| 
rb@118
 | 
   196  | 
  | 
| 
icg179@496
 | 
   197  | 
  | 
| 
rb@118
 | 
   198  | 
@app.route('/en')
 | 
| 
rb@118
 | 
   199  | 
def en():
  | 
| 
rb@118
 | 
   200  | 
    global LANGUAGE_SELECTED
  | 
| 
rb@118
 | 
   201  | 
    LANGUAGE_SELECTED = "en"
  | 
| 
peter@160
 | 
   202  | 
    return render_template("/index.html",
 | 
| 
rb@233
 | 
   203  | 
                           eskp_info=_(u'About ESKP'),
  | 
| 
rb@233
 | 
   204  | 
                           )
  | 
| 
rb@118
 | 
   205  | 
  | 
| 
icg179@496
 | 
   206  | 
  | 
| 
rb@233
 | 
   207  | 
@app.route("/eskp")
 | 
| 
rb@233
 | 
   208  | 
def eskp():
  | 
| 
rb@233
 | 
   209  | 
    filename = os.path.join("templates", get_locale(), "rst", "eskp.rst")
 | 
| 
rb@162
 | 
   210  | 
    content = get_content(filename)
  | 
| 
j@272
 | 
   211  | 
    filename = os.path.join("templates", get_locale(), "rst", "eskp_title.rst")
 | 
| 
j@272
 | 
   212  | 
    headline = get_content(filename)
  | 
| 
j@272
 | 
   213  | 
    return render_template("/eskp.html", act="eskp", content=content, headline=headline)
 | 
| 
j@252
 | 
   214  | 
  | 
| 
peter@1
 | 
   215  | 
  | 
| 
rb@275
 | 
   216  | 
def qr_image_data(card):
  | 
| 
icg179@496
 | 
   217  | 
    buf = StringIO.StringIO()
  | 
| 
rb@275
 | 
   218  | 
    qr = qrcode.QRCode(
  | 
| 
rb@275
 | 
   219  | 
        version=1,
  | 
| 
rb@275
 | 
   220  | 
        error_correction=qrcode.constants.ERROR_CORRECT_L,
  | 
| 
rb@275
 | 
   221  | 
        box_size=2,
  | 
| 
rb@275
 | 
   222  | 
        border=2,
  | 
| 
icg179@496
 | 
   223  | 
    )
  | 
| 
rb@275
 | 
   224  | 
    qr.add_data(card.serialize())
  | 
| 
rb@275
 | 
   225  | 
    qr.make(fit=True)
  | 
| 
rb@275
 | 
   226  | 
    img = qr.make_image()
  | 
| 
rb@275
 | 
   227  | 
    img.save(buf)
  | 
| 
rb@275
 | 
   228  | 
    image = buf.getvalue()
  | 
| 
rb@275
 | 
   229  | 
    return base64.b64encode(image)
  | 
| 
rb@275
 | 
   230  | 
  | 
| 
rb@275
 | 
   231  | 
  | 
| 
rb@233
 | 
   232  | 
@app.route("/ozoneloss")
 | 
| 
rb@257
 | 
   233  | 
def ozoneloss():
  | 
| 
rb@233
 | 
   234  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
 | 
| 
rb@165
 | 
   235  | 
    content = get_content(filename)
  | 
| 
rb@275
 | 
   236  | 
  | 
| 
rb@275
 | 
   237  | 
    vcard_file = os.path.join("vcards", "jug.vcf")
 | 
| 
rb@275
 | 
   238  | 
    author = u""
  | 
| 
icg179@496
 | 
   239  | 
  | 
| 
rb@275
 | 
   240  | 
    try:
  | 
| 
rb@275
 | 
   241  | 
        card = get_vcard(vcard_file)
  | 
| 
rb@275
 | 
   242  | 
    except IOError:
  | 
| 
rb@275
 | 
   243  | 
        card = None
  | 
| 
rb@275
 | 
   244  | 
    if card is not None:
  | 
| 
rb@275
 | 
   245  | 
        qr_image = qr_image_data(card)
  | 
| 
rb@275
 | 
   246  | 
        author = render_template("/author_info.html", act="author", title=_(u"Ozoneloss"),
 | 
| 
icg179@496
 | 
   247  | 
                                 card=card, image=qr_image, contact=_(u"Contact"), exit=_(u"Close"))
  | 
| 
rb@275
 | 
   248  | 
  | 
| 
rb@267
 | 
   249  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_publications.rst")
 | 
| 
rb@267
 | 
   250  | 
    publications = modal_info("/publications_info.html", "publications", _(u"Ozoneloss"), filename)
 | 
| 
rb@264
 | 
   251  | 
    return render_template("/ozoneloss.html", act="ozoneloss", content=content,
 | 
| 
icg179@496
 | 
   252  | 
                           author=author, card=card, publications=publications)
  | 
| 
icg179@496
 | 
   253  | 
  | 
| 
j@247
 | 
   254  | 
  | 
| 
j@249
 | 
   255  | 
@app.route("/ozoneloss/clams")
 | 
| 
rb@257
 | 
   256  | 
def ozoneloss_clams():
  | 
| 
j@249
 | 
   257  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_clams.rst")
 | 
| 
j@247
 | 
   258  | 
    content = get_content(filename)
  | 
| 
j@249
 | 
   259  | 
    return render_template("/ozoneloss_clams.html", act="ozoneloss/clams", content=content)
 | 
| 
j@249
 | 
   260  | 
  | 
| 
icg179@496
 | 
   261  | 
  | 
| 
icg179@496
 | 
   262  | 
@app.route("/ozoneloss/uvmap")
 | 
| 
icg179@496
 | 
   263  | 
def ozoneloss_uvmap():
  | 
| 
icg179@496
 | 
   264  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_uvmap.rst")
 | 
| 
icg179@496
 | 
   265  | 
    content = get_content(filename)
  | 
| 
icg179@496
 | 
   266  | 
    return render_template("/ozoneloss_uvmap.html", act="ozoneloss/uvmap", content=content)
 | 
| 
icg179@496
 | 
   267  | 
  | 
| 
icg179@496
 | 
   268  | 
  | 
| 
j@249
 | 
   269  | 
@app.route("/ozoneloss/vpsc")
 | 
| 
rb@257
 | 
   270  | 
def ozoneloss_vspc():
  | 
| 
j@249
 | 
   271  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_vpsc.rst")
 | 
| 
j@249
 | 
   272  | 
    content = get_content(filename)
  | 
| 
j@249
 | 
   273  | 
    return render_template("/ozoneloss_vpsc.html", act="ozoneloss/vpsc", content=content)
 | 
| 
peter@1
 | 
   274  | 
  | 
| 
j@380
 | 
   275  | 
  | 
| 
j@380
 | 
   276  | 
@app.route("/ozoneloss/uvi", methods=['GET'])
 | 
| 
j@317
 | 
   277  | 
def ozoneloss_uvi():
  | 
| 
j@380
 | 
   278  | 
    # XXX check 'POST' does not work
  | 
| 
j@317
 | 
   279  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_uvi.rst")
 | 
| 
j@317
 | 
   280  | 
    content = get_content(filename)
  | 
| 
j@380
 | 
   281  | 
  | 
| 
j@380
 | 
   282  | 
    lat = 50.
  | 
| 
j@380
 | 
   283  | 
    o3offset = 50.
  | 
| 
j@380
 | 
   284  | 
    figname = "uvincr_lat%0.3i_do3%0.3i.svg" % (lat, o3offset)
  | 
| 
j@380
 | 
   285  | 
  | 
| 
j@380
 | 
   286  | 
    return render_template('ozoneloss_uvi.html', act="ozoneloss/uvi", content=content, figname=figname,
 | 
| 
j@380
 | 
   287  | 
                           alt=_(u"UV increase at {{lat}} degrees N for {{o3offset}} DU ozone depletion"))
 | 
| 
j@380
 | 
   288  | 
  | 
| 
icg179@496
 | 
   289  | 
  | 
| 
j@380
 | 
   290  | 
@app.route("/ozoneloss/uvi_graph", methods=['POST'])
 | 
| 
j@380
 | 
   291  | 
def ozoneloss_uvi_graph():
  | 
| 
j@380
 | 
   292  | 
    filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_uvi.rst")
 | 
| 
j@380
 | 
   293  | 
    content = get_content(filename)
  | 
| 
j@380
 | 
   294  | 
  | 
| 
j@380
 | 
   295  | 
    latstr = request.form['Gradzahl']
  | 
| 
j@380
 | 
   296  | 
    o3offsetstr = request.form['Dobson-Unit']
  | 
| 
j@380
 | 
   297  | 
  | 
| 
j@380
 | 
   298  | 
    latstr2 = latstr.replace(u'\xb0', '')
  | 
| 
j@380
 | 
   299  | 
  | 
| 
j@380
 | 
   300  | 
    if latstr2.endswith(u'N'):
  | 
| 
j@380
 | 
   301  | 
        latstr2 = latstr2.replace(u'N', '')
  | 
| 
j@380
 | 
   302  | 
        lat = float(latstr2)
  | 
| 
j@380
 | 
   303  | 
    if latstr2.endswith(u'S'):
  | 
| 
j@380
 | 
   304  | 
        latstr2 = latstr2.replace(u'S', '')
  | 
| 
j@380
 | 
   305  | 
        lat = -float(latstr2)
  | 
| 
j@380
 | 
   306  | 
  | 
| 
j@380
 | 
   307  | 
    figname = "uvincr_lat%0.3i_do3%0.3i.svg" % (lat, float(o3offsetstr))
  | 
| 
j@380
 | 
   308  | 
  | 
| 
j@380
 | 
   309  | 
    return render_template('graph.html', act="ozoneloss_uvi_graph", content=content, figname=figname,
 | 
| 
j@380
 | 
   310  | 
                           o3offsetstr=o3offsetstr, latstr=latstr)
  | 
| 
j@380
 | 
   311  | 
  | 
| 
j@380
 | 
   312  | 
  | 
| 
rb@233
 | 
   313  | 
@app.route("/iek-7")
 | 
| 
rb@257
 | 
   314  | 
def institute():
  | 
| 
rb@233
 | 
   315  | 
    filename = os.path.join("templates", get_locale(), "rst", "iek-7.rst")
 | 
| 
rb@167
 | 
   316  | 
    content = get_content(filename)
  | 
| 
rb@277
 | 
   317  | 
    vcard_file = os.path.join("vcards", "sas.vcf")
 | 
| 
rb@277
 | 
   318  | 
    author = u""
  | 
| 
rb@277
 | 
   319  | 
    try:
  | 
| 
rb@277
 | 
   320  | 
        card = get_vcard(vcard_file)
  | 
| 
rb@277
 | 
   321  | 
    except IOError:
  | 
| 
rb@277
 | 
   322  | 
        card = None
  | 
| 
rb@277
 | 
   323  | 
    if card is not None:
  | 
| 
rb@277
 | 
   324  | 
        qr_image = qr_image_data(card)
  | 
| 
rb@277
 | 
   325  | 
        author = render_template("/author_info.html", act="author", title=_(u"IEK-7"),
 | 
| 
icg179@496
 | 
   326  | 
                                 card=card, image=qr_image, contact=_(u"Contact"), exit=_(u"Close"))
  | 
| 
rb@277
 | 
   327  | 
  | 
| 
rb@264
 | 
   328  | 
    return render_template("/iek-7.html", act="iek-7", content=content,
 | 
| 
j@380
 | 
   329  | 
                           author=author, card=card, contact=u"IEK-7")
  | 
| 
peter@1
 | 
   330  | 
  | 
| 
peter@1
 | 
   331  | 
  | 
| 
rb@100
 | 
   332  | 
@app.route("/imprint")
 | 
| 
peter@88
 | 
   333  | 
def imprint():
  | 
| 
rb@163
 | 
   334  | 
    filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
 | 
| 
rb@163
 | 
   335  | 
    content = get_content(filename)
  | 
| 
rb@170
 | 
   336  | 
    return render_template("/content.html", act="imprint", content=content)
 | 
| 
peter@88
 | 
   337  | 
  | 
| 
peter@109
 | 
   338  | 
  | 
| 
peter@1
 | 
   339  | 
@app.errorhandler(404)
  | 
| 
peter@1
 | 
   340  | 
def page_not_found(e):
  | 
| 
rb@213
 | 
   341  | 
    msg = _(u"Url: %(url)s not found", url=request.url)
  | 
| 
rb@157
 | 
   342  | 
    info = _(u"This information is not available!")
  | 
| 
rb@157
 | 
   343  | 
    return render_template("404.html", msg=msg, info=info)
 | 
| 
peter@1
 | 
   344  | 
  | 
| 
icg179@496
 | 
   345  | 
  | 
| 
peter@1
 | 
   346  | 
if __name__ == "__main__":
  | 
| 
icg179@496
 | 
   347  | 
    app.run(host='localhost', port=5014, debug=True)
  |