diff --git a/db_schema.sql b/db_schema.sql index 58cef7e751703571adcf6256fe601f9bb7aa57d0..921b1daa1b871a8d58f2a915e9c1dda83e234714 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 947b896bc68552b8fccb083056436e07a3bc69ab..8c7a23e602f4a09bb972bed64fd84f4bc5ce1cd0 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(): @@ -218,14 +219,15 @@ def logout(): @app.route('/edit', methods=['GET', 'POST']) @mod_required def edit(prefix="", ignore=[]): + # All editable tables are expected to have a 'time_updated' field tabs = { 'courses': ('courses_data', 'id', ['visible', 'listed', 'title', 'short', 'handle', 'organizer', 'subject', 'semester', 'downloadable', 'internal', 'responsible','deleted']), '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: @@ -240,7 +242,7 @@ def edit(prefix="", ignore=[]): assert table in tabs assert column in tabs[table][2] query('INSERT INTO changelog ("table",id_value,id_key,field,value_new,value_old,"when",who,executed) VALUES (?,?,?,?,?,(SELECT %s FROM %s WHERE %s = ?),?,?,1)'%(column,tabs[table][0],tabs[table][1]),table,id,tabs[table][1],column,val,id,datetime.now(),session['user']['givenName']) - query('UPDATE %s SET %s = ? WHERE %s = ?'%(tabs[table][0], column,tabs[table][1]), val, id) + query('UPDATE %s SET %s = ?, time_updated = ? WHERE %s = ?'%(tabs[table][0], column, tabs[table][1]), val, datetime.now(), id) query('COMMIT') return "OK", 200 @@ -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