Ticket #7153: template_callable.diff

File template_callable.diff, 2.5 KB (added by Ionut Ciocirlan <ionut.ciocirlan@…>, 16 years ago)
  • django/template/__init__.py

     
    686686            except (TypeError, AttributeError, KeyError):
    687687                try: # attribute lookup
    688688                    current = getattr(current, bit)
    689                     if callable(current):
    690                         if getattr(current, 'alters_data', False):
    691                             current = settings.TEMPLATE_STRING_IF_INVALID
    692                         else:
    693                             try: # method call (assuming no args required)
    694                                 current = current()
    695                             except TypeError: # arguments *were* required
    696                                 # GOTCHA: This will also catch any TypeError
    697                                 # raised in the function itself.
    698                                 current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call
    699                             except Exception, e:
    700                                 if getattr(e, 'silent_variable_failure', False):
    701                                     current = settings.TEMPLATE_STRING_IF_INVALID
    702                                 else:
    703                                     raise
    704689                except (TypeError, AttributeError):
    705690                    try: # list-index lookup
    706691                        current = current[int(bit)]
     
    715700                        current = settings.TEMPLATE_STRING_IF_INVALID
    716701                    else:
    717702                        raise
     703           
     704            if callable(current):
     705                if getattr(current, 'alters_data', False):
     706                    current = settings.TEMPLATE_STRING_IF_INVALID
     707                else:
     708                    try: # method call (assuming no args required)
     709                        current = current()
     710                    except TypeError: # arguments *were* required
     711                        # GOTCHA: This will also catch any TypeError
     712                        # raised in the function itself.
     713                        current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call
     714                    except Exception, e:
     715                        if getattr(e, 'silent_variable_failure', False):
     716                            current = settings.TEMPLATE_STRING_IF_INVALID
     717                        else:
     718                            raise
    718719
    719720        return current
    720721
Back to Top