Re: ObjectWrapper subclasses always callable

PJ Eby <pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]> Wed, 23 May 2012 15:32:12 -0400
Newsgroups gmane.comp.python.peak
Message-ID <CALeMXf4upk9hdoVP867iTQpcsm4UqAeeSgCAbVvceQm5_b6gxQ@mail.gmail.com>
--===============1817863482==
Content-Type: multipart/alternative; boundary=bcaec51b9bf523328004c0b931c5

--bcaec51b9bf523328004c0b931c5
Content-Type: text/plain; charset=ISO-8859-1

On Wed, May 23, 2012 at 2:18 PM, Marcin Tustin <[email protected]>wrote:

> I'm wrapping an object to pass to a django form, to alter how it is
> displayed in the form. Django's form rendering code has the code:
> if callable(data):
>     data = data()
>
> This breaks when passed the proxy object, because the underlying object is
> not callable.
>

Ah.  In that case, define a __call__ on your wrapper class that returns
self.  ;-)

--bcaec51b9bf523328004c0b931c5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div class=3D"gmail_quote">On Wed, May 23, 2012 at 2:18 PM, Marcin Tustin <=
span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_=
blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">
I&#39;m wrapping an object to pass to a django form, to alter how it is dis=
played in the form. Django&#39;s form rendering code has the code:<div>if c=
allable(data):</div><div>=A0 =A0 data =3D data()<br><br>This breaks when pa=
ssed the proxy object, because the underlying object is not callable.</div>
</blockquote><div><br>Ah.=A0 In that case, define a __call__ on your wrappe=
r class that returns self.=A0 ;-)<br></div></div><br>

--bcaec51b9bf523328004c0b931c5--

--===============1817863482==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
PEAK mailing list
[email protected]
http://www.eby-sarna.com/mailman/listinfo/peak
--===============1817863482==--