From df86d17b1cfa2a1990f16d3155408a8a5881aafc Mon Sep 17 00:00:00 2001 From: Julian Rother <julianr@fsmpi.rwth-aachen.de> Date: Tue, 6 Sep 2016 20:05:02 +0200 Subject: [PATCH] Added backend support for chapter marks --- db_schema.sql | 12 ++++++++++++ server.py | 21 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/db_schema.sql b/db_schema.sql index 58cef7e..921b1da 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -28,6 +28,18 @@ CREATE TABLE IF NOT EXISTS `changelog` ( `value_new` text NOT NULL, `executed` text NOT NULL ); +CREATE TABLE IF NOT EXISTS `chapters` ( +`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `lecture_id` INTEGER NOT NULL, + `time` INTEGER NOT NULL, + `text` text NOT NULL, + `visible` INTEGER NOT NULL DEFAULT 0, + `deleted` INTEGER NOT NULL DEFAULT 0, + `time_created` datetime NOT NULL, + `time_updated` datetime NOT NULL, + `created_by` INTEGER DEFAULT NULL, + `submitted_by` varchar(32) DEFAULT NULL +); CREATE TABLE IF NOT EXISTS `courses_data` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `visible` INTEGER NOT NULL, diff --git a/server.py b/server.py index 947b896..08ba757 100755 --- a/server.py +++ b/server.py @@ -176,7 +176,8 @@ def lecture(id): courses = query('SELECT * FROM courses WHERE id = ? AND (? OR (visible AND listed))', lectures[0]['course_id'], ismod()) if not courses: return render_endpoint('course', 'Diese Veranstaltung existiert nicht!'), 404 - return render_template('lecture.html', course=courses[0], lecture=lectures[0], videos=videos) + chapters = query('SELECT * FROM chapters WHERE lecture_id = ? AND NOT deleted AND (? OR visible) ORDER BY time ASC', id, ismod()) + return render_template('lecture.html', course=courses[0], lecture=lectures[0], videos=videos, chapters=chapters) @app.route('/search') def search(): @@ -225,7 +226,8 @@ def edit(prefix="", ignore=[]): 'lectures': ('lectures_data', 'id', ['visible', 'title', 'comment', 'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted']), 'site_texts': ('site_texts', 'key', ['value']), - 'videos': ('videos_data', 'id', ['visible','deleted']) + 'videos': ('videos_data', 'id', ['visible','deleted']), + 'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']) } query('BEGIN') if request.is_json: @@ -388,5 +390,20 @@ def changelog(): def files(filename): return redirect(config['VIDEOPREFIX']+'/'+filename) +@app.route('/newchapter/<int:lectureid>', methods=['POST', 'GET']) +def suggest_chapter(lectureid): + time = request.values['time'] + text = request.values['text'] + assert(time and text) + time = int(time) + submitter = None + if not ismod(): + submitter = request.environ['REMOTE_ADDR'] + id = query('INSERT INTO chapters (lecture_id, time, text, time_created, time_updated, created_by, submitted_by) VALUES (?, ?, ?, ?, ?, ?, ?)', + lectureid, time, text, datetime.now(), datetime.now(), session.get('user', {'dbid':None})['dbid'], submitter) + if 'ref' in request.values: + return redirect(request.values['ref']) + return 'OK', 200 + import feeds import importer -- GitLab