Commit ac621026 authored by Julian Rother's avatar Julian Rother
Browse files

Improved new-endpoint so it can create rows with NOT NULL-columns

parent c54c4ac8
......@@ -275,11 +275,9 @@ def edit(prefix='', ignore=[]):
if not prefix and 'prefix' in request.args:
prefix = request.args['prefix']
modify('BEGIN')
changes = request.values.items()
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
......@@ -299,9 +297,19 @@ def edit(prefix='', ignore=[]):
@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)+'.')
columns = ['created_by', 'time_created', 'time_updated']
values = [session['user']['dbid'], datetime.now(), datetime.now()]
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]
columns.append(column)
values.append(val)
id = modify('INSERT INTO %s (%s) VALUES (%s)'%(tabs[table][0],
','.join(columns), ','.join(['?']*len(values))), *values)
if 'ref' in request.values:
return redirect(request.values['ref'])
return str(id), 200
......
Supports Markdown
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