Commit c0647a0d authored by Julian Rother's avatar Julian Rother

Wrote a common create endpoint to replace all new_* ones

parent 9c24a5ba
......@@ -248,25 +248,28 @@ def logout():
session.pop('user')
return redirect(request.values.get('ref', url_for('index')))
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']),
'videos': ('videos_data', 'id', ['visible','deleted']),
'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']),
'announcements': ('announcements', 'id', ['text', 'internal', 'level', 'visible', 'deleted'])
}
@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']),
'videos': ('videos_data', 'id', ['visible','deleted']),
'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']),
'announcements': ('announcements', 'id', ['text', 'internal', 'level', 'visible', 'deleted'])
}
ignore.append('ref')
modify('BEGIN')
if request.is_json:
changes = request.get_json().items()
else:
changes = request.args.items()
created = {}
for key, val in changes:
if key in ignore:
continue
......@@ -277,8 +280,21 @@ def edit(prefix="", ignore=[]):
modify('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'])
modify('UPDATE %s SET %s = ?, time_updated = ? WHERE %s = ?'%(tabs[table][0], column, tabs[table][1]), val, datetime.now(), id)
modify('COMMIT')
if 'ref' in request.values:
return redirect(request.values['ref'])
return "OK", 200
@app.route('/new/<table>', methods=['GET', 'POST'])
@mod_required
def create(table):
assert table in tabs
id = modify('INSERT INTO %s (created_by, time_created, time_updated) VALUES (?, ?, ?)'%tabs[table][0],
session['user']['dbid'], datetime.now(), datetime.now())
edit(prefix=table+'.'+str(id)+'.')
if 'ref' in request.values:
return redirect(request.values['ref'])
return str(id), 200
@app.route('/newcourse', methods=['GET', 'POST'])
@mod_required
def new_course():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment