def get_username(identifier):
    pattern = re.compile('.+@\w+\..+')
    if pattern.match(identifier):
        try:
            user = User.objects.get(email=identifier)
        except:
            raise Http404
        else:
            return user.username
    else:
        return identifier
Checks if a string is a email adress or not.
dataset/ETHPy150Open bitmazk/django-libs/django_libs/decorators.py/get_username