crud fix
This commit is contained in:
parent
96f36193cd
commit
9f236bfd4a
|
|
@ -21,9 +21,10 @@ class Crud_DB:
|
||||||
@db.connection_context()
|
@db.connection_context()
|
||||||
@db.atomic()
|
@db.atomic()
|
||||||
def commit(self, data, deleted_rows=None):
|
def commit(self, data, deleted_rows=None):
|
||||||
deleted = self.table_model.delete().where(self.table_pk << deleted_rows).execute()
|
if deleted_rows is not None:
|
||||||
if deleted != len(deleted_rows):
|
deleted = self.table_model.delete().where(self.table_pk << deleted_rows).execute()
|
||||||
raise AssertionError(f"deleted {deleted} rows instead of the expected {len(deleted_rows)}")
|
if deleted != len(deleted_rows):
|
||||||
|
raise AssertionError(f"deleted {deleted} rows instead of the expected {len(deleted_rows)}")
|
||||||
# SQLITE DOES NOT SUPPORT UPDATE, ONLY REPLACE
|
# SQLITE DOES NOT SUPPORT UPDATE, ONLY REPLACE
|
||||||
complete_data = []
|
complete_data = []
|
||||||
for rn, row in enumerate(data):
|
for rn, row in enumerate(data):
|
||||||
|
|
|
||||||
|
|
@ -443,7 +443,7 @@ class Crud(Widget):
|
||||||
# delete rows with primary key changed to avoid duplication if primary key in selected fields and editable
|
# delete rows with primary key changed to avoid duplication if primary key in selected fields and editable
|
||||||
if self.db.table_pk.name in self.select and not (self.readonly is None or self.readonly is True or (self.readonly is not False and self.db.table_pk.name in self.readonly)):
|
if self.db.table_pk.name in self.select and not (self.readonly is None or self.readonly is True or (self.readonly is not False and self.db.table_pk.name in self.readonly)):
|
||||||
for rn, r in enumerate(data):
|
for rn, r in enumerate(data):
|
||||||
if r[self.db.table_pk.name] != self.data_index[rn]:
|
if self.data_index[rn] is not None and r[self.db.table_pk.name] != self.data_index[rn]:
|
||||||
self.deleted_rows.add(self.data_index[rn])
|
self.deleted_rows.add(self.data_index[rn])
|
||||||
# INDEX DATA WITH PK
|
# INDEX DATA WITH PK
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user