pombreda / formalchemy

Automatically exported from code.google.com/p/formalchemy
MIT License
0 stars 0 forks source link

default_renderers and subclassing #114

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello

If I add class entries in the fieldset default_renderers mapping
for a given renderer, 

it's not necessarely the one that will be picked if the class overrides
a class that is registered for another renderer.

That's because AbstractField._get_renderer does :

{{{
isinstance(self.type, t)
}}}

It should try first :

{{{
type(self.type) is t
}}}

First, then maybe try parent classes.

(I can't provide a hg patch because your code base uses trailing spaces
so the diff looks ugly ;)

Original issue reported on code.google.com by ziade.ta...@gmail.com on 17 Sep 2009 at 5:19

GoogleCodeExporter commented 9 years ago
here's the diff that works for me:

     def _get_renderer(self):
+        # first, try a perfect type match
+        for t in self.parent.default_renderers:
+            if not isinstance(t, basestring) and type(self.type) is t:
+                return self.parent.default_renderers[t]
+        # next, try a class + subclass match

Original comment by ziade.ta...@gmail.com on 18 Sep 2009 at 9:33

GoogleCodeExporter commented 9 years ago
fixed, thanks

Original comment by gael.pas...@gmail.com on 18 Sep 2009 at 12:58

GoogleCodeExporter commented 9 years ago
Thx :)

Original comment by ziade.ta...@gmail.com on 18 Sep 2009 at 2:05