|
1 import os |
|
2 import codecs |
|
3 |
|
4 from docutils.core import publish_parts |
1 from flask import Flask |
5 from flask import Flask |
2 from flask import render_template |
6 from flask import render_template |
3 from flask import request |
7 from flask import request |
4 from flask import abort, redirect, url_for |
|
5 import os |
|
6 from flask import send_from_directory |
|
7 import logging |
|
8 from logging import Formatter |
|
9 |
|
10 from flask.ext.babel import gettext as _ |
8 from flask.ext.babel import gettext as _ |
11 from flask.ext.babel import Babel |
9 from flask.ext.babel import Babel |
12 |
|
13 from config import LANGUAGES |
10 from config import LANGUAGES |
14 from sayings import get_saying |
11 from sayings import get_saying |
15 from jinja2 import Environment, FileSystemLoader |
|
16 |
|
17 import codecs |
|
18 from docutils.core import publish_parts |
|
19 |
12 |
20 |
13 |
21 LANGUAGE_SELECTED = "de" |
14 LANGUAGE_SELECTED = "de" |
22 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None |
15 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None |
23 |
16 |
24 app = Flask(__name__) |
17 app = Flask(__name__) |
25 babel = Babel(app) |
18 babel = Babel(app) |
26 |
19 |
27 app.config['BABEL_DEFAULT_LOCALE'] = 'de' |
20 app.config['BABEL_DEFAULT_LOCALE'] = 'de' |
|
21 |
28 |
22 |
29 def get_content(filename): |
23 def get_content(filename): |
30 content = u"" |
24 content = u"" |
31 if os.path.isfile(filename): |
25 if os.path.isfile(filename): |
32 with codecs.open(filename, 'r', 'utf-8') as f: |
26 with codecs.open(filename, 'r', 'utf-8') as f: |
34 f.close() |
28 f.close() |
35 content = publish_parts(rst_data, writer_name='html')['html_body'] |
29 content = publish_parts(rst_data, writer_name='html')['html_body'] |
36 return content |
30 return content |
37 |
31 |
38 def get_topmenue(): |
32 def get_topmenue(): |
39 menue = [('/competition', _(u'Competition')), |
33 menue = [('/competition', _(u'Competition')), |
40 ('/task', _(u'Task')), |
34 ('/task', _(u'Task')), |
41 ('/submission', _(u'Submission')), |
35 ('/submission', _(u'Submission')), |
42 ('/coursematerial', _(u'Coursematerial')), |
36 ('/coursematerial', _(u'Coursematerial')), |
43 ] |
37 ] |
44 return menue |
38 return menue |
45 |
39 |
46 app.jinja_env.globals.update(get_topmenue=get_topmenue) |
40 app.jinja_env.globals.update(get_topmenue=get_topmenue) |
47 |
41 |
48 |
42 |
55 @app.route("/") |
49 @app.route("/") |
56 @app.route("/index") |
50 @app.route("/index") |
57 def index(): |
51 def index(): |
58 saying, author = get_saying() |
52 saying, author = get_saying() |
59 return render_template("/index.html", |
53 return render_template("/index.html", |
60 saying = saying, |
54 saying=saying, |
61 author = author, |
55 author=author, |
62 competition_info=_(u'About Competition'), |
56 competition_info=_(u'About Competition'), |
63 dates=_(u'Dates'), |
57 dates=_(u'Dates'), |
64 impressions=_(u'Impressions')) |
58 impressions=_(u'Impressions')) |
65 |
59 |
66 @app.route('/de') |
60 @app.route('/de') |
67 def de(): |
61 def de(): |
68 global LANGUAGE_SELECTED |
62 global LANGUAGE_SELECTED |
69 LANGUAGE_SELECTED = "de" |
63 LANGUAGE_SELECTED = "de" |
70 saying, author = get_saying() |
64 saying, author = get_saying() |
71 return render_template("/index.html", |
65 return render_template("/index.html", |
72 saying = saying, |
66 saying=saying, |
73 author = author, |
67 author=author, |
74 competition_info=_(u'About Competition'), |
68 competition_info=_(u'About Competition'), |
75 dates=_(u'Dates'), |
69 dates=_(u'Dates'), |
76 impressions=_(u'Impressions')) |
70 impressions=_(u'Impressions')) |
77 |
71 |
78 @app.route('/en') |
72 @app.route('/en') |
79 def en(): |
73 def en(): |
80 saying, author = get_saying() |
74 saying, author = get_saying() |
81 global LANGUAGE_SELECTED |
75 global LANGUAGE_SELECTED |
82 LANGUAGE_SELECTED = "en" |
76 LANGUAGE_SELECTED = "en" |
83 return render_template("/index.html", |
77 return render_template("/index.html", |
84 saying = saying, |
78 saying=saying, |
85 author = author, |
79 author=author, |
86 competition_info=_(u'About Competition'), |
80 competition_info=_(u'About Competition'), |
87 dates=_(u'Dates'), |
81 dates=_(u'Dates'), |
88 impressions=_(u'Impressions')) |
82 impressions=_(u'Impressions')) |
89 |
83 |
90 @app.route("/competition") |
84 @app.route("/competition") |