#NEWLINE# def get_attribute_value( item , field , context , force = False , skip_autofield = True ) : #NEWLINE# #INDENT# " Gets a string version of the given attribute's value, like repr() might. " #NEWLINE# try : #NEWLINE# #INDENT# value = getattr ( item , field . name ) #NEWLINE# #UNINDENT# except ObjectDoesNotExist : #NEWLINE# #INDENT# raise SkipValue ( ( 'Could not find object for %s.%s, ignoring.\n' % ( item . __class__ . __name__ , field . name ) ) ) #NEWLINE# #UNINDENT# if ( skip_autofield and isinstance ( field , AutoField ) ) : #NEWLINE# #INDENT# raise SkipValue ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( field , BooleanField ) and ( value is not None ) ) : #NEWLINE# #INDENT# return repr ( bool ( value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( field , FileField ) : #NEWLINE# #INDENT# return repr ( force_unicode ( value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( field , ForeignKey ) and ( value is not None ) ) : #NEWLINE# #INDENT# if ( field . rel . to is ContentType ) : #NEWLINE# #INDENT# return ( 'ContentType.objects.get(app_label="%s", model="%s")' % ( value . app_label , context . model ) ) #NEWLINE# #UNINDENT# pk_name = value . _meta . pk . name #NEWLINE# key = ( '%s_%s' % ( value . __class__ . __name__ , getattr ( value , pk_name ) ) ) #NEWLINE# if ( key in context ) : #NEWLINE# #INDENT# variable_name = context [ key ] #NEWLINE# if ( variable_name is None ) : #NEWLINE# #INDENT# raise SkipValue ( ) #NEWLINE# #UNINDENT# return ( '%s' % variable_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( value . __class__ not in context [ '__avaliable_models' ] ) or force ) : #NEWLINE# #INDENT# context [ '__extra_imports' ] [ value . _meta . object_name ] = value . __module__ #NEWLINE# item_locator = orm_item_locator ( value ) #NEWLINE# return item_locator #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise DoLater ( ( '(FK) %s.%s\n' % ( item . __class__ . __name__ , field . name ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( field , ( DateField , DateTimeField ) ) and ( value is not None ) ) : #NEWLINE# #INDENT# return ( 'dateutil.parser.parse("%s")' % value . isoformat ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return repr ( value )