Files
edx-platform/lms/djangoapps/instructor/views/tools.py
Sarina Canelake 91d85f5c2a Enable alerts when a task succeeds.
Note: Alerts are pop-up boxes. Not sure if this is desireable, but I couldn't figure out
how to make a success message show up in the same place that error messages do.
2013-09-27 12:17:53 -04:00

26 lines
769 B
Python

"""
Tools for the instructor dashboard
"""
from django.contrib.auth.models import User
def strip_if_string(value):
if isinstance(value, basestring):
return value.strip()
return value
def get_student_from_identifier(unique_student_identifier):
"""
Gets a student object using either an email address or username.
Returns the student object associated with `unique_student_identifier`
Raises User.DoesNotExist if no user object can be found.
"""
unique_student_identifier = strip_if_string(unique_student_identifier)
if "@" in unique_student_identifier:
student = User.objects.get(email=unique_student_identifier)
else:
student = User.objects.get(username=unique_student_identifier)
return student