Closed GoogleCodeExporter closed 9 years ago
I've been using a patch to get around that too, the problem seems to be that
self._value is a string or list of strings after a validation failure, even if
it
would be another type in a "fresh" fieldset. I'm not convinced I have a proper
or
complete fix, but my patch is below:
Index: fields.py
===================================================================
--- fields.py (revision 714)
+++ fields.py (working copy)
@@ -457,7 +457,7 @@
return FieldRenderer._serialized_value(self)
def _is_checked(self, choice_value):
- return self._value == choice_value
+ return self._value == choice_value or self._value == str(choice_value)
def render(self, options, **kwargs):
self.radios = []
@@ -480,7 +480,7 @@
return FieldRenderer._serialized_value(self)
def _is_checked(self, choice_value):
- return choice_value in self._value
+ return str(choice_value) in self._value or choice_value in self._value
class SelectFieldRenderer(FieldRenderer):
Original comment by andr...@gmail.com
on 3 Mar 2009 at 10:15
Original comment by jbel...@gmail.com
on 3 Mar 2009 at 10:22
It seems to work well for CheckBoxSet, but I can't find a similar approach to
get
SelectFieldRenderer working too.
I'm new at python, so help would be very appreciated... ;-)
Original comment by robarago@gmail.com
on 4 Mar 2009 at 2:25
Although it seems a bit sloppy, this should work:
--- fields.py.orig 2009-03-04 02:26:30.000000000 +0100
+++ fields.py 2009-03-04 03:37:33.000000000 +0100
@@ -457,7 +457,7 @@
return FieldRenderer._serialized_value(self)
def _is_checked(self, choice_value):
- return self._value == choice_value
+ return self._value == choice_value or self._value == str(choice_value)
def render(self, options, **kwargs):
self.radios = []
@@ -480,7 +480,7 @@
return FieldRenderer._serialized_value(self)
def _is_checked(self, choice_value):
- return choice_value in self._value
+ return str(choice_value) in self._value or choice_value in self._value
class SelectFieldRenderer(FieldRenderer):
@@ -493,7 +493,10 @@
return FieldRenderer._serialized_value(self)
def render(self, options, **kwargs):
- selected = kwargs.get('selected', None) or self._value
+ selected = []
+ if options:
+ t = type(options[0][1])
+ selected = kwargs.get('selected', None) or [t(i) for i in
self._value]
return h.select(self.name, h.options_for_select(options, selected=selected),
**kwargs)
Any better idea?
Original comment by robarago@gmail.com
on 4 Mar 2009 at 2:44
fixed in r716. Thanks for the help tracking this down!
Original comment by jbel...@gmail.com
on 4 Mar 2009 at 2:12
Original comment by jbel...@gmail.com
on 4 Mar 2009 at 2:13
Original issue reported on code.google.com by
robarago@gmail.com
on 2 Mar 2009 at 9:27