diff --git a/server.py b/server.py index c914df7ab6d7c1734359d360fb935587c2c5f93b..4ff1396b5d9bb2f27d8a4505bf0246b3d5e58223 100755 --- a/server.py +++ b/server.py @@ -136,7 +136,15 @@ def mod_required(func): return func(*args, **kwargs) return decorator +app.jinja_env.globals['navbar'] = [] +def register_navbar(name, icon=None): + def wrapper(func): + app.jinja_env.globals['navbar'].append((func.__name__, name, icon)) + return func + return wrapper + @app.route('/') +@register_navbar('Home', icon='home') def index(): return render_template('index.html', latestvideos=query(''' SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.short, courses.downloadable, courses.title AS coursetitle @@ -150,6 +158,7 @@ def index(): ''', ismod())) @app.route('/videos') +@register_navbar('Videos', icon='film') def videos(): courses = query('SELECT * FROM courses WHERE (? OR (visible AND listed))', ismod()) for course in courses: @@ -161,6 +170,7 @@ def videos(): return render_template('videos.html', courses=courses, groupedby=groupedby) @app.route('/faq') +@register_navbar('FAQ', icon='question-sign') def faq(): return render_template('faq.html') diff --git a/templates/base.html b/templates/base.html index a6ad2219de0963a4c28ab40a25b691b3287cf99f..2c7eb73175777a23ec18c9aa0783fc104cc70502 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,10 +1,3 @@ -{% set navigation_bar = [ -('/', 'index', 'Home', 'home'), -('/videos', 'videos', 'Videos', 'film'), -('/faq', 'faq', 'FAQ', 'question-sign') -] -%} -{% set active_page = active_page|default('none') -%} - {% set page_border = page_border|default(1) -%} <!DOCTYPE html> @@ -53,9 +46,9 @@ <div class="row"> <div class="col-xs-12 col-sm-8"> <ul class="nav nav-pills"> - {% for href, id, caption, gly in navigation_bar %} - <li{% if id == active_page %} class="active"{% endif %}> - <a href="{{ href|e }}">{% if gly != '' %}<span class="glyphicon glyphicon-{{ gly }}"></span> {% endif %}{{ caption }}</a> + {% for endpoint, caption, gly in navbar %} + <li{% if endpoint == request.endpoint %} class="active"{% endif %}> + <a href="{{ url_for(endpoint)|e }}">{% if gly != '' %}<span class="glyphicon glyphicon-{{ gly }}"></span> {% endif %}{{ caption }}</a> </li> {% endfor %} <li class="navbar-right"> diff --git a/templates/faq.html b/templates/faq.html index 737585aead498893a878a5be8e17060290258425..29519ca87fa48d5038d48af279539c32a38ee4bd 100644 --- a/templates/faq.html +++ b/templates/faq.html @@ -1,6 +1,5 @@ {% from 'macros.html' import preview %} {% extends "base.html" %} -{% set active_page = "faq" %} {% block content %} <div class="alert alert-warning alert-dismissible" role="alert" id="kontakt"> Unter <a href="mailto:video@fsmpi.rwth-aachen.de">video@fsmpi.rwth-aachen.de</a> stehen wir für alle Fragen bereit. diff --git a/templates/index.html b/templates/index.html index 32134c5b18e6380c8dbd0ab5c05d3c9c04a382ce..6ad3b970f053ecfb6b719257d8f2cdf56c109eec 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,5 @@ {% from 'macros.html' import preview %} {% extends "base.html" %} -{% set active_page = "index" %} {% set page_border = 0 %} {% block content %} <div class="row"> diff --git a/templates/videos.html b/templates/videos.html index 931c1d62314809c6ae8617bac2d8c878dce2adcb..57feef3c14b94ee041ad080371192f96b2fed16c 100644 --- a/templates/videos.html +++ b/templates/videos.html @@ -1,6 +1,4 @@ {% from 'macros.html' import course_list_item %} -{% set active_page = 'videos' -%} - {% extends "base.html" %} {% block content %} <div class="row">