From 1d995ecf56bef862bdab573dc713454f7bf04d32 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 16 Jan 2019 09:29:01 +0100 Subject: [PATCH] add owner method --- tiramisu_json_api/api.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tiramisu_json_api/api.py b/tiramisu_json_api/api.py index 0440f26..240c8fb 100644 --- a/tiramisu_json_api/api.py +++ b/tiramisu_json_api/api.py @@ -186,6 +186,33 @@ class _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): # config.option(path).value def __init__(self, @@ -198,8 +225,6 @@ class TiramisuOptionValue(_Value): index: int) -> None: self.config = config self.schema = schema - if schema.get('properties') != None: - raise Exception('pouet') self.model = model self.form = form self.temp = temp @@ -328,6 +353,14 @@ class TiramisuOption: self.temp, self.path, 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 self.index != None: raise NotImplementedError() @@ -487,7 +520,7 @@ class Config: index: Optional[int], remote: bool) -> None: schema = self.get_schema(path) - value = schema['value']; + value = schema.get('value'); if value is None and schema.get('isMulti', False): value = [] self.updates_value('delete',