From cb8cd916612d8b69e308871560898e10ef0de8f2 Mon Sep 17 00:00:00 2001
From: Andreas <andreasv@fsmpi.rwth-aachen.de>
Date: Wed, 5 Oct 2016 12:54:28 +0200
Subject: [PATCH] fixed download button

---
 config.py.example     |  2 +-
 server.py             | 18 +++++++++++++-----
 templates/course.html |  2 +-
 templates/macros.html |  2 +-
 4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/config.py.example b/config.py.example
index 711c23f..289983e 100644
--- a/config.py.example
+++ b/config.py.example
@@ -1,7 +1,7 @@
 # Defaults for development ,do not use in production!
 DEBUG = False
 VIDEOPREFIX = 'https://videoag.fsmpi.rwth-aachen.de'
-VIDEOMOUNT = ['files/protected/','files/pub/','files/vpnonline/']
+VIDEOMOUNT = [{'mountpoint': 'files/protected/', 'prefix':'protected/'},{'mountpoint':'files/pub/','prefix':'pub/' }, {'mountpoint':'files/vpnonline/','prefix':'vpnonline/' }]
 #SECRET_KEY = 'something random'
 
 DB_SCHEMA = 'db_schema.sql'
diff --git a/server.py b/server.py
index 4cbbe46..bd0c769 100644
--- a/server.py
+++ b/server.py
@@ -220,15 +220,23 @@ def faq():
 @app.route('/embed/<int:id>', endpoint='embed')
 @handle_errors('course', 'Diese Vorlesung existiert nicht!', 404, IndexError)
 def lecture(id):
-	lectures = query('SELECT * FROM lectures WHERE id = ? AND (? OR visible)', id, ismod())
-	videos = query('SELECT videos.*, formats.description AS format_description, formats.prio, formats.player_prio FROM videos JOIN formats ON (videos.video_format = formats.id) WHERE lecture_id = ? AND (? OR visible)', id, ismod())
+	lecture = query('SELECT * FROM lectures WHERE id = ? AND (? OR visible)', id, ismod())[0]
+	videos = query('''
+			SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, formats.description AS format_description, formats.player_prio, formats.prio
+			FROM videos
+			JOIN lectures ON (videos.lecture_id = lectures.id)
+			JOIN formats ON (videos.video_format = formats.id)
+			JOIN courses ON (lectures.course_id = courses.id)
+			WHERE lectures.course_id= ? AND (? OR videos.visible)
+			ORDER BY lectures.time, formats.prio DESC
+			''', lecture['course_id'], ismod())
 	if not videos:
 		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())
-	if not courses:
+	course = query('SELECT * FROM courses WHERE id = ? AND (? OR (visible AND listed))', lecture['course_id'], ismod())
+	if not course:
 		return render_endpoint('course', 'Diese Veranstaltung existiert nicht!'), 404
 	chapters = query('SELECT * FROM chapters WHERE lecture_id = ? AND NOT deleted AND (? OR visible) ORDER BY time ASC', id, ismod())
-	return render_template('embed.html' if request.endpoint == 'embed' else 'lecture.html', course=courses[0], lecture=lectures[0], videos=videos, chapters=chapters)
+	return render_template('embed.html' if request.endpoint == 'embed' else 'lecture.html', course=course, lecture=lecture, videos=videos, chapters=chapters)
 
 
 @app.route('/search')
diff --git a/templates/course.html b/templates/course.html
index 97c7982..a371248 100644
--- a/templates/course.html
+++ b/templates/course.html
@@ -32,7 +32,7 @@
 				<tbody>
 					<tr><td>Sichtbar:</td><td>{{ moderator_checkbox(['courses',course.id,'visible'], course.visible) }}</td></tr>
 					<tr><td>Gelistet:</td><td>{{ moderator_checkbox(['courses',course.id,'listed'], course.listed) }}</td></tr>
-					<tr><td>Downloadable:</td><td>{{ moderator_checkbox(['courses',course.id,'downloadable'], course.downloadable) }}</td></tr>
+					<tr><td>Videos downloadbar:</td><td>{{ moderator_checkbox(['courses',course.id,'downloadable'], course.downloadable) }}</td></tr>
 					<tr><td>Short:</td><td>{{ moderator_editor(['courses',course.id,'short'], course.short) }}</td></tr>
 					<tr><td>Handle:</td><td>{{ moderator_editor(['courses',course.id,'handle'], course.handle) }}</td></tr>
 					<tr><td>Thema:</td><td>{{ moderator_editor(['courses',course.id,'subject'], course.subject) }}</td></tr>
diff --git a/templates/macros.html b/templates/macros.html
index 16b0ed3..ab23ba5 100644
--- a/templates/macros.html
+++ b/templates/macros.html
@@ -84,7 +84,7 @@ $('#videoplayer').css("width");
 <span class="btn btn-default dropdown-toggle{% if videos|length is equalto 0 %} disabled{% endif %}" type="button" data-toggle="dropdown">Download <span class="caret"></span></span>
 <ul class="dropdown-menu">
 	{% for v in videos|sort(attribute='prio', reverse=True) %}
-		{% if v.downloadable %}	
+		{% if v.downloadable or ismod() %}	
 		<li><a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{ moderator_checkbox(['videos',v.id,'visible'], v.visible) }} {{v.format_description}} ({{v.file_size|filesizeformat(true)}}) {{moderator_delete(['videos',v.id,'deleted'])}} </a></li>
 		{% endif %}
 	{% endfor %}
-- 
GitLab