Skip to content
Snippets Groups Projects
Commit 2a8ab861 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Modify the return dictionary in _get_fields and add some protection.

parent 38aca9dd
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ RECORD_INSERTED = "Record is inserted with id %i."
RECORD_NOT_IN_DB = "The record '%s' doesn't exist in the table %s."
RECORD_UPDATED = "Record %s is updated."
TABLE_NOT_IN_DB = "The table '%s' doesn't exist in the database."
TO_MANY_RECORDS = "To many records !!!"
class DbSvcException(BaseException): pass
......@@ -135,7 +136,7 @@ class DbSvc(BaseSvc):
[(table1, field1), (table1, field2), (table2, field3), ...]
records (ROOT)
A dictionary containing the new / update values for field
List of dictionary containing the new / update values for field
as well as the identifier of the record to be updated (id)
Return a dictionary {fieldName: value, ...}
......@@ -145,21 +146,26 @@ class DbSvc(BaseSvc):
fields = {}
table = arg['tableName']
# protection
if len(arg[ROOT]) > 1:
raise DbSvcException(TO_MANY_RECORDS)
# Remove fields in the record which do not belong to the table.
# The JsonStore send the foreign key and the the pointing field
# when manipulating table with foreign keys. the latter belongs
# to another table.
for record in arg[ROOT]:
for table_field in record:
tablename, fieldname = decode_field(table_field)
if tablename == table:
fields[fieldname.encode('utf8')] = record[table_field]
record = arg[ROOT][0]
for table_field in record:
tablename, fieldname = decode_field(table_field)
if tablename == table:
fields[fieldname.encode('utf8')] = record[table_field]
# Validate field contents
di = self._is_fields_values_valid(table, fields)
if di:
table_id = encode_field(table, 'id')
return {SUCCESS: False, "errors": di, ROOT: {table_id: -1}}
record[table_id] = ""
return {SUCCESS: False, "errors": di, ROOT: record}
return fields
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment