Frictions: Fix none assiciated stricklers at save/load.

setup.py
Pierre-Antoine Rouby 2024-01-17 14:42:20 +01:00
parent e86111bd7a
commit 8b8aff7df1
1 changed files with 19 additions and 3 deletions

View File

@ -77,7 +77,14 @@ class Friction(SQLSubModel):
for row in table:
ind = row[0]
# Get stricklers
if int(row[3]) == -1:
bs = None
else:
bs = next(filter(lambda s: s.id == row[3], stricklers))
if int(row[4]) == -1:
es = None
else:
es = next(filter(lambda s: s.id == row[4], stricklers))
# Create friction
@ -94,6 +101,15 @@ class Friction(SQLSubModel):
def _db_save(self, execute, data=None):
ind = data["ind"]
b_s_id = -1
e_s_id = -1
if self._begin_strickler is not None:
b_s_id = self._begin_strickler.id
if self._end_strickler is not None:
e_s_id = self._end_strickler.id
execute(
"INSERT INTO " +
"friction(ind, begin_kp, end_kp, " +
@ -101,7 +117,7 @@ class Friction(SQLSubModel):
"VALUES (" +
f"{ind}, {self._begin_kp}, {self._end_kp}, " +
f"{self._edge.id}, " +
f"{self._begin_strickler.id}, {self._end_strickler.id}" +
f"{b_s_id}, {e_s_id}" +
")"
)