#NEWLINE# def clean_username( self ) : #NEWLINE# #INDENT# '\n        Validates that a user exists with the given e-mail address.\n        ' #NEWLINE# username = self . cleaned_data [ 'username' ] #NEWLINE# if ( '@' in username ) : #NEWLINE# #INDENT# emails = ContactValue . objects . filter ( value = username , field__field_type = 'email' , contact__trash = False , contact__related_user__isnull = False ) #NEWLINE# users = [ email . contact . related_user . user for email in emails ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# users = User . objects . filter ( user__username = username ) #NEWLINE# #UNINDENT# if ( len ( users ) == 0 ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( "Sorry, we don't know that user or e-mail." ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# username = emails [ 0 ] #NEWLINE# #UNINDENT# return username