'Returns a generator of batches of users.'

def _batch_users(self, context):

    def grouper(iterable, chunk_size=self.USER_BATCH_SIZE, fillvalue=None):
        args = ([iter(iterable)] * chunk_size)
        return izip_longest(fillvalue=fillvalue, *args)
    users = CourseEnrollment.objects.users_enrolled_in(context.course_id, include_inactive=True)
    users = users.select_related('profile__allow_certificate')
    return grouper(users)
