Exemple #1
0
 def get_cohorts(self):
     cohorts = [""] + [
         group.name
         for group in get_course_cohorts(course_id=self.course_id)
     ]
     random_cohort = get_random_cohort(self.course_id)
     if random_cohort and random_cohort.name in cohorts:
         cohorts.remove(random_cohort.name)
     return cohorts
Exemple #2
0
def move_to_verified_cohort(sender, instance, **kwargs):  # pylint: disable=unused-argument
    """
    If the learner has changed modes, update assigned cohort iff the course is using
    the Automatic Verified Track Cohorting MVP feature.
    """
    from lms.djangoapps.courseware.courses import get_course_by_id
    course_key = instance.course_id
    verified_cohort_enabled = VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(
        course_key)
    verified_cohort_name = VerifiedTrackCohortedCourse.verified_cohort_name_for_course(
        course_key)

    if verified_cohort_enabled and (instance.mode != instance._old_mode):  # pylint: disable=protected-access
        if not is_course_cohorted(course_key):
            log.error(
                u"Automatic verified cohorting enabled for course '%s', but course is not cohorted.",
                course_key)
        else:
            course = get_course_by_id(course_key)
            existing_manual_cohorts = get_course_cohorts(
                course, assignment_type=CourseCohort.MANUAL)
            if any(cohort.name == verified_cohort_name
                   for cohort in existing_manual_cohorts):
                # Get a random cohort to use as the default cohort (for audit learners).
                # Note that calling this method will create a "Default Group" random cohort if no random
                # cohort yet exist.
                random_cohort = get_random_cohort(course_key)
                args = {
                    'course_id': six.text_type(course_key),
                    'user_id': instance.user.id,
                    'verified_cohort_name': verified_cohort_name,
                    'default_cohort_name': random_cohort.name
                }
                log.info(
                    u"Queuing automatic cohorting for user '%s' in course '%s' "
                    u"due to change in enrollment mode from '%s' to '%s'.",
                    instance.user.id,
                    course_key,
                    instance._old_mode,
                    instance.mode  # pylint: disable=protected-access
                )

                # Do the update with a 3-second delay in hopes that the CourseEnrollment transaction has been
                # completed before the celery task runs. We want a reasonably short delay in case the learner
                # immediately goes to the courseware.
                sync_cohort_with_mode.apply_async(kwargs=args, countdown=3)

                # In case the transaction actually was not committed before the celery task runs,
                # run it again after 5 minutes. If the first completed successfully, this task will be a no-op.
                sync_cohort_with_mode.apply_async(kwargs=args, countdown=300)
            else:
                log.error(
                    u"Automatic verified cohorting enabled for course '%s', "
                    u"but verified cohort named '%s' does not exist.",
                    course_key,
                    verified_cohort_name,
                )
Exemple #3
0
def move_to_verified_cohort(sender, instance, **kwargs):  # pylint: disable=unused-argument
    """
    If the learner has changed modes, update assigned cohort iff the course is using
    the Automatic Verified Track Cohorting MVP feature.
    """
    course_key = instance.course_id
    verified_cohort_enabled = VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(
        course_key)
    verified_cohort_name = VerifiedTrackCohortedCourse.verified_cohort_name_for_course(
        course_key)

    if verified_cohort_enabled and (instance.mode != instance._old_mode):  # pylint: disable=protected-access
        if not is_course_cohorted(course_key):
            log.error(
                "Automatic verified cohorting enabled for course '%s', but course is not cohorted.",
                course_key)
        else:
            course = get_course_by_id(course_key)
            existing_manual_cohorts = get_course_cohorts(
                course, CourseCohort.MANUAL)
            if any(cohort.name == verified_cohort_name
                   for cohort in existing_manual_cohorts):
                # Verify that a single random cohort exists in the course. Note that calling this method will create
                # a "Default Group" random cohort if no random cohorts exist yet.
                random_cohort = get_random_cohort(course_key)
                if not is_default_cohort(random_cohort):
                    log.error(
                        "Automatic verified cohorting enabled for course '%s', "
                        "but course does not have exactly one default cohort for audit learners.",
                        course_key)
                else:
                    args = {
                        'course_id': unicode(course_key),
                        'user_id': instance.user.id,
                        'verified_cohort_name': verified_cohort_name,
                        'default_cohort_name': random_cohort.name
                    }
                    # Do the update with a 3-second delay in hopes that the CourseEnrollment transaction has been
                    # completed before the celery task runs. We want a reasonably short delay in case the learner
                    # immediately goes to the courseware.
                    sync_cohort_with_mode.apply_async(kwargs=args, countdown=3)

                    # In case the transaction actually was not committed before the celery task runs,
                    # run it again after 5 minutes. If the first completed successfully, this task will be a no-op.
                    sync_cohort_with_mode.apply_async(kwargs=args,
                                                      countdown=300)
            else:
                log.error(
                    "Automatic verified cohorting enabled for course '%s', "
                    "but verified cohort named '%s' does not exist.",
                    course_key,
                    verified_cohort_name,
                )
Exemple #4
0
def move_to_verified_cohort(sender, instance, **kwargs):  # pylint: disable=unused-argument
    """
    If the learner has changed modes, update assigned cohort iff the course is using
    the Automatic Verified Track Cohorting MVP feature.
    """
    course_key = instance.course_id
    verified_cohort_enabled = VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key)
    verified_cohort_name = VerifiedTrackCohortedCourse.verified_cohort_name_for_course(course_key)

    if verified_cohort_enabled and (instance.mode != instance._old_mode):  # pylint: disable=protected-access
        if not is_course_cohorted(course_key):
            log.error("Automatic verified cohorting enabled for course '%s', but course is not cohorted.", course_key)
        else:
            course = get_course_by_id(course_key)
            existing_manual_cohorts = get_course_cohorts(course, CourseCohort.MANUAL)
            if any(cohort.name == verified_cohort_name for cohort in existing_manual_cohorts):
                # Get a random cohort to use as the default cohort (for audit learners).
                # Note that calling this method will create a "Default Group" random cohort if no random
                # cohort yet exist.
                random_cohort = get_random_cohort(course_key)
                args = {
                    'course_id': unicode(course_key),
                    'user_id': instance.user.id,
                    'verified_cohort_name': verified_cohort_name,
                    'default_cohort_name': random_cohort.name
                }
                log.info(
                    "Queuing automatic cohorting for user '%s' in course '%s' "
                    "due to change in enrollment mode from '%s' to '%s'.",
                    instance.user.id, course_key, instance._old_mode, instance.mode  # pylint: disable=protected-access
                )

                # Do the update with a 3-second delay in hopes that the CourseEnrollment transaction has been
                # completed before the celery task runs. We want a reasonably short delay in case the learner
                # immediately goes to the courseware.
                sync_cohort_with_mode.apply_async(kwargs=args, countdown=3)

                # In case the transaction actually was not committed before the celery task runs,
                # run it again after 5 minutes. If the first completed successfully, this task will be a no-op.
                sync_cohort_with_mode.apply_async(kwargs=args, countdown=300)
            else:
                log.error(
                    "Automatic verified cohorting enabled for course '%s', "
                    "but verified cohort named '%s' does not exist.",
                    course_key,
                    verified_cohort_name,
                )