Re: Templates: __html__ method support

2017-09-27 Thread Patryk Zawadzki
W dniu wtorek, 26 września 2017 14:34:29 UTC+2 użytkownik Jonas H napisał: > > Proposal: Support the __html__ method as an alternative/addition to the > __str__ for turning objects into strings in the template layer. > > If this has been discussed before, please point me to it; I couldn't find >

Re: Templates: __html__ method support

2017-09-26 Thread Jonas Haag
> Am 26.09.2017 um 22:50 schrieb Aymeric Augustin > : > > Hello, > > This could be a regression because > https://github.com/django/django/commit/3483682749577b4b5a8141a766489d5b460e30e9 > > > looks like it i

Re: Templates: __html__ method support

2017-09-26 Thread Jonas Haag
> Aymeric Augustin: > >> On 26 Sep 2017, at 22:56, Jonas Haag > > wrote: >> >> Without having had a look at any of the links you’ve posted, this does NOT >> work in Jinja2 the way I suggested: >> >> >>> jinja2.Template('{{foo}}').render({'foo': Money('1', '$')}) >> '$

Re: Templates: __html__ method support

2017-09-26 Thread Aymeric Augustin
And the test case for Django templates is: >>> class Money: ... def __init__(self, amount, currency): ... self.amount = amount ... self.currency = currency ... def __str__(self): ... return 'str %s %s' % (self.currency, self.amount) ... def __html__(self): ...

Re: Templates: __html__ method support

2017-09-26 Thread Aymeric Augustin
> On 26 Sep 2017, at 22:56, Jonas Haag wrote: > > Without having had a look at any of the links you’ve posted, this does NOT > work in Jinja2 the way I suggested: > > >>> jinja2.Template('{{foo}}').render({'foo': Money('1', '$')}) > '$ 1' > > So whatever the changes for better __html__ interop

Re: Templates: __html__ method support

2017-09-26 Thread Jonas Haag
> Aymeric Augustin: > This could be a regression Without having had a look at any of the links you’ve posted, this does NOT work in Jinja2 the way I suggested: >>> jinja2.Template('{{foo}}').render({'foo': Money('1', '$')}) '$ 1' So whatever the changes for better __html__ interoperability wer

Re: Templates: __html__ method support

2017-09-26 Thread Aymeric Augustin
On 26 Sep 2017, at 22:18, Brice Parent wrote: > Only question: Where should it stop? Should there also be a __json__, a > __yaml__ and an __xml__ methods? Hello, __html__ is a fairly well established convention in the Python community, pioneered by Armin Ronacher around 2006 (give or take a c

Re: Templates: __html__ method support

2017-09-26 Thread Aymeric Augustin
Hello, This could be a regression because https://github.com/django/django/commit/3483682749577b4b5a8141a766489d5b460e30e9 looks like it implemented that behavior; unfortunately but didn't include a test for th

Re: Templates: __html__ method support

2017-09-26 Thread Tom Forbes
The problem with something more complex like yaml or json is it's not easy to combine the output. If those methods return a string, as in actual json, it's not easy to do anything with them (like combine them into an array or another object). YAML is also whitespace sensitive. If they return a dict

Re: Templates: __html__ method support

2017-09-26 Thread Jonas Haag
> Collin Anderson: > I think this is a good idea. Django has used __html__ internally for the last > 4 years so it's not something new [0]. I'm surprised this doesn't work > out-of-the box. I too expected this to work already, and I was surprised to find it doesn’t. Hence this thread. (It also

Re: Templates: __html__ method support

2017-09-26 Thread Collin Anderson
I think this is a good idea. Django has used __html__ internally for the last 4 years so it's not something new [0]. I'm surprised this doesn't work out-of-the box. [0] https://code.djangoproject.com/ticket/7261 On Tue, Sep 26, 2017 at 9:26 AM, George-Cristian Bîrzan wrote: > On Tuesday, Septem

Re: Templates: __html__ method support

2017-09-26 Thread George-Cristian Bîrzan
On Tuesday, September 26, 2017 at 3:34:29 PM UTC+3, Jonas H wrote: > > Proposal: Support the __html__ method as an alternative/addition to the > __str__ for turning objects into strings in the template layer. > > Dunder methods' names shouldn't be invented, so a better name is needed. -- You rec

Templates: __html__ method support

2017-09-26 Thread Jonas H
Proposal: Support the __html__ method as an alternative/addition to the __str__ for turning objects into strings in the template layer. If this has been discussed before, please point me to it; I couldn't find anything with the search function. Some custom classes may have, in addition to a __s