From 6e4a112577ce741916906966dd2c57c0504a6f4c Mon Sep 17 00:00:00 2001 From: Julian Rother <julianr@fsmpi.rwth-aachen.de> Date: Mon, 16 Oct 2017 00:06:19 +0200 Subject: [PATCH] Implemented optional chapter links on course page --- db_schema.sql | 3 ++- edit.py | 3 ++- server.py | 5 ++++- templates/course.html | 3 ++- templates/macros.html | 5 ++++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/db_schema.sql b/db_schema.sql index 44ac919..02d4ef1 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -62,7 +62,8 @@ CREATE TABLE IF NOT EXISTS `courses_data` ( `internal` text NOT NULL DEFAULT '', `responsible` text NOT NULL DEFAULT '', `feed_url` text NOT NULL DEFAULT '', - `external` INTEGER NOT NULL DEFAULT 0 + `external` INTEGER NOT NULL DEFAULT 0, + `coursechapters` INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE IF NOT EXISTS `filesizes` ( `path` varchar(255) NOT NULL PRIMARY KEY, diff --git a/edit.py b/edit.py index 87659ed..e12116f 100644 --- a/edit.py +++ b/edit.py @@ -25,7 +25,8 @@ editable_tables = { 'responsible': {'type': 'shortstring'}, 'deleted': {'type': 'boolean'}, 'description': {'type': 'text'}, - 'external': {'type': 'boolean', 'description': 'Soll die Veranstaltung nicht im Drehplan angezeigt werden?'}}, + 'external': {'type': 'boolean', 'description': 'Soll die Veranstaltung nicht im Drehplan angezeigt werden?'}, + 'coursechapters': {'type': 'boolean', 'description': 'Sollen auf der Kursseite die Kapitelmarker der Videos angezeigt werden?'}}, 'creationtime_fields': ['created_by', 'time_created', 'time_updated'] }, 'lectures': { 'table': 'lectures_data', diff --git a/server.py b/server.py index 0c4de2e..16bca01 100644 --- a/server.py +++ b/server.py @@ -237,8 +237,11 @@ def course(id=None, handle=None): JOIN formats ON formats.keywords = "hls" WHERE streams.active AND (? OR streams.visible) AND lectures.course_id = ? ''', ismod(), course['id']) + chapters = [] + if course['coursechapters']: + chapters = query('SELECT chapters.* FROM chapters JOIN lectures ON lectures.id = chapters.lecture_id WHERE lectures.course_id = ? AND NOT chapters.deleted AND chapters.visible ORDER BY time ASC', course['id']) videos += genlive(livestreams) - return render_template('course.html', course=course, lectures=lectures, videos=videos) + return render_template('course.html', course=course, lectures=lectures, videos=videos, chapters=chapters) @app.route('/faq') @register_navbar('FAQ', icon='question-sign') diff --git a/templates/course.html b/templates/course.html index a9175a0..1437b4c 100644 --- a/templates/course.html +++ b/templates/course.html @@ -43,6 +43,7 @@ <tr><td>Gelistet:</td><td>{{ moderator_checkbox(['courses',course.id,'listed'], course.listed) }}</td></tr> <tr><td>Nicht im Drehplan:</td><td>{{ moderator_checkbox(['courses',course.id,'external'], course.external) }}</td></tr> <tr><td>Videos downloadbar:</td><td>{{ moderator_checkbox(['courses',course.id,'downloadable'], course.downloadable) }}</td></tr> + <tr><td>Kapitel auf Kursseite:</td><td>{{ moderator_checkbox(['courses',course.id,'coursechapters'], course.coursechapters) }}</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> @@ -93,7 +94,7 @@ </div> <ul class="list-group lectureslist"> {% for l in lectures %} - {{ lecture_list_item(l,videos|selectattr('lecture_id','equalto',l.id)|list,global_permissions)}} + {{ lecture_list_item(l,videos|selectattr('lecture_id','equalto',l.id)|list,global_permissions,chapters=chapters|selectattr('lecture_id','equalto',l.id))}} {% endfor %} </ul> </div> diff --git a/templates/macros.html b/templates/macros.html index ab1a2c9..0ec91ee 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -204,7 +204,7 @@ $('#embedcodebtn').popover( </script> {% endmacro %} -{% macro lecture_list_item(lecture,videos,global_permissions) %} +{% macro lecture_list_item(lecture,videos,global_permissions,chapters=[]) %} <li class="list-group-item{% if lecture.norecording %} text-muted{% endif %}" id="lecture-{{lecture.id}}"> <div class="row"> {% if ismod() or (videos|length > 0) %} @@ -228,6 +228,9 @@ $('#embedcodebtn').popover( </ul> <ul class="list-unstyled col-sm-3 col-xs-12"> <li>{{ moderator_editor(['lectures',lecture.id,'comment'], lecture.comment) }}</li> + {% for chapter in chapters %} + <li><span class="glyphicon glyphicon-play"></span> <a href="{{url_for('lecture', course=lecture.course.handle, id=lecture.id, t=chapter.time)}}">{{chapter.text}}</a></li> + {% endfor %} {% if ismod() %} <li>{{ moderator_editor(['lectures',lecture.id,'internal'], lecture.internal) }}</li> <li>Sichtbar: {{ moderator_checkbox(['lectures',lecture.id,'visible'], lecture.visible) }}</li> -- GitLab