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