Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from edx-solutions/aamishbaloch/YONK-994
Browse files Browse the repository at this point in the history
YONK-994: Existing shell import inconsistent progress FIX
  • Loading branch information
aamishbaloch committed May 28, 2018
2 parents 4625e5c + 372099f commit d74f46a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 36 additions & 1 deletion course_metadata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,41 @@
Utility methods for course metadata app
"""
from django.conf import settings
from django.db.models import Q

from xmodule.modulestore.django import modulestore
from progress.models import StudentProgress, CourseModuleCompletion
from student.models import CourseEnrollment


def remove_orphans_and_recalculate_progress(course_key, detached_categories):
from contentstore.views.item import _delete_orphans
from xmodule.modulestore import ModuleStoreEnum
from progress.signals import is_valid_progress_module

_delete_orphans(
course_key, ModuleStoreEnum.UserID.mgmt_command, True
)

users = CourseEnrollment.objects.users_enrolled_in(course_key)

detached_categories_list = [Q(content_id__contains=item.strip()) for item in detached_categories]
detached_categories_list = reduce(lambda a, b: a | b, detached_categories_list)

for user in users:
completions = CourseModuleCompletion.objects.filter(course_id=course_key, user_id=user.id)\
.exclude(detached_categories_list).values_list('content_id', flat=True).distinct()

num_completions = sum([is_valid_progress_module(content_id=content_id) for content_id in completions])
try:
progress_record = StudentProgress.objects.get(user=user, course_id=course_key)

if progress_record.completions != num_completions:
progress_record.completions = num_completions
progress_record.save()

except StudentProgress.DoesNotExist:
pass


def get_course_leaf_nodes(course_key):
Expand All @@ -13,8 +46,10 @@ def get_course_leaf_nodes(course_key):
nodes = []
detached_categories = getattr(settings, 'PROGRESS_DETACHED_CATEGORIES', [])
store = modulestore()
verticals = store.get_items(course_key, qualifiers={'category': 'vertical'})
orphans = store.get_orphans(course_key)
if orphans:
remove_orphans_and_recalculate_progress(course_key, detached_categories)
verticals = store.get_items(course_key, qualifiers={'category': 'vertical'})
for vertical in verticals:
if hasattr(vertical, 'children') and not is_progress_detached_vertical(vertical) and \
vertical.location not in orphans:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='course-edx-platform-extensions',
version='1.0.9',
version='1.1.1',
description='Course metadata management extension for edX platform',
long_description=open('README.rst').read(),
author='edX',
Expand Down

0 comments on commit d74f46a

Please sign in to comment.