better multi's mandatory support

This commit is contained in:
Emmanuel Garette 2019-05-09 20:16:57 +02:00
parent 4ec269f2b9
commit 64fc2df3d2
1 changed files with 14 additions and 8 deletions

View File

@ -157,12 +157,12 @@ class _Value:
for index in range(leadership_len):
value = self.config.get_value(key,
index)
self._display_warnings(key, value, option['type'], option['name'], withwarning)
self._display_warnings(key, value, option['type'], key, withwarning)
values.append(value)
ret[key] = values
else:
value = self.config.get_value(key)
self._display_warnings(key, value, option['type'], option['name'], withwarning)
self._display_warnings(key, value, option['type'], key, withwarning)
ret[key] = value
if schema.get('type') == 'array':
leadership_len = len(value)
@ -248,12 +248,12 @@ class TiramisuOptionValue(_Value):
if self.index is None:
raise APIError(_('index must be set with the follower option "{}"').format(self.path))
value = self.config.get_value(self.path, self.index)
self._display_warnings(self.path, value, self.schema['type'], self.schema['name'])
self._display_warnings(self.path, value, self.schema['type'], self.path)
return value
if self.index is not None:
raise APIError(_('index must only be set with a follower option, not for "{}"').format(self.path))
value = self.config.get_value(self.path)
self._display_warnings(self.path, value, self.schema['type'], self.schema['name'])
self._display_warnings(self.path, value, self.schema['type'], self.path)
return value
def list(self):
@ -294,7 +294,7 @@ class TiramisuOptionValue(_Value):
value,
remote,
leader_old_value)
self._display_warnings(self.path, value, type_, self.schema['name'])
self._display_warnings(self.path, value, type_, self.path)
def reset(self):
self.config.delete_value(self.path,
@ -525,8 +525,8 @@ class ContextValue(_Value):
def mandatory(self):
for key, value in self.dict().items():
if self.config.isfollower(key):
# FIXME test with index
if self.model.get(key, {}).get(None, {}).get('required'):
# FIXME test with index
if self.config.get_schema(key).get('isSubMulti'):
for val in value:
if not val or None in val or '' in val:
@ -534,8 +534,12 @@ class ContextValue(_Value):
break
elif None in value or '' in value:
yield key
elif value is None or \
(self.config.get_schema(key).get('isMulti') and (not value or None in value or '' in value)):
elif self.config.get_schema(key).get('isMulti'):
if self.model.get(key, {}).get('required') and (None in value or '' in value):
yield key
if self.model.get(key, {}).get('needs_len') and not value:
yield key
elif self.model.get(key, {}).get('required') and value is None:
yield key
@ -971,6 +975,8 @@ class Config:
if value is None:
match = True
else:
if isinstance(value, int):
value = str(value)
match = self.form[path]['pattern'].search(value)
if not remote:
if not match: