fix error message when the value isn't in the choices list
This commit is contained in:
parent
700d77596a
commit
85100e4c3a
1 changed files with 4 additions and 3 deletions
|
|
@ -92,7 +92,7 @@ class BaseBackend(object):
|
|||
self.is_masked = is_masked
|
||||
self.regexp = regexp
|
||||
self.description = description
|
||||
self.choices=None
|
||||
self.choices = choices
|
||||
|
||||
class ConfigError(Exception): pass
|
||||
|
||||
|
|
@ -132,12 +132,13 @@ class BaseBackend(object):
|
|||
elif isinstance(field.default, float) and not isinstance(value, float):
|
||||
value = float(value)
|
||||
|
||||
print value, field.choices
|
||||
if field.choices:
|
||||
if (isinstance(field.choices, (tuple,list)) and not value in field.choices) or \
|
||||
(isinstance(field.choices, dict) and not value in field.choices.iterkeys()):
|
||||
raise BaseBackend.ConfigError('Value of "%s" might be in this list: %s' %
|
||||
raise BaseBackend.ConfigError('Value of "%s" might be in this list: %s' % (name,
|
||||
', '.join([s for s in (field.choices.iterkeys() if isinstance(field.choices, dict)
|
||||
else field.choices)]))
|
||||
else field.choices)])))
|
||||
self.config[name] = value
|
||||
self.storage = BackendStorage(self.name, storage)
|
||||
self.storage.load(self.STORAGE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue