def handle(self, *args, **kwargs):  # pylint: disable=unused-argument
        edx_course_key = kwargs.get('edx_course_key')
        try:
            run = CourseRun.objects.get(edx_course_key=edx_course_key)
        except CourseRun.DoesNotExist:
            raise CommandError('Course Run for course_id "{0}" does not exist'.format(edx_course_key))

        con = get_redis_connection("redis")
        failed_users_count = con.llen(CACHE_KEY_FAILED_USERS_BASE_STR.format(edx_course_key))

        if CourseRunGradingStatus.is_complete(run):
            self.stdout.write(
                self.style.SUCCESS(
                    'Final grades for course "{0}" are complete'.format(edx_course_key)
                )
            )
        elif CourseRunGradingStatus.is_pending(run):
            cache_id = CACHE_ID_BASE_STR.format(edx_course_key)
            group_results_id = cache_redis.get(cache_id)
            if group_results_id is not None:
                results = GroupResult.restore(group_results_id, app=app)
                if not results.ready():
                    self.stdout.write(
                        self.style.WARNING(
                            'Final grades for course "{0}" are being processed'.format(edx_course_key)
                        )
                    )
                else:
                    self.stdout.write(
                        self.style.WARNING(
                            'Async task to freeze grade for course "{0}" '
                            'are done, but course is not marked as complete.'.format(edx_course_key)
                        )
                    )
            else:
                self.stdout.write(
                    self.style.ERROR(
                        'Final grades for course "{0}" are marked as they are being processed'
                        ', but no task found.'.format(edx_course_key)
                    )
                )
        else:
            self.stdout.write(
                self.style.WARNING(
                    'Final grades for course "{0}" are not being processed yet'.format(edx_course_key)
                )
            )
        message_detail = ', where {0} failed authentication'.format(failed_users_count) if failed_users_count else ''
        users_in_cache = set(CachedEnrollment.get_cached_users(run)).intersection(
            set(CachedCurrentGrade.get_cached_users(run))
        )
        self.stdout.write(
            self.style.SUCCESS(
                'The students with a final grade are {0}/{1}{2}'.format(
                    FinalGrade.objects.filter(course_run=run).count(),
                    len(users_in_cache),
                    message_detail
                )
            )
        )
    def handle(self, *args, **kwargs):  # pylint: disable=unused-argument
        edx_course_key = kwargs.get('edx_course_key')
        try:
            run = CourseRun.objects.get(edx_course_key=edx_course_key)
        except CourseRun.DoesNotExist:
            raise CommandError(
                'Course Run for course_id "{0}" does not exist'.format(
                    edx_course_key))

        con = get_redis_connection("redis")
        failed_users_count = con.llen(
            CACHE_KEY_FAILED_USERS_BASE_STR.format(edx_course_key))

        if CourseRunGradingStatus.is_complete(run):
            self.stdout.write(
                self.style.SUCCESS(
                    'Final grades for course "{0}" are complete'.format(
                        edx_course_key)))
        elif CourseRunGradingStatus.is_pending(run):
            cache_id = CACHE_ID_BASE_STR.format(edx_course_key)
            group_results_id = cache_redis.get(cache_id)
            if group_results_id is not None:
                results = GroupResult.restore(group_results_id, app=app)
                if not results.ready():
                    self.stdout.write(
                        self.style.WARNING(
                            'Final grades for course "{0}" are being processed'
                            .format(edx_course_key)))
                else:
                    self.stdout.write(
                        self.style.WARNING(
                            'Async task to freeze grade for course "{0}" '
                            'are done, but course is not marked as complete.'.
                            format(edx_course_key)))
            else:
                self.stdout.write(
                    self.style.ERROR(
                        'Final grades for course "{0}" are marked as they are being processed'
                        ', but no task found.'.format(edx_course_key)))
        else:
            self.stdout.write(
                self.style.WARNING(
                    'Final grades for course "{0}" are not being processed yet'
                    .format(edx_course_key)))
        message_detail = ', where {0} failed authentication'.format(
            failed_users_count) if failed_users_count else ''
        users_in_cache = set(
            CachedEnrollment.get_cached_users(run)).intersection(
                set(CachedCurrentGrade.get_cached_users(run)))
        self.stdout.write(
            self.style.SUCCESS(
                'The students with a final grade are {0}/{1}{2}'.format(
                    FinalGrade.objects.filter(course_run=run).count(),
                    len(users_in_cache), message_detail)))
Beispiel #3
0
def get_users_without_frozen_final_grade(course_run):
    """
    Public function to extract all the users that need a final grade freeze for a course run.
    All the users that are enrolled in a course run and have a
    current grade must have frozen final grade.

    Args:
        course_run (CourseRun): a course run model object

    Returns:
        queryset: a queryset of users
    """
    # get the list of users enrolled in the course and have current grade
    users_in_cache = set(CachedEnrollment.get_cached_users(course_run)).intersection(
        set(CachedCurrentGrade.get_cached_users(course_run))
    )
    # get all the users with already frozen final grade
    users_already_processed = set(FinalGrade.get_frozen_users(course_run))
    return User.objects.filter(pk__in=users_in_cache.difference(users_already_processed))
Beispiel #4
0
def get_users_without_frozen_final_grade(course_run):
    """
    Public function to extract all the users that need a final grade freeze for a course run.
    All the users that are enrolled in a course run and have a
    current grade must have frozen final grade.

    Args:
        course_run (CourseRun): a course run model object

    Returns:
        queryset: a queryset of users
    """
    # get the list of users enrolled in the course and have current grade
    users_in_cache = set(CachedEnrollment.get_cached_users(course_run)).intersection(
        set(CachedCurrentGrade.get_cached_users(course_run))
    )
    # get all the users with already frozen final grade
    users_already_processed = set(FinalGrade.get_frozen_users(course_run))
    return User.objects.filter(pk__in=users_in_cache.difference(users_already_processed))