mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Model: Add a Pamhyr List Abstract implementation and use it for
Stricklers and friction.
This commit is contained in:
1 parent
0a968e2184
commit
89b9fd21ff
5 files changed
+141
-119
No files matched your search
@@ -22,25 +22,17 @@ from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.DB import SQLSubModel
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
|
||||
from Model.Friction.Friction import Friction
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
class FrictionList(SQLSubModel):
|
||||
class FrictionList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
Friction
|
||||
]
|
||||
|
||||
def __init__(self, status = None):
|
||||
super(FrictionList, self).__init__()
|
||||
|
||||
self._status = status
|
||||
self._frictions = []
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _sql_update_0_0_1(cls, execute, version):
|
||||
execute("ALTER TABLE `section` RENAME TO `friction`")
|
||||
@@ -57,7 +49,7 @@ class FrictionList(SQLSubModel):
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data['status'])
|
||||
|
||||
new._frictions = Friction._sql_load(
|
||||
new._lst = Friction._sql_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
@@ -69,70 +61,19 @@ class FrictionList(SQLSubModel):
|
||||
|
||||
ok = True
|
||||
ind = 0
|
||||
for friction in self._frictions:
|
||||
for friction in self._lst:
|
||||
data["ind"] = ind
|
||||
ok &= friction._sql_save(execute, data = data)
|
||||
ind += 1
|
||||
|
||||
return ok
|
||||
|
||||
def __len__(self):
|
||||
return len(self._frictions)
|
||||
|
||||
@property
|
||||
def frictions(self):
|
||||
return self._frictions.copy()
|
||||
|
||||
def get(self, row):
|
||||
return self._frictions[row]
|
||||
|
||||
def set(self, row, new):
|
||||
self._frictions[row] = new
|
||||
self._status.modified()
|
||||
return self.lst
|
||||
|
||||
def new(self, index):
|
||||
n = Friction(status = self._status)
|
||||
self._frictions.insert(index, n)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def insert(self, index, new):
|
||||
self._frictions.insert(index, new)
|
||||
self._status.modified()
|
||||
|
||||
def delete(self, frictions):
|
||||
for friction in frictions:
|
||||
self._frictions.remove(friction)
|
||||
self._status.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
frictions = list(
|
||||
map(
|
||||
lambda x: x[1],
|
||||
filter(
|
||||
lambda x: x[0] in indexes,
|
||||
enumerate(self._frictions)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.delete(frictions)
|
||||
|
||||
def sort(self, reverse=False, key=None):
|
||||
self._frictions.sort(reverse=reverse, key=key)
|
||||
self._status.modified()
|
||||
|
||||
def move_up(self, index):
|
||||
if index < len(self._frictions):
|
||||
next = index - 1
|
||||
|
||||
l = self._frictions
|
||||
l[index], l[next] = l[next], l[index]
|
||||
self._status.modified()
|
||||
|
||||
def move_down(self, index):
|
||||
if index >= 0:
|
||||
prev = index + 1
|
||||
|
||||
l = self._frictions
|
||||
l[index], l[prev] = l[prev], l[index]
|
||||
self._status.modified()
|
||||
Reference in new issue
Block a user