fix error message when the value isn't in the choices list

This commit is contained in:
Romain Bignon 2010-08-13 11:18:55 +02:00
commit 85100e4c3a

View file

@ -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)