Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'missing resource' alert not showing on Home page for missing quiz resources #12008

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions kolibri/plugins/learn/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def get(self, request, format=None):
)


def _map_contentnodes(request, content_ids):
contentnodes = (
contentnode_viewset.serialize_list(request, {"ids": content_ids})
if content_ids
else []
)
contentnode_map = {c["id"]: c for c in contentnodes}
return contentnode_map


def _consolidate_lessons_data(request, lessons):
lesson_contentnode_ids = set()
for lesson in lessons:
Expand All @@ -69,16 +79,10 @@ def _consolidate_lessons_data(request, lessons):
else []
)

contentnodes = (
contentnode_viewset.serialize_list(request, {"ids": lesson_contentnode_ids})
if lesson_contentnode_ids
else []
)
contentnode_map = _map_contentnodes(request, lesson_contentnode_ids)

progress_map = {l["content_id"]: l["progress"] for l in contentnode_progress}

contentnode_map = {c["id"]: c for c in contentnodes}

for lesson in lessons:
lesson["progress"] = {
"resource_progress": sum(
Expand Down Expand Up @@ -198,6 +202,8 @@ def consolidate(self, items, queryset):
)
)

contentnode_map = _map_contentnodes(self.request, available_exam_ids)

for exam in exams:
closed = exam.pop("closed")
score = exam.pop("score")
Expand All @@ -216,10 +222,12 @@ def consolidate(self, items, queryset):
"closed": None,
"started": False,
}
exam["missing_resource"] = any(
question["exercise_id"] not in available_exam_ids
rtibbles marked this conversation as resolved.
Show resolved Hide resolved
for question in exam.get("question_sources")
)
missing_resource = False
for question_source in exam["question_sources"]:
if question_source["exercise_id"] not in contentnode_map:
missing_resource = True
break
exam["missing_resource"] = missing_resource
out_items = []
for item in items:
item["assignments"] = {
Expand Down
Loading