1 from flask import Flask
 
     2 from flask import render_template
 
     3 from flask import request
 
     4 from flask import abort, redirect, url_for
 
     6 from flask import send_from_directory
 
     8 from logging import Formatter
 
    10 from flask.ext.babel import gettext as _
 
    11 from flask.ext.babel import Babel
 
    13 from config import LANGUAGES
 
    14 from sayings import get_saying
 
    15 from jinja2 import Environment, FileSystemLoader
 
    18 from docutils.core import publish_parts
 
    21 LANGUAGE_SELECTED = "de"
 
    22 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
 
    27 app.config['BABEL_DEFAULT_LOCALE'] = 'de'
 
    29 def get_content(filename):
 
    31     if os.path.isfile(filename):
 
    32         with codecs.open(filename, 'r', 'utf-8') as f:
 
    35         content = publish_parts(rst_data, writer_name='html')['html_body']
 
    39     menue =  [('/competition', _(u'Competition')),
 
    40               ('/task', _(u'Task')),
 
    41               ('/submission', _(u'Submission')),
 
    42               ('/coursematerial', _(u'Coursematerial')),
 
    46 app.jinja_env.globals.update(get_topmenue=get_topmenue)
 
    51     """ToDo: if translation is completed, switch to en """
 
    52     return LANGUAGE_SELECTED or request.accept_languages.best_match(LANGUAGES.keys()) or 'de'
 
    58     saying, author = get_saying()
 
    59     return render_template("/index.html", 
 
    62                            competition_info=_(u'About Competition'),
 
    67     global LANGUAGE_SELECTED
 
    68     LANGUAGE_SELECTED = "de"
 
    69     saying, author = get_saying()
 
    70     return render_template("/index.html",
 
    73                            competition_info=_(u'About Competition'),
 
    78     saying, author = get_saying()
 
    79     global LANGUAGE_SELECTED
 
    80     LANGUAGE_SELECTED = "en"
 
    81     return render_template("/index.html",
 
    84                            competition_info=_(u'About Competition'),
 
    87 @app.route("/competition")
 
    89     filename = os.path.join("templates", get_locale(), "rst", "competition.rst")
 
    90     content = get_content(filename)
 
    91     return render_template("/content.html", act="competition", content=content)
 
    95     filename = os.path.join("templates", get_locale(), "rst", "task.rst")
 
    96     content = get_content(filename)
 
    97     return render_template("/content.html", act="task", content=content)
 
    99 @app.route("/submission")
 
   101     filename = os.path.join("templates", get_locale(), "rst", "submission.rst")
 
   102     content = get_content(filename)
 
   103     return render_template("/content.html", act="submission", content=content)
 
   105 @app.route("/coursematerial")
 
   106 def coursematerial():
 
   107     filename = os.path.join("templates", get_locale(), "rst", "coursematerial.rst")
 
   108     content = get_content(filename)
 
   109     return render_template("/content.html", act="coursematerial", content=content)
 
   111 @app.route("/imprint")
 
   113     filename = os.path.join("templates", get_locale(), "rst", "imprint.rst")
 
   114     content = get_content(filename)
 
   115     return render_template("/content.html", act="imprint", content=content)
 
   117 @app.route("/privacy")
 
   119     filename = os.path.join("templates", get_locale(), "rst", "privacy.rst")
 
   120     content = get_content(filename)
 
   121     return render_template("/content.html", act="privacy", content=content)
 
   125     filename = os.path.join("templates", get_locale(), "rst", "dates.rst")
 
   126     content = get_content(filename)
 
   127     return render_template("/content.html",
 
   128                            act="dates", content=content)
 
   130 @app.route("/competition/2013")
 
   131 def competition_2013():
 
   132     print get_locale() + "/archive/competitions/2013/index.html"
 
   133     return render_template(get_locale() + "/archive/competitions/2013/index.html", 
 
   134                            act="coursematerial")
 
   136 @app.route("/competition/2014")
 
   137 def competition_2014():
 
   138     print get_locale() + "/archive/competitions/2014/index.html"
 
   139     return render_template(get_locale() + "/archive/competitions/2014/index.html", 
 
   140                            act="coursematerial")
 
   142 @app.errorhandler(404)
 
   143 def page_not_found(e):
 
   144     msg = _(u"Url: %(url)s not found" , url=request.url)
 
   145     info = _(u"This information is not available!")
 
   146     return render_template("404.html", msg=msg, info=info)
 
   148 if __name__ == "__main__":
 
   149     app.run(host='localhost', port=5014, debug=True)