mirror of https://gitlab.com/pamhyr/pamhyr2
Model: Fix possible data removing durring save.
parent
51858597cd
commit
d891c9783d
|
|
@ -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):
|
||||||
)
|
)
|
||||||
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):
|
||||||
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):
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue