old_contents: import re
  from django.template import Library
  from django.conf import settings
  
  numeric_test = re.compile("^\d+$")
  register = Library()
  
  @register.filter
  def getattribute(value, arg):
      """Gets an attribute of an object dynamically from a string name"""
      if hasattr(value, str(arg)):
          return getattr(value, arg)
      elif hasattr(value, 'has_key') and value.has_key(arg):
          return value[arg]
      elif numeric_test.match(str(arg)) and len(value) > int(arg):
          return value[int(arg)]
      else:
          return settings.TEMPLATE_STRING_IF_INVALID
  
new_contents: import re
  from django.template import Library
  from django.conf import settings
  
  numeric_test = re.compile("^\d+$")
  register = Library()
  
  @register.filter
  def getattribute(value, argstr):
      """Gets an attribute of an object dynamically from a string name"""
      args = argstr.split(".")
      leads = args[:-1]
      arg = args[-1]
      for lead in leads:
          value = getattr(value, lead)
      if hasattr(value, str(arg)):
          return getattr(value, arg)
      elif hasattr(value, 'has_key') and value.has_key(arg):
          return value[arg]
      elif numeric_test.match(str(arg)) and len(value) > int(arg):
          return value[int(arg)]
      else:
          return settings.TEMPLATE_STRING_IF_INVALID
  
subject: Make getattribute traverse nested items