1 | diff -r 3f91fa6ba472 db/models/fields/__init__.py
|
---|
2 | --- a/db/models/fields/__init__.py Wed Jul 07 17:22:15 2010 -0400
|
---|
3 | +++ b/db/models/fields/__init__.py Wed Oct 06 12:41:37 2010 -0400
|
---|
4 | @@ -168,15 +168,25 @@
|
---|
5 | # Skip validation for non-editable fields.
|
---|
6 | return
|
---|
7 | if self._choices and value:
|
---|
8 | + choices_dict = dict()
|
---|
9 | for option_key, option_value in self.choices:
|
---|
10 | if isinstance(option_value, (list, tuple)):
|
---|
11 | # This is an optgroup, so look inside the group for options.
|
---|
12 | for optgroup_key, optgroup_value in option_value:
|
---|
13 | - if value == optgroup_key:
|
---|
14 | - return
|
---|
15 | - elif value == option_key:
|
---|
16 | - return
|
---|
17 | - raise exceptions.ValidationError(self.error_messages['invalid_choice'] % value)
|
---|
18 | + choices_dict.update({optgroup_key : optgroup_value})
|
---|
19 | + else:
|
---|
20 | + choices_dict.update({option_key : option_value})
|
---|
21 | + _value = value
|
---|
22 | + if not isinstance(value, (list, tuple)):
|
---|
23 | + _value = [value]
|
---|
24 | + invalid_v = []
|
---|
25 | + for v in _value:
|
---|
26 | + if not choices_dict.has_key(v):
|
---|
27 | + invalid_v.append(v)
|
---|
28 | + if invalid_v.__len__() > 0:
|
---|
29 | + raise exceptions.ValidationError(self.error_messages['invalid_choice'] % invalid_v)
|
---|
30 | + else:
|
---|
31 | + return
|
---|
32 |
|
---|
33 | if value is None and not self.null:
|
---|
34 | raise exceptions.ValidationError(self.error_messages['null'])
|
---|