diff --git a/scormxblock/scormxblock.py b/scormxblock/scormxblock.py index c23aa841..80759571 100644 --- a/scormxblock/scormxblock.py +++ b/scormxblock/scormxblock.py @@ -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( @@ -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, '')} @@ -360,4 +369,4 @@ def workbench_scenarios(): """), - ] \ No newline at end of file + ]