#NEWLINE# @ register . filter ( ) #NEWLINE# def getattribute( model , item ) : #NEWLINE# #INDENT# "Chained lookup of item on model\n\n    If item has dots (eg: 'foo.bar.baz'), recursively call getattribute():\n    e = getattr(model, 'foo')\n    e = getattr(e, 'bar')\n    e = getattr(e, 'baz')\n    At each step, check if e is a callable, and if so, use e()\n\n    " #NEWLINE# elements = item . split ( '.' ) #NEWLINE# element = elements . pop ( 0 ) #NEWLINE# try : #NEWLINE# #INDENT# attr = getattr ( model , element , None ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( attr is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if callable ( attr ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# attr = attr ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# if elements : #NEWLINE# #INDENT# return getattribute ( attr , '.' . join ( element ) ) #NEWLINE# #UNINDENT# return attr