mirror of https://gitlab.com/pamhyr/pamhyr2
Pamhyr2: Create new generic methode '_data_traversal' for scenario duplicattion.
parent
591cd8950c
commit
8173eb8de9
|
|
@ -502,3 +502,18 @@ class Study(SQLModel):
|
||||||
self.status.set_as_read_only()
|
self.status.set_as_read_only()
|
||||||
else:
|
else:
|
||||||
self.status.set_as_editable()
|
self.status.set_as_editable()
|
||||||
|
|
||||||
|
def duplicate_current_scenario(self):
|
||||||
|
source = self.status.scenario_id
|
||||||
|
new = self.scenarios.new(
|
||||||
|
self.status.scenario.parent
|
||||||
|
)
|
||||||
|
|
||||||
|
self.river._data_traversal(
|
||||||
|
predicate=lambda obj: obj._owner_scenario == source,
|
||||||
|
execute=lambda obj: obj.set_owner_scenario(),
|
||||||
|
data={}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.status.set_as_editable()
|
||||||
|
return new
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ class SQLSubModel(PamhyrID):
|
||||||
self._owner_scenario = self._status.scenario_id
|
self._owner_scenario = self._status.scenario_id
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def set_owner_scenario_if(self, predicate):
|
def set_owner_scenario(self):
|
||||||
"""Set study status the object owner_scenario to current
|
"""Set study status the object owner_scenario to current
|
||||||
scenario if predicate(scenario_id) is true
|
scenario if predicate(scenario_id) is true
|
||||||
|
|
||||||
|
|
@ -215,7 +215,6 @@ class SQLSubModel(PamhyrID):
|
||||||
if self._status is None:
|
if self._status is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if predicate(self._owner_scenario):
|
|
||||||
self._owner_scenario = self._status.scenario_id
|
self._owner_scenario = self._status.scenario_id
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,20 +82,27 @@ class PamhyrModelDict(SQLSubModel):
|
||||||
self.set(key, new)
|
self.set(key, new)
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def rec_set_owner_scenario_if(self, predicate):
|
def _data_traversal(self,
|
||||||
"""Set study status the object owner_scenario to current
|
predicate=lambda obj, data: True,
|
||||||
scenario if predicate(scenario_id) is true
|
modifier=lambda obj, data: None,
|
||||||
|
data={}):
|
||||||
|
"""Traversal data and execute modifier fonction if predicate
|
||||||
|
true
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
predicate: Function predicate on owner_scenario id
|
predicate: Function predicate, take current obj and data as input
|
||||||
|
modifier: Function modifier, take current obj and data as input
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Nothing
|
Nothing
|
||||||
"""
|
|
||||||
self.set_owner_scenario_if(predicate)
|
|
||||||
|
|
||||||
for k in self._lst:
|
"""
|
||||||
self._dict[key].set_owner_scenario_if(predicate)
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
|
for key in self._lst:
|
||||||
|
self._dict[key]\
|
||||||
|
._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
def new(self, key):
|
def new(self, key):
|
||||||
raise NotImplementedMethodeError(self, self.new)
|
raise NotImplementedMethodeError(self, self.new)
|
||||||
|
|
|
||||||
|
|
@ -85,20 +85,26 @@ class PamhyrModelList(SQLSubModel):
|
||||||
if self._status is not None:
|
if self._status is not None:
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def rec_set_owner_scenario_if(self, predicate):
|
def _data_traversal(self,
|
||||||
"""Set study status the object owner_scenario to current
|
predicate=lambda obj, data: True,
|
||||||
scenario if predicate(scenario_id) is true
|
modifier=lambda obj, data: None,
|
||||||
|
data={}):
|
||||||
|
"""Traversal data and execute modifier fonction if predicate
|
||||||
|
true
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
predicate: Function predicate on owner_scenario id
|
predicate: Function predicate, take current obj and data as input
|
||||||
|
modifier: Function modifier, take current obj and data as input
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.set_owner_scenario_if(predicate)
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
for el in self._lst:
|
for el in self._lst:
|
||||||
el.set_owner_scenario_if(predicate)
|
el._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
"""Create new elements and add it to list
|
"""Create new elements and add it to list
|
||||||
|
|
|
||||||
|
|
@ -90,20 +90,26 @@ class PamhyrModelList(SQLSubModel):
|
||||||
if self._status is not None:
|
if self._status is not None:
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def rec_set_owner_scenario_if(self, predicate):
|
def _data_traversal(self,
|
||||||
"""Set study status the object owner_scenario to current
|
predicate=lambda obj, data: True,
|
||||||
scenario if predicate(scenario_id) is true
|
modifier=lambda obj, data: None,
|
||||||
|
data={}):
|
||||||
|
"""Traversal data and execute modifier fonction if predicate
|
||||||
|
true
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
predicate: Function predicate on owner_scenario id
|
predicate: Function predicate, take current obj and data as input
|
||||||
|
modifier: Function modifier, take current obj and data as input
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.set_owner_scenario_if(predicate)
|
if predicate(self, data):
|
||||||
|
modifier(self, data)
|
||||||
|
|
||||||
for el in self._lst:
|
for el in self._lst:
|
||||||
el.set_owner_scenario_if(predicate)
|
el._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
"""Create new elements and add it to list
|
"""Create new elements and add it to list
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue