topmenu as global function for jinja tmeplates
authorPeter Koppatz <peter@koppatz.com>
Sat, 18 Jan 2014 20:43:38 +0100
changeset 1426dea01810014
parent 141 ea70f3d81676
child 143 ced4e431cdd9
topmenu as global function for jinja tmeplates
pymove3d.py
templates/theme.html
     1.1 --- a/pymove3d.py	Sat Jan 18 20:06:19 2014 +0100
     1.2 +++ b/pymove3d.py	Sat Jan 18 20:43:38 2014 +0100
     1.3 @@ -12,6 +12,7 @@
     1.4  
     1.5  from config import LANGUAGES
     1.6  from sayings import get_saying
     1.7 +from jinja2 import Environment, FileSystemLoader
     1.8  
     1.9  LANGUAGE_SELECTED = "de"
    1.10  #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
    1.11 @@ -19,6 +20,19 @@
    1.12  app = Flask(__name__)
    1.13  babel = Babel(app)
    1.14  
    1.15 +def get_topmenue():
    1.16 +    
    1.17 +    topmenue = [('/competition', _('Competition')),
    1.18 +                ('/task', _('Task')),
    1.19 +                ('/submission', _('Submission')),
    1.20 +                ('/coursematerial', _('Coursematerial')),
    1.21 +                ]
    1.22 +    
    1.23 +    return topmenue
    1.24 +
    1.25 +app.jinja_env.globals.update(get_topmenue=get_topmenue)
    1.26 +
    1.27 +
    1.28  @babel.localeselector
    1.29  def get_locale():
    1.30      """ToDo: if translation is completed, switch to en """
     2.1 --- a/templates/theme.html	Sat Jan 18 20:06:19 2014 +0100
     2.2 +++ b/templates/theme.html	Sat Jan 18 20:43:38 2014 +0100
     2.3 @@ -41,12 +41,7 @@
     2.4              </div>
     2.5              <div class="collapse navbar-collapse">
     2.6                <ul class="nav navbar-nav navbar-right">
     2.7 -               {% for href, caption in [('/competition', 'Competition'),
     2.8 -               ('/task', 'Task'),
     2.9 -               ('/submission', 'Submission'),
    2.10 -               ('/coursematerial', 'Coursematerial'),
    2.11 -               ]:
    2.12 -               %}
    2.13 +               {% for href, caption in get_topmenue(): %}
    2.14                 {%- if href[1:] == act -%} 
    2.15                 <li class="active">{% else %} <li>{% endif %}<a href="{{ href }}" >{{ caption }}</a></li>
    2.16                 {% endfor %}
Impressum Datenschutzerklärung