'Retrieve the :class:`~StudentModule`s for the supplied ``username`` and ``block_keys``.
Arguments:
username (str): The name of the user to load `StudentModule`s for.
block_keys (list of :class:`~UsageKey`): The set of XBlocks to load data for.'

def _get_student_modules(self, username, block_keys):

    course_key_func = attrgetter('course_key')
    by_course = itertools.groupby(sorted(block_keys, key=course_key_func), course_key_func)
    for (course_key, usage_keys) in by_course:
        query = StudentModule.objects.chunked_filter('module_state_key__in', usage_keys, student__username=username, course_id=course_key)
        for student_module in query:
            usage_key = student_module.module_state_key.map_into_course(student_module.course_id)
            (yield (student_module, usage_key))
