Skip to content
Snippets Groups Projects
Commit 9b84296c authored by Julian Rother's avatar Julian Rother
Browse files

Cleanup

parent c716b741
Branches
No related tags found
No related merge requests found
...@@ -22,14 +22,12 @@ config.from_pyfile('config.py', silent=True) ...@@ -22,14 +22,12 @@ config.from_pyfile('config.py', silent=True)
from db import query, searchquery, ldapauth, ldapget from db import query, searchquery, ldapauth, ldapget
app.jinja_env.globals['videoprefix'] = config['VIDEOPREFIX']
mod_endpoints = [] mod_endpoints = []
@app.template_global()
def ismod(*args): def ismod(*args):
return ('user' in session) return ('user' in session)
app.jinja_env.globals['ismod'] = ismod
def mod_required(func): def mod_required(func):
mod_endpoints.append(func.__name__) mod_endpoints.append(func.__name__)
@wraps(func) @wraps(func)
...@@ -50,6 +48,18 @@ def register_navbar(name, icon=None): ...@@ -50,6 +48,18 @@ def register_navbar(name, icon=None):
return func return func
return wrapper return wrapper
def render_endpoint(endpoint, flashtext=None, **kargs):
if flashtext:
flash(flashtext)
# request.endpoint is used for navbar highlighting
if request.url_rule:
request.url_rule.endpoint = endpoint
return app.view_functions[endpoint](**kargs)
@app.errorhandler(404)
def handle_not_found(e):
return render_endpoint('index', 'Diese Seite existiert nicht!')
@app.route('/') @app.route('/')
@register_navbar('Home', icon='home') @register_navbar('Home', icon='home')
def index(): def index():
...@@ -80,8 +90,7 @@ def videos(): ...@@ -80,8 +90,7 @@ def videos():
def course(id): def course(id):
courses = query('SELECT * FROM courses WHERE ((handle = ?) or id = ?) AND (? OR visible)', id, id, ismod()) courses = query('SELECT * FROM courses WHERE ((handle = ?) or id = ?) AND (? OR visible)', id, id, ismod())
if not courses: if not courses:
flash('Diese Veranstaltung existiert nicht!') return render_endpoint('index', 'Diese Veranstaltung existiert nicht!'), 404
return app.view_functions['videos'](), 404
lectures = query('SELECT * FROM lectures WHERE course_id = ? AND (? OR visible)', courses[0]['id'], ismod()) lectures = query('SELECT * FROM lectures WHERE course_id = ? AND (? OR visible)', courses[0]['id'], ismod())
videos = query(''' videos = query('''
SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, formats.description AS format_description SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, formats.description AS format_description
...@@ -104,14 +113,12 @@ def play(id): ...@@ -104,14 +113,12 @@ def play(id):
lectures = query('SELECT * FROM lectures WHERE id = ? AND (? OR visible)', id, ismod()) lectures = query('SELECT * FROM lectures WHERE id = ? AND (? OR visible)', id, ismod())
videos = query('SELECT * FROM videos WHERE lecture_id = ? AND (? OR visible)', id, ismod()) videos = query('SELECT * FROM videos WHERE lecture_id = ? AND (? OR visible)', id, ismod())
if not lectures: if not lectures:
flash('Diese Vorlesung existiert nicht!') return render_endpoint('videos', 'Diese Vorlesung existiert nicht!'), 404
return app.view_functions['videos'](), 404
if not videos: if not videos:
flash('Zu dieser Vorlesung wurden noch keine Videos veröffentlicht!') flash('Zu dieser Vorlesung wurden noch keine Videos veröffentlicht!')
courses = query('SELECT * FROM courses WHERE id = ? AND (? OR (visible AND listed))', lectures[0]['course_id'], ismod()) courses = query('SELECT * FROM courses WHERE id = ? AND (? OR (visible AND listed))', lectures[0]['course_id'], ismod())
if not courses: if not courses:
flash('Diese Veranstaltung existiert nicht!') return render_endpoint('videos', 'Diese Veranstaltung existiert nicht!'), 404
return app.view_functions['videos'](), 404
return render_template('play.html', course=courses[0], lecture=lectures[0], videos=videos) return render_template('play.html', course=courses[0], lecture=lectures[0], videos=videos)
@app.route('/search') @app.route('/search')
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
{% for endpoint, caption, gly, visible in navbar %} {% for endpoint, caption, gly, visible in navbar %}
{% if visible or ismod() %} {% if visible or ismod() %}
<li{% if endpoint == request.endpoint %} class="active"{% endif %}> <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> <a href="{{ url_for(endpoint) }}">{% if gly != '' %}<span class="glyphicon glyphicon-{{ gly }}"></span> {% endif %}{{ caption }}</a>
</li> </li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
...@@ -63,12 +63,12 @@ ...@@ -63,12 +63,12 @@
{ {
html:true, html:true,
title:'Login für Moderatoren', title:'Login für Moderatoren',
content:'<form method="post" action="{{url_for('login')}}"><input placeholder="User" name="user" type="text"><br><input placeholder="Password" name="password" type="password"><br><input type="hidden" name="ref" value="{{ request.url|e }}"><input type="submit" value="Login"></form>' content:'<form method="post" action="{{url_for('login', ref=request.url)}}"><input placeholder="User" name="user" type="text"><br><input placeholder="Password" name="password" type="password"><br><input type="submit" value="Login"></form>'
} }
) )
</script> </script>
{% else %} {% else %}
<a href="{{url_for('logout')}}?ref={{ request.url|urlencode }}"> <a href="{{url_for('logout', ref=request.url)}}">
{{ session.user.givenName }} {{ session.user.givenName }}
<span class="glyphicon glyphicon-log-out"></span> <span class="glyphicon glyphicon-log-out"></span>
</a> </a>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<li class="list-group-item"> <li class="list-group-item">
<a class="hidden-xs" href="{{url_for('play', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}"> <a class="hidden-xs" href="{{url_for('play', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}">
<div class="row"> <div class="row">
<img class="col-xs-4" src="{{ videoprefix }}/{{ lecture['titlefile'] }}" alt="Vorschaubild"> <img class="col-xs-4" src="{{ config.VIDEOPREFIX }}/{{ lecture['titlefile'] }}" alt="Vorschaubild">
<div class="col-xs-4"> <div class="col-xs-4">
<span style="color: #000;"><strong>{{ lecture['short'] }}</strong></span><br> <span style="color: #000;"><strong>{{ lecture['short'] }}</strong></span><br>
<span style="color: #000;">{{ lecture['time'] }}</span> <span style="color: #000;">{{ lecture['time'] }}</span>
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</a> </a>
<a class="visible-xs" href="{{url_for('play', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}"> <a class="visible-xs" href="{{url_for('play', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}">
<div class="row"> <div class="row">
<img class="col-xs-12" src="{{ videoprefix }}/{{ lecture['titlefile'] }}" alt="Vorschaubild"> <img class="col-xs-12" src="{{ config.VIDEOPREFIX }}/{{ lecture['titlefile'] }}" alt="Vorschaubild">
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<link rel="stylesheet" href="{{url_for('static', filename='mediaelementjs/mediaelementplayer.css')}}" /> <link rel="stylesheet" href="{{url_for('static', filename='mediaelementjs/mediaelementplayer.css')}}" />
<video class="mejs-player" width="640" height="360" style="width: 100%; height: 100%;"> <video class="mejs-player" width="640" height="360" style="width: 100%; height: 100%;">
{% for v in videos %} {% for v in videos %}
<source type="video/mp4" src="{{ videoprefix }}/{{ v.path }}" /> <source type="video/mp4" src="{{ config.VIDEOPREFIX }}/{{ v.path }}" />
{% endfor %} {% endfor %}
</video> </video>
<script> <script>
...@@ -94,13 +94,13 @@ ...@@ -94,13 +94,13 @@
<button class="btn btn-primary dropdown-toggle {% if videos|length is equalto 0 %}disabled{% endif %}" type="button" data-toggle="dropdown">Download <span class="caret"></span></button> <button class="btn btn-primary dropdown-toggle {% if videos|length is equalto 0 %}disabled{% endif %}" type="button" data-toggle="dropdown">Download <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
{% for v in videos %} {% for v in videos %}
{% if v.downloadable %} <li><a href="{{ videoprefix }}/{{v.path}}">{{ valuecheckbox(['videos',v.id,'visible'], v.visible) }} {{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>{% endif %} {% if v.downloadable %} <li><a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{ valuecheckbox(['videos',v.id,'visible'], v.visible) }} {{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
<noscript> <noscript>
<ul class="pull-right list-unstyled" style="margin-left:10px;"> <ul class="pull-right list-unstyled" style="margin-left:10px;">
{% for v in videos %} {% for v in videos %}
<li><a href="{{ videoprefix }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li> <li><a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</noscript> </noscript>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment