Skip to content

Commit

Permalink
Merge pull request #4 from edly-io/tehreem/make_scorm_xblock_compatib…
Browse files Browse the repository at this point in the history
…le_with_edx_completion_tool

Publish completion status on successfull completion of scorm course.
  • Loading branch information
tehreem-sadat authored Oct 26, 2020
2 parents 4176110 + 8e0595a commit ca7ed67
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions openedxscorm/scormxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import zipfile
import concurrent.futures

from completion import waffle as completion_waffle
from django.conf import settings
from django.core.files import File
from django.template import Context, Template
Expand All @@ -19,6 +20,7 @@
import pkg_resources

from web_fragments.fragment import Fragment
from xblock.completable import XBlockCompletionMode
from xblock.core import XBlock
from xblock.fields import Scope, String, Float, Boolean, Dict, DateTime, Integer

Expand Down Expand Up @@ -56,6 +58,8 @@ class ScormXBlock(XBlock):
Note that neither the folder the folder nor the package file are deleted when the
xblock is removed.
"""
has_custom_completion = True
completion_mode = XBlockCompletionMode.COMPLETABLE

display_name = String(
display_name=_("Display Name"),
Expand Down Expand Up @@ -331,6 +335,35 @@ def publish_grade(self):
self.runtime.publish(
self, "grade", {"value": self.get_grade(), "max_value": self.weight},
)
self.publish_completion()


def publish_completion(self):
"""
Mark scorm xbloxk as completed if user has completed the scorm course unit.
it will work along with the edX completion tool: https://github.com/edx/completion
"""
if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
return

if XBlockCompletionMode.get_mode(self) != XBlockCompletionMode.COMPLETABLE:
return

completion_value = 0.0
if not self.has_score:
# component does not have any score
if self.get_completion_status() == "completed":
completion_value = 1.0
else:
if self.get_completion_status() in ["passed", "failed"]:
completion_value = 1.0

data = {
"completion": completion_value
}
self.runtime.publish(self, "completion", data)


def get_grade(self):
lesson_score = self.lesson_score
Expand Down

0 comments on commit ca7ed67

Please sign in to comment.