Commit d891c978 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Model: Fix possible data removing durring save.

Showing with 16 additions and 7 deletions
+16 -7
...@@ -57,12 +57,14 @@ class FrictionList(PamhyrModelList): ...@@ -57,12 +57,14 @@ class FrictionList(PamhyrModelList):
return new return new
def _db_save(self, execute, data=None): def _db_save(self, execute, data=None):
frictions = self.lst
reach = data["reach"] reach = data["reach"]
execute(f"DELETE FROM friction WHERE reach = {reach.id}") execute(f"DELETE FROM friction WHERE reach = {reach.id}")
ok = True ok = True
ind = 0 ind = 0
for friction in self._lst: for friction in frictions:
data["ind"] = ind data["ind"] = ind
ok &= friction._db_save(execute, data=data) ok &= friction._db_save(execute, data=data)
ind += 1 ind += 1
......
...@@ -173,11 +173,13 @@ class ProfileXYZ(Profile, SQLSubModel): ...@@ -173,11 +173,13 @@ class ProfileXYZ(Profile, SQLSubModel):
) )
execute(sql) execute(sql)
points = self.points
data["profile"] = self data["profile"] = self
execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}") execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}")
ind = 0 ind = 0
for point in self.points: for point in points:
data["ind"] = ind data["ind"] = ind
ok &= point._db_save(execute, data) ok &= point._db_save(execute, data)
ind += 1 ind += 1
......
...@@ -71,15 +71,16 @@ class Reach(SQLSubModel): ...@@ -71,15 +71,16 @@ class Reach(SQLSubModel):
return new return new
def _db_save(self, execute, data=None): def _db_save(self, execute, data=None):
profiles = self.profiles
# Delete old data # Delete old data
execute(f"DELETE FROM geometry_profileXYZ WHERE reach = {self.id}") execute(f"DELETE FROM geometry_profileXYZ WHERE reach = {self.id}")
# execute(f"DELETE FROM geometry_pointXYZ")
if data is None: if data is None:
data = {} data = {}
ind = 0 ind = 0
for profile in self.profiles: for profile in profiles:
data["ind"] = ind data["ind"] = ind
profile._db_save(execute, data) profile._db_save(execute, data)
ind += 1 ind += 1
......
...@@ -55,14 +55,18 @@ class InitialConditionsDict(PamhyrModelDict): ...@@ -55,14 +55,18 @@ class InitialConditionsDict(PamhyrModelDict):
if data is None: if data is None:
data = {} data = {}
execute("DELETE FROM initial_conditions") ics = self._dict
for reach in ics:
for reach in self._dict:
data["reach"] = reach data["reach"] = reach
v = self._dict[reach] v = self._dict[reach]
if isinstance(v, types.GeneratorType): if isinstance(v, types.GeneratorType):
self._dict[reach] = list(v)[0] self._dict[reach] = list(v)[0]
execute(
"DELETE FROM initial_conditions " +
f"WHERE reach = '{reach.id}'"
)
ok &= self._dict[reach]._db_save(execute, data) ok &= self._dict[reach]._db_save(execute, data)
return ok return ok
......
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