#15791: New feature: callable objects can signal that templates should never 
call
them
-------------------------+--------------------------------
 Reporter:  ejucovy      |         Owner:  nobody
     Type:  New feature  |        Status:  new
Milestone:               |     Component:  Template system
  Version:  SVN          |      Severity:  Normal
 Keywords:               |  Triage Stage:  Unreviewed
Has patch:  1            |
-------------------------+--------------------------------
 I have a Python class that contains some data, and also has a `__call__`
 method, e.g.:
 {{{
 #!python
 class Doodad(object):
     def __init__(self, x, y):
         self.x = x
         self.y = y

     def __call__(self, a, b):
         return (self.x + a, self.y + b)
 }}}

 I'd like to be able to use instances of this class in my templates, to
 reference their attributes:
 {{{
 #!python
 from django.template import Template, Context

 ctx = Context(dict(my_doodad=Doodad(5, 10)))
 Template("My doodad's x value is {{my_doodad.x}}").render(ctx)
 }}}

 But because the object has a `__call__` method which takes more than zero
 arguments, Django's template system will try to call the method, catch the
 resulting !TypeError, and replace the object with
 `settings.TEMPLATE_STRING_IF_INVALID`.

 With the attached patch, callable objects can set an attribute to signal
 that Django's template system should leave them alone altogether.

 This is analogous to the `alters_data` attribute, which signals that
 Django's template system should replace the object with
 `settings.TEMPLATE_STRING_IF_INVALID` without trying to call it.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15791>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to