def jinja2_getattr(self, obj, attribute):
 try:
  value = getattr(obj, attribute)
  if isinstance(value, property):
   value = value.fget()
  return value
 except AttributeError:
  pass
 try:
  value = obj[attribute]
  if isinstance(value, property):
   value = value.fget()
  return value
 except (TypeError, LookupError, AttributeError):
  return self.undefined(obj=obj, name=attribute)

def jinja2_getattr ( self , obj , attribute ) : try : value = getattr ( obj , attribute ) if isinstance ( value , property ) : value = value . fget ( ) return value except AttributeError : pass try : value = obj [ attribute ] if isinstance ( value , property ) : value = value . fget ( ) return value except ( TypeError , LookupError , AttributeError ) : return self . undefined ( obj = obj , name = attribute )
get an item or attribute of an object but prefer the attribute .