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

Add the ability to get learner_id/student_id and learner_name from SCORM 1.2 or 2004 #26

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions scormxblock/scormxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
_ = lambda text: text

log = logging.getLogger(__name__)
log.setLevel(logging.INFO)

SCORM_ROOT = os.path.join(settings.MEDIA_ROOT, 'scorm')
SCORM_URL = os.path.join(settings.MEDIA_URL, 'scorm')


@XBlock.wants('user')
class ScormXBlock(XBlock):

display_name = String(
Expand Down Expand Up @@ -182,13 +183,21 @@ def studio_submit(self, request, suffix=''):

@XBlock.json_handler
def scorm_get_value(self, data, suffix=''):
user_service = self.runtime.service(self, 'user')
xb_user = user_service.get_current_user()
name = data.get('name')
log.info('Retrieve xb_user {}'.format(xb_user))
log.info('Retrieve anonymous student ID "{}"'.format(self.runtime.anonymous_student_id))
if name in ['cmi.core.lesson_status', 'cmi.completion_status']:
return {'value': self.lesson_status}
elif name == 'cmi.success_status':
return {'value': self.success_status}
elif name in ['cmi.core.score.raw', 'cmi.score.raw']:
return {'value': self.lesson_score * 100}
elif name in ['cmi.learner_id', 'cmi.core.student_id']:
return {'value': xb_user.opt_attrs.get('edx-platform.user_id', xb_user.full_name) or self.runtime.anonymous_student_id}
elif name in ['cmi.learner_name', 'cmi.core.student_name']:
return {'value': xb_user.opt_attrs.get('edx-platform.username', xb_user.full_name)}
else:
return {'value': self.data_scorm.get(name, '')}

Expand Down Expand Up @@ -360,4 +369,4 @@ def workbench_scenarios():
<scormxblock/>
</vertical_demo>
"""),
]
]