diff --git a/db_schema.sql b/db_schema.sql index f5e1fbf63a42173719aaa78d6c9d1106dd73e580..b0c5c1fb89e7483d133aad71ebe40184dc3209a9 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -84,19 +84,19 @@ CREATE TABLE IF NOT EXISTS `lectures_data` ( `visible` INTEGER NOT NULL DEFAULT '1', `timed_release` datetime DEFAULT NULL, `use_timed_release` INTEGER NOT NULL DEFAULT '0', - `drehplan` varchar(10) NOT NULL, + `drehplan` varchar(10) NOT NULL DEFAULT '', `deleted` INTEGER NOT NULL DEFAULT '0', - `title` text NOT NULL, - `comment` text NOT NULL, - `internal` text NOT NULL, - `speaker` text NOT NULL, - `place` text NOT NULL, + `title` text NOT NULL DEFAULT '', + `comment` text NOT NULL DEFAULT '', + `internal` text NOT NULL DEFAULT '', + `speaker` text NOT NULL DEFAULT '', + `place` text NOT NULL DEFAULT '', `time` datetime NOT NULL, `duration` INTEGER NOT NULL DEFAULT '90', `time_created` datetime NOT NULL, `time_updated` datetime NOT NULL, - `jumplist` text NOT NULL, - `titlefile` varchar(255) NOT NULL + `jumplist` text NOT NULL DEFAULT '', + `titlefile` varchar(255) NOT NULL DEFAULT '' ); CREATE TABLE IF NOT EXISTS `places` ( `place` varchar(20) NOT NULL PRIMARY KEY, diff --git a/server.py b/server.py index db58e4ae57d7e1f20768a99f37d3ef4e9113dd3f..5b31facd94a598b502a7abfa6c525181b29d578b 100644 --- a/server.py +++ b/server.py @@ -257,13 +257,20 @@ def logout(): tabs = { 'courses': ('courses_data', 'id', ['visible', 'listed', 'title', 'short', 'handle', 'organizer', 'subject', 'semester', 'downloadable', - 'internal', 'responsible','deleted']), + 'internal', 'responsible','deleted'], + ['created_by', 'time_created', 'time_updated']), 'lectures': ('lectures_data', 'id', ['visible', 'title', 'comment', - 'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted']), - 'videos': ('videos_data', 'id', ['visible','deleted']), - 'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']), - 'announcements': ('announcements', 'id', ['text', 'level', 'visible', 'deleted', 'time_publish', 'time_expire']), - 'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted']) + 'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted'], + ['course_id', 'time_created', 'time_updated']), + 'videos': ('videos_data', 'id', ['visible','deleted'], + ['created_by', 'time_created', 'time_updated']), + 'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted'], + ['created_by', 'time_created', 'time_updated']), + 'announcements': ('announcements', 'id', ['text', 'level', 'visible', + 'deleted', 'time_publish', 'time_expire'], + ['created_by', 'time_created', 'time_updated']), + 'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'], + ['created_by', 'time_created', 'time_updated']) } @app.route('/edit', methods=['GET', 'POST']) @@ -297,15 +304,21 @@ def edit(prefix='', ignore=[]): @mod_required def create(table): assert table in tabs - columns = ['created_by', 'time_created', 'time_updated'] - values = [session['user']['dbid'], datetime.now(), datetime.now()] + defaults = {'created_by': session['user']['dbid'], 'time_created': datetime.now(), 'time_updated': datetime.now()} + columns = [] + values = [] + for column, val in defaults.items(): + if column in tabs[table][3]: + columns.append(column) + values.append(val) args = request.values if request.is_json: args = request.get_json() for column, val in args.items(): if column == 'ref': continue - assert column in tabs[table][2] + assert column in tabs[table][2]+tabs[table][3] + assert column not in defaults columns.append(column) values.append(val) id = modify('INSERT INTO %s (%s) VALUES (%s)'%(tabs[table][0], @@ -314,20 +327,6 @@ def create(table): return redirect(request.values['ref']) return str(id), 200 -@app.route('/newlecture/<courseid>', methods=['GET', 'POST']) -@mod_required -def new_lecture(courseid): - id = modify(''' - INSERT INTO lectures_data - (course_id, visible, drehplan, title, comment, internal, speaker, place, - time, time_created, time_updated, jumplist, titlefile) - VALUES (?, 0, "", "Noch kein Titel", "", "", "", "", ?, ?, ?, "", "") - ''', courseid, datetime.now(), datetime.now(), datetime.now()) - edit(prefix='lectures.'+str(id)+'.', ignore=['ref']) - if 'ref' in request.values: - return redirect(request.values['ref']) - return str(id), 200 - @app.route('/auth') def auth(): # For use with nginx auth_request if 'X-Original-Uri' not in request.headers: diff --git a/templates/course.html b/templates/course.html index 48c70f6fff3c0cd544dc26f55ca45e64d335b590..24b78c76ba176d1862ffc5789b27867dedc75c01 100644 --- a/templates/course.html +++ b/templates/course.html @@ -38,7 +38,7 @@ </div> <div class="panel panel-default"> <div class="panel-heading"> - <h1 class="panel-title">Videos{% if ismod() %} <a class="btn btn-default" style="margin-right: 5px;" href="{{ url_for('new_lecture', courseid=course.id, ref=request.url) }}">Neuer Termin</a><a class="btn btn-default" style="margin-right: 5px;" href="{{url_for('import_from', id=course['id'])}}">Campus Import</a>{% endif %} <a class="fa fa-rss-square pull-right" aria-hidden="true" href="{{url_for('feed', handle=course.handle)}}"></a> </h1> + <h1 class="panel-title">Videos{% if ismod() %} <a class="btn btn-default" style="margin-right: 5px;" href="{{ url_for('create', table='lectures', time=datetime.now(), title='Noch kein Title', course_id=course.id, ref=request.url) }}">Neuer Termin</a><a class="btn btn-default" style="margin-right: 5px;" href="{{url_for('import_from', id=course['id'])}}">Campus Import</a>{% endif %} <a class="fa fa-rss-square pull-right" aria-hidden="true" href="{{url_for('feed', handle=course.handle)}}"></a> </h1> </div> <ul class="list-group lectureslist"> {% for l in lectures %} diff --git a/templates/import_campus.html b/templates/import_campus.html index 3240907f378a18c060308c0c9222f19ccd715e67..3a5819f6ec729836a183d4d439597b60f3d0854a 100644 --- a/templates/import_campus.html +++ b/templates/import_campus.html @@ -90,7 +90,7 @@ {{ valuedeletebtn(['lectures',i.id,'deleted']) }} {% endif%} {% if (i.type == 'import') %} - <button class="btn btn-default newlecture" onclick="moderatorinterface.gethttp('{{ url_for('new_lecture', courseid=course.id, time=i.time, title=i.title, place=i.place) }}')">anlegen</a> + <button class="btn btn-default newlecture" onclick="moderatorinterface.gethttp('{{ url_for('create', table='lecture', course_id=course.id, time=i.time, title=i.title, place=i.place) }}')">anlegen</a> {% endif%} </span> </span>