add owner method

This commit is contained in:
Emmanuel Garette 2019-01-16 09:29:01 +01:00
parent a91f32401a
commit 1d995ecf56
1 changed files with 36 additions and 3 deletions

View File

@ -186,6 +186,33 @@ class _Value:
return value return value
class TiramisuOptionOwner:
# config.option(path).owner
def __init__(self,
config: 'Config',
schema: Dict,
model: List[Dict],
form: List[Dict],
temp: List[Dict],
path: str,
index: int) -> None:
self.config = config
self.schema = schema
self.model = model
self.form = form
self.temp = temp
self.path = path
self.index = index
def isdefault(self) -> Any:
owner = 'default'
if self.path in self.temp:
owner = self.temp[self.path]['owner']
elif self.path in self.model and 'owner' in self.model[self.path]:
owner = self.model[self.path]['owner']
return owner == 'default'
class TiramisuOptionValue(_Value): class TiramisuOptionValue(_Value):
# config.option(path).value # config.option(path).value
def __init__(self, def __init__(self,
@ -198,8 +225,6 @@ class TiramisuOptionValue(_Value):
index: int) -> None: index: int) -> None:
self.config = config self.config = config
self.schema = schema self.schema = schema
if schema.get('properties') != None:
raise Exception('pouet')
self.model = model self.model = model
self.form = form self.form = form
self.temp = temp self.temp = temp
@ -328,6 +353,14 @@ class TiramisuOption:
self.temp, self.temp,
self.path, self.path,
self.index) self.index)
if subfunc == 'owner':
return TiramisuOptionOwner(self.config,
self.schema,
self.model,
self.form,
self.temp,
self.path,
self.index)
if subfunc == 'property': if subfunc == 'property':
if self.index != None: if self.index != None:
raise NotImplementedError() raise NotImplementedError()
@ -487,7 +520,7 @@ class Config:
index: Optional[int], index: Optional[int],
remote: bool) -> None: remote: bool) -> None:
schema = self.get_schema(path) schema = self.get_schema(path)
value = schema['value']; value = schema.get('value');
if value is None and schema.get('isMulti', False): if value is None and schema.get('isMulti', False):
value = [] value = []
self.updates_value('delete', self.updates_value('delete',