From 260cd77d550b0f7f699a9d427eb5effb641a0f3c Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 16 Jan 2019 17:45:44 +0100 Subject: [PATCH] add config.value.mandatory() --- tiramisu_json_api/api.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tiramisu_json_api/api.py b/tiramisu_json_api/api.py index df44d37..549fdac 100644 --- a/tiramisu_json_api/api.py +++ b/tiramisu_json_api/api.py @@ -83,7 +83,7 @@ class TiramisuOptionOption: def properties(self) -> List[str]: props = [] - model = self.model[self._path] + model = self.model.get(self._path, {}) if model.get('required'): #FIXME 'empty', 'needs_len' props.append('mandatory') @@ -435,8 +435,7 @@ class ContextValue(_Value): self.form = form first = next(iter(schema.keys())) self.path = first.rsplit('.', 1)[0] - schema = {'properties': schema} - self.schema = schema + self.schema = {'properties': schema} self.temp = temp def __call__(self) -> TiramisuOptionValue: @@ -448,6 +447,14 @@ class ContextValue(_Value): path, index) + def mandatory(self): + # config.value.mandatory() + for key, value in self.dict().items(): + if self.model.get(key, {}).get('required') and \ + value is None or \ + (self.schema.get('isMulti') and (None in value or '' in value)): + yield key + class Config: # config