#NEWLINE# def to_dict( model ) : #NEWLINE# #INDENT# output = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , prop ) in model . properties ( ) . iteritems ( ) : #NEWLINE# #INDENT# value = getattr ( model , key ) #NEWLINE# if ( ( value is None ) or isinstance ( value , SIMPLE_TYPES ) ) : #NEWLINE# #INDENT# output [ key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , datetime . date ) : #NEWLINE# #INDENT# output [ key ] = value . strftime ( settings . DATE_FORMAT ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , db . GeoPt ) : #NEWLINE# #INDENT# output [ key ] = { #NEWLINE# #INDENT# 'lat' : value . lat , #NEWLINE# 'lon' : value . lon , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , db . Model ) : #NEWLINE# #INDENT# output [ key ] = to_dict ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'cannot encode ' + repr ( prop ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# output [ 'id' ] = model . key ( ) . id ( ) #NEWLINE# return output