'Validates that a user exists with the given e-mail address.'

def clean_username(self):

    username = self.cleaned_data['username']
    if ('@' in username):
        emails = ContactValue.objects.filter(value=username, field__field_type='email', contact__trash=False, contact__related_user__isnull=False)
        users = [email.contact.related_user.user for email in emails]
    else:
        users = User.objects.filter(user__username=username)
    if (len(users) == 0):
        raise forms.ValidationError(_("Sorry,    we    don't    know    that    user    or    e-mail."))
    else:
        username = users[0]
    return username
