Files
edx-platform/cms/djangoapps/contentstore/management/commands/utils.py
2014-10-21 16:34:36 -04:00

20 lines
548 B
Python

"""
Common methods for cms commands to use
"""
from django.contrib.auth.models import User
def user_from_str(identifier):
"""
Return a user identified by the given string. The string could be an email
address, or a stringified integer corresponding to the ID of the user in
the database. If no user could be found, a User.DoesNotExist exception
will be raised.
"""
try:
user_id = int(identifier)
except ValueError:
return User.objects.get(email=identifier)
return User.objects.get(id=user_id)