Skip to content

Commit

Permalink
Merge pull request #32099 from open-craft/navin/fix-video-transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
e0d authored May 18, 2023
2 parents 26e62de + 1836305 commit 2f44415
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cms/djangoapps/contentstore/views/tests/test_transcripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def test_transcript_upload_success(self, edx_video_id, include_bom):
expected_edx_video_id = edx_video_id if edx_video_id else json_response['edx_video_id']
video = modulestore().get_item(self.video_usage_key)
self.assertEqual(video.edx_video_id, expected_edx_video_id)
self.assertDictEqual(video.transcripts, {'en': f'{expected_edx_video_id}-en.srt'})

# Verify transcript content
actual_transcript = get_video_transcript_content(video.edx_video_id, language_code='en')
Expand Down Expand Up @@ -319,6 +320,8 @@ def test_transcript_upload_bad_content(self):
expected_status_code=400,
expected_message='There is a problem with this transcript file. Try to upload a different file.'
)
video = modulestore().get_item(self.video_usage_key)
self.assertDictEqual(video.transcripts, {})

def test_transcript_upload_unknown_category(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions cms/djangoapps/contentstore/views/transcripts_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def upload_transcripts(request):
file_data=ContentFile(sjson_subs),
)

video.transcripts['en'] = f"{edx_video_id}-en.srt"
video.save_with_metadata(request.user)
if transcript_created is None:
response = JsonResponse({'status': 'Invalid Video ID'}, status=400)

Expand Down
4 changes: 3 additions & 1 deletion lms/djangoapps/courseware/tests/test_video_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def test_studio_transcript_post_w_no_edx_video_id(self, edx_video_id):
assert response.status == '201 Created'
response = json.loads(response.text)
assert response['language_code'], 'uk'
self.assertDictEqual(self.block.transcripts, {})
self.assertDictEqual(self.block.transcripts, {'uk': f'{response["edx_video_id"]}-uk.srt'})
assert edxval_api.get_video_transcript_data(video_id=response['edx_video_id'], language_code='uk')

def test_studio_transcript_post_bad_content(self):
Expand All @@ -999,6 +999,8 @@ def test_studio_transcript_post_bad_content(self):
response = self.block.studio_transcript(request=request, dispatch="translation")
assert response.status_code == 400
assert response.json['error'] == 'There is a problem with this transcript file. Try to upload a different file.'
# transcripts fields should not be updated
self.assertDictEqual(self.block.transcripts, {})


@ddt.ddt
Expand Down
2 changes: 1 addition & 1 deletion xmodule/video_block/video_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ def studio_transcript(self, request, dispatch):
`POST`:
Upload srt file. Check possibility of generation of proper sjson files.
For now, it works only for self.transcripts, not for `en`.
Do not update self.transcripts, as fields are updated on save in Studio.
`GET:
Return filename from storage. SRT format is sent back on success. Filename should be in GET dict.
Expand Down Expand Up @@ -529,6 +528,7 @@ def studio_transcript(self, request, dispatch):
'edx_video_id': edx_video_id,
'language_code': new_language_code
}
self.transcripts[new_language_code] = f'{edx_video_id}-{new_language_code}.srt'
response = Response(json.dumps(payload), status=201)
except (TranscriptsGenerationException, UnicodeDecodeError):
response = Response(
Expand Down

0 comments on commit 2f44415

Please sign in to comment.