From 1fffcccc3584be04683b64a665174f9e6fc4d8a6 Mon Sep 17 00:00:00 2001 From: Andrey Lykhoman Date: Fri, 14 Dec 2018 14:38:31 +0200 Subject: [PATCH] add index_page property to response about a scorm file --- scormxblock/scormxblock.py | 19 +++++++++++++------ setup.py | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/scormxblock/scormxblock.py b/scormxblock/scormxblock.py index 4fb35b7b..e5b67db2 100644 --- a/scormxblock/scormxblock.py +++ b/scormxblock/scormxblock.py @@ -43,6 +43,10 @@ class ScormXBlock(XBlock): display_name=_("Upload scorm file"), scope=Scope.settings, ) + path_index_page = String( + display_name=_("Path to the index page in scorm file"), + scope=Scope.settings, + ) scorm_file_meta = Dict( scope=Scope.content ) @@ -273,7 +277,7 @@ def render_template(self, template_path, context): return template.render(Context(context)) def set_fields_xblock(self, path_to_file): - path_index_page = 'index.html' + self.path_index_page = 'index.html' try: tree = ET.parse('{}/imsmanifest.xml'.format(path_to_file)) except IOError: @@ -294,13 +298,13 @@ def set_fields_xblock(self, path_to_file): schemaversion = root.find('metadata/schemaversion') if resource: - path_index_page = resource.get('href') + self.path_index_page = resource.get('href') if (schemaversion is not None) and (re.match('^1.2$', schemaversion.text) is None): self.version_scorm = 'SCORM_2004' else: self.version_scorm = 'SCORM_12' - self.scorm_file = os.path.join(SCORM_URL, '{}/{}'.format(self.location.block_id, path_index_page)) + self.scorm_file = os.path.join(SCORM_URL, '{}/{}'.format(self.location.block_id, self.path_index_page)) def get_completion_status(self): completion_status = self.lesson_status @@ -339,9 +343,12 @@ def student_view_data(self): Make sure to include `student_view_data=scormxblock` to URL params in the request. """ if self.scorm_file and self.scorm_file_meta: - return {'last_modified': self.scorm_file_meta.get('last_updated', ''), - 'scorm_data': default_storage.url(self._file_storage_path()), - 'size': self.scorm_file_meta.get('size', 0)} + return { + 'last_modified': self.scorm_file_meta.get('last_updated', ''), + 'scorm_data': default_storage.url(self._file_storage_path()), + 'size': self.scorm_file_meta.get('size', 0), + 'index_page': self.path_index_page, + } return {} @staticmethod diff --git a/setup.py b/setup.py index 54a3dec4..ad101ddf 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def package_data(pkg, roots): setup( name='scormxblock-xblock', - version='0.4', + version='0.5', description='scormxblock XBlock', # TODO: write a better description. packages=[ 'scormxblock',