﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15791	New feature: callable objects can signal that templates should never call them	Ethan Jucovy	nobody	"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."	New feature	closed	Template system	dev	Normal	fixed		ethan.jucovy@…	Ready for checkin	1	0	0	0	0	0
