Something went wrong on our end
Select Git revision
chapters.py
-
Andreas Valder authoredAndreas Valder authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
chapters.py 1.39 KiB
from server import *
@app.route('/internal/newchapter/<int:lectureid>', methods=['POST', 'GET'])
def suggest_chapter(lectureid):
time = request.values['time']
text = request.values['text']
assert(time and text)
try:
x = datetime.strptime(time,'%H:%M:%S')
time= timedelta(hours=x.hour,minutes=x.minute,seconds=x.second).total_seconds()
time = int(time)
except ValueError:
flash('Falsches Zeitformat, "%H:%M:%S" wird erwartet. Z.B. "01:39:42" für eine Kapitel bei Stunde 1, Minute 39, Sekunde 42')
submitter = None
if not ismod():
submitter = request.environ['REMOTE_ADDR']
id = modify('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
@app.route('/internal/chapters/<int:lectureid>')
def chapters(lectureid):
chapters = query("SELECT * FROM chapters WHERE lecture_id = ? AND NOT deleted AND (visible OR ?) ORDER BY time DESC", lectureid, ismod())
if not chapters:
return 'No chapters found', 404
last = None
for c in chapters:
c['start'] = c['time']
c['end'] = last['start'] if last else 9999
last = c
return Response(render_template('chapters.srt',chapters=chapters), 200, {'Content-Type':'text/vtt'})