Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ad4e3d50
Commit
ad4e3d50
authored
Apr 03, 2017
by
Omar Al-Ithawi
Committed by
Salah Alomari
May 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow uploading subtitles with unicode filenames
parent
6fa189dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
11 deletions
+28
-11
cms/djangoapps/contentstore/tests/test_transcripts_utils.py
+27
-10
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
+1
-1
No files found.
cms/djangoapps/contentstore/tests/test_transcripts_utils.py
View file @
ad4e3d50
...
@@ -86,11 +86,19 @@ class TestSaveSubsToStore(SharedModuleStoreTestCase):
...
@@ -86,11 +86,19 @@ class TestSaveSubsToStore(SharedModuleStoreTestCase):
def
clear_subs_content
(
self
):
def
clear_subs_content
(
self
):
"""Remove, if subtitles content exists."""
"""Remove, if subtitles content exists."""
try
:
for
content_location
in
[
self
.
content_location
,
self
.
content_copied_location
]:
content
=
contentstore
()
.
find
(
self
.
content_location
)
try
:
contentstore
()
.
delete
(
content
.
location
)
content
=
contentstore
()
.
find
(
content_location
)
except
NotFoundError
:
contentstore
()
.
delete
(
content
.
location
)
pass
except
NotFoundError
:
pass
@classmethod
def
sub_id_to_location
(
cls
,
sub_id
):
"""
A helper to compute a static file location from a subtitle id.
"""
return
StaticContent
.
compute_location
(
cls
.
course
.
id
,
u'subs_{0}.srt.sjson'
.
format
(
sub_id
))
@classmethod
@classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
...
@@ -110,22 +118,31 @@ class TestSaveSubsToStore(SharedModuleStoreTestCase):
...
@@ -110,22 +118,31 @@ class TestSaveSubsToStore(SharedModuleStoreTestCase):
]
]
}
}
cls
.
subs_id
=
str
(
uuid4
())
# Prefix it to ensure that unicode filenames are allowed
filename
=
'subs_{0}.srt.sjson'
.
format
(
cls
.
subs_id
)
cls
.
subs_id
=
u'uniçøde_{}'
.
format
(
uuid4
())
cls
.
content_location
=
StaticContent
.
compute_location
(
cls
.
course
.
id
,
filename
)
cls
.
subs_copied_id
=
u'cøpy_{}'
.
format
(
uuid4
())
cls
.
content_location
=
cls
.
sub_id_to_location
(
cls
.
subs_id
)
cls
.
content_copied_location
=
cls
.
sub_id_to_location
(
cls
.
subs_copied_id
)
# incorrect subs
# incorrect subs
cls
.
unjsonable_subs
=
{
1
}
# set can't be serialized
cls
.
unjsonable_subs
=
{
1
}
# set can't be serialized
cls
.
unjsonable_subs_id
=
str
(
uuid4
())
cls
.
unjsonable_subs_id
=
str
(
uuid4
())
filename_unjsonable
=
'subs_{0}.srt.sjson'
.
format
(
cls
.
unjsonable_subs_id
)
cls
.
content_location_unjsonable
=
cls
.
sub_id_to_location
(
cls
.
unjsonable_subs_id
)
cls
.
content_location_unjsonable
=
StaticContent
.
compute_location
(
cls
.
course
.
id
,
filename_unjsonable
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestSaveSubsToStore
,
self
)
.
setUp
()
super
(
TestSaveSubsToStore
,
self
)
.
setUp
()
self
.
addCleanup
(
self
.
clear_subs_content
)
self
.
addCleanup
(
self
.
clear_subs_content
)
self
.
clear_subs_content
()
self
.
clear_subs_content
()
def
test_save_unicode_filename
(
self
):
# Mock a video item
item
=
Mock
(
location
=
Mock
(
course_key
=
self
.
course
.
id
))
transcripts_utils
.
save_subs_to_store
(
self
.
subs
,
self
.
subs_id
,
self
.
course
)
transcripts_utils
.
copy_or_rename_transcript
(
self
.
subs_copied_id
,
self
.
subs_id
,
item
)
self
.
assertTrue
(
contentstore
()
.
find
(
self
.
content_copied_location
))
def
test_save_subs_to_store
(
self
):
def
test_save_subs_to_store
(
self
):
with
self
.
assertRaises
(
NotFoundError
):
with
self
.
assertRaises
(
NotFoundError
):
contentstore
()
.
find
(
self
.
content_location
)
contentstore
()
.
find
(
self
.
content_location
)
...
...
common/lib/xmodule/xmodule/video_module/transcripts_utils.py
View file @
ad4e3d50
...
@@ -283,7 +283,7 @@ def copy_or_rename_transcript(new_name, old_name, item, delete_old=False, user=N
...
@@ -283,7 +283,7 @@ def copy_or_rename_transcript(new_name, old_name, item, delete_old=False, user=N
If `old_name` is not found in storage, raises `NotFoundError`.
If `old_name` is not found in storage, raises `NotFoundError`.
If `delete_old` is True, removes `old_name` files from storage.
If `delete_old` is True, removes `old_name` files from storage.
"""
"""
filename
=
'subs_{0}.srt.sjson'
.
format
(
old_name
)
filename
=
u
'subs_{0}.srt.sjson'
.
format
(
old_name
)
content_location
=
StaticContent
.
compute_location
(
item
.
location
.
course_key
,
filename
)
content_location
=
StaticContent
.
compute_location
(
item
.
location
.
course_key
,
filename
)
transcripts
=
contentstore
()
.
find
(
content_location
)
.
data
transcripts
=
contentstore
()
.
find
(
content_location
)
.
data
save_subs_to_store
(
json
.
loads
(
transcripts
),
new_name
,
item
)
save_subs_to_store
(
json
.
loads
(
transcripts
),
new_name
,
item
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment