'Generates a hash encoding the given user\'s *active* enrollments.
Args:
user (User): User whose enrollments should be hashed.
Returns:
str: Hash of the user\'s active enrollments. If the user is anonymous, `None` is returned.'

@classmethod
def generate_enrollment_status_hash(cls, user):

    assert user
    if user.is_anonymous():
        return None
    cache_key = cls.enrollment_status_hash_cache_key(user)
    status_hash = cache.get(cache_key)
    if (not status_hash):
        enrollments = cls.enrollments_for_user(user).values_list('course_id', 'mode')
        enrollments = [(e[0].lower(), e[1].lower()) for e in enrollments]
        enrollments = sorted(enrollments, key=(lambda e: e[0]))
        hash_elements = [user.username]
        hash_elements += ['{course_id}={mode}'.format(course_id=e[0], mode=e[1]) for e in enrollments]
        status_hash = hashlib.md5('&'.join(hash_elements).encode('utf-8')).hexdigest()
        cache.set(cache_key, status_hash, None)
    return status_hash
