Commit 03d2e51f by Awais Jibran

Fix unable to view ORA responses (files) in leaderboard

EDUCATOR-560
parent 93e0ca47
...@@ -28,3 +28,4 @@ Mushtaq Ali <mushtaak@gmail.com> ...@@ -28,3 +28,4 @@ Mushtaq Ali <mushtaak@gmail.com>
Dmitry Viskov <dmitry.viskov@webenterprise.ru> Dmitry Viskov <dmitry.viskov@webenterprise.ru>
Jeff LaJoie <jlajoie@edx.org> Jeff LaJoie <jlajoie@edx.org>
Albert St. Aubin Jr. <astaubin@edx.org> Albert St. Aubin Jr. <astaubin@edx.org>
Awais Jibran <awaisdar001@gmail.com>
...@@ -76,16 +76,18 @@ class LeaderboardMixin(object): ...@@ -76,16 +76,18 @@ class LeaderboardMixin(object):
for score in scores: for score in scores:
score['files'] = [] score['files'] = []
if 'file_keys' in score['content']: if 'file_keys' in score['content']:
for key in score['content']['file_keys']: file_keys = score['content'].get('file_keys', [])
url = '' descriptions = score['content'].get('files_descriptions', [])
try: for idx, key in enumerate(file_keys):
url = file_upload_api.get_download_url(key) file_download_url = self._get_file_download_url(key)
except FileUploadError: if file_download_url:
pass file_description = descriptions[idx] if idx < len(descriptions) else ''
if url: score['files'].append((file_download_url, file_description))
score['files'].append(url)
elif 'file_key' in score['content']: elif 'file_key' in score['content']:
score['files'].append(file_upload_api.get_download_url(score['content']['file_key'])) file_download_url = self._get_file_download_url(score['content']['file_key'])
if file_download_url:
score['files'].append((file_download_url, ''))
if 'text' in score['content'] or 'parts' in score['content']: if 'text' in score['content'] or 'parts' in score['content']:
submission = {'answer': score.pop('content')} submission = {'answer': score.pop('content')}
score['submission'] = create_submission_dict(submission, self.prompts) score['submission'] = create_submission_dict(submission, self.prompts)
...@@ -112,3 +114,19 @@ class LeaderboardMixin(object): ...@@ -112,3 +114,19 @@ class LeaderboardMixin(object):
template_path (string), tuple of context (dict) template_path (string), tuple of context (dict)
""" """
return 'openassessmentblock/leaderboard/oa_leaderboard_waiting.html', {'xblock_id': self.get_xblock_id()} return 'openassessmentblock/leaderboard/oa_leaderboard_waiting.html', {'xblock_id': self.get_xblock_id()}
def _get_file_download_url(self, file_key):
"""
Internal function for retrieving the download url at which the file that corresponds
to the file_key can be downloaded.
Arguments:
file_key (string): Corresponding file key.
Returns:
file_download_url (string) or empty string in case of error.
"""
try:
file_download_url = file_upload_api.get_download_url(file_key)
except FileUploadError:
file_download_url = ''
return file_download_url
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment