Commit 5f1f10d0 authored by Julian Rother's avatar Julian Rother
Browse files

Implemented navbar items as decorators

parent d3fadbf9
...@@ -136,7 +136,15 @@ def mod_required(func): ...@@ -136,7 +136,15 @@ def mod_required(func):
return func(*args, **kwargs) return func(*args, **kwargs)
return decorator 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('/') @app.route('/')
@register_navbar('Home', icon='home')
def index(): def index():
return render_template('index.html', latestvideos=query(''' return render_template('index.html', latestvideos=query('''
SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.short, courses.downloadable, courses.title AS coursetitle SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.short, courses.downloadable, courses.title AS coursetitle
...@@ -150,6 +158,7 @@ def index(): ...@@ -150,6 +158,7 @@ def index():
''', ismod())) ''', ismod()))
@app.route('/videos') @app.route('/videos')
@register_navbar('Videos', icon='film')
def videos(): def videos():
courses = query('SELECT * FROM courses WHERE (? OR (visible AND listed))', ismod()) courses = query('SELECT * FROM courses WHERE (? OR (visible AND listed))', ismod())
for course in courses: for course in courses:
...@@ -161,6 +170,7 @@ def videos(): ...@@ -161,6 +170,7 @@ def videos():
return render_template('videos.html', courses=courses, groupedby=groupedby) return render_template('videos.html', courses=courses, groupedby=groupedby)
@app.route('/faq') @app.route('/faq')
@register_navbar('FAQ', icon='question-sign')
def faq(): def faq():
return render_template('faq.html') return render_template('faq.html')
......
{% 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) -%} {% set page_border = page_border|default(1) -%}
<!DOCTYPE html> <!DOCTYPE html>
...@@ -53,9 +46,9 @@ ...@@ -53,9 +46,9 @@
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<ul class="nav nav-pills"> <ul class="nav nav-pills">
{% for href, id, caption, gly in navigation_bar %} {% for endpoint, caption, gly in navbar %}
<li{% if id == active_page %} class="active"{% endif %}> <li{% if endpoint == request.endpoint %} class="active"{% endif %}>
<a href="{{ href|e }}">{% if gly != '' %}<span class="glyphicon glyphicon-{{ gly }}"></span> {% endif %}{{ caption }}</a> <a href="{{ url_for(endpoint)|e }}">{% if gly != '' %}<span class="glyphicon glyphicon-{{ gly }}"></span> {% endif %}{{ caption }}</a>
</li> </li>
{% endfor %} {% endfor %}
<li class="navbar-right"> <li class="navbar-right">
......
{% from 'macros.html' import preview %} {% from 'macros.html' import preview %}
{% extends "base.html" %} {% extends "base.html" %}
{% set active_page = "faq" %}
{% block content %} {% block content %}
<div class="alert alert-warning alert-dismissible" role="alert" id="kontakt"> <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. Unter <a href="mailto:video@fsmpi.rwth-aachen.de">video@fsmpi.rwth-aachen.de</a> stehen wir für alle Fragen bereit.
......
{% from 'macros.html' import preview %} {% from 'macros.html' import preview %}
{% extends "base.html" %} {% extends "base.html" %}
{% set active_page = "index" %}
{% set page_border = 0 %} {% set page_border = 0 %}
{% block content %} {% block content %}
<div class="row"> <div class="row">
......
{% from 'macros.html' import course_list_item %} {% from 'macros.html' import course_list_item %}
{% set active_page = 'videos' -%}
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<div class="row"> <div class="row">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment