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
d4e82424
Commit
d4e82424
authored
Dec 10, 2014
by
Braden MacDonald
Committed by
E. Kolpakov
Jan 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Friendly error message when library key is invalid
parent
d25673ec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
3 deletions
+38
-3
cms/djangoapps/contentstore/views/item.py
+3
-2
cms/djangoapps/contentstore/views/tests/test_item.py
+23
-0
common/lib/xmodule/xmodule/library_content_module.py
+12
-1
No files found.
cms/djangoapps/contentstore/views/item.py
View file @
d4e82424
...
...
@@ -426,8 +426,9 @@ def _save_xblock(user, xblock, data=None, children_strings=None, metadata=None,
else
:
try
:
value
=
field
.
from_json
(
value
)
except
ValueError
:
return
JsonResponse
({
"error"
:
"Invalid data"
},
400
)
except
ValueError
as
verr
:
reason
=
_
(
"Invalid data ({details})"
)
.
format
(
details
=
verr
.
message
)
if
verr
.
message
else
_
(
"Invalid data"
)
return
JsonResponse
({
"error"
:
reason
},
400
)
field
.
write_to
(
xblock
,
value
)
# update the xblock and call any xblock callbacks
...
...
cms/djangoapps/contentstore/views/tests/test_item.py
View file @
d4e82424
...
...
@@ -894,6 +894,29 @@ class TestEditItem(ItemTest):
self
.
_verify_published_with_draft
(
unit_usage_key
)
self
.
_verify_published_with_draft
(
html_usage_key
)
def
test_field_value_errors
(
self
):
"""
Test that if the user's input causes a ValueError on an XBlock field,
we provide a friendly error message back to the user.
"""
response
=
self
.
create_xblock
(
parent_usage_key
=
self
.
seq_usage_key
,
category
=
'video'
)
video_usage_key
=
self
.
response_usage_key
(
response
)
update_url
=
reverse_usage_url
(
'xblock_handler'
,
video_usage_key
)
response
=
self
.
client
.
ajax_post
(
update_url
,
data
=
{
'id'
:
unicode
(
video_usage_key
),
'metadata'
:
{
'saved_video_position'
:
"Not a valid relative time"
,
},
}
)
self
.
assertEqual
(
response
.
status_code
,
400
)
parsed
=
json
.
loads
(
response
.
content
)
self
.
assertIn
(
"error"
,
parsed
)
self
.
assertIn
(
"Incorrect RelativeTime value"
,
parsed
[
"error"
])
# See xmodule/fields.py
class
TestEditSplitModule
(
ItemTest
):
"""
...
...
common/lib/xmodule/xmodule/library_content_module.py
View file @
d4e82424
"""
LibraryContent: The XBlock used to include blocks from a library in a course.
"""
from
bson.objectid
import
ObjectId
from
bson.objectid
import
ObjectId
,
InvalidId
from
collections
import
namedtuple
from
copy
import
copy
import
hashlib
from
.mako_module
import
MakoModuleDescriptor
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locator
import
LibraryLocator
import
random
from
webob
import
Response
...
...
@@ -46,7 +47,10 @@ class LibraryVersionReference(namedtuple("LibraryVersionReference", "library_id
version
=
library_id
.
version_guid
library_id
=
library_id
.
for_version
(
None
)
if
version
and
not
isinstance
(
version
,
ObjectId
):
try
:
version
=
ObjectId
(
version
)
except
InvalidId
:
raise
ValueError
(
version
)
return
super
(
LibraryVersionReference
,
cls
)
.
__new__
(
cls
,
library_id
,
version
)
@staticmethod
...
...
@@ -86,7 +90,14 @@ class LibraryList(List):
val
=
val
.
strip
(
' []'
)
parts
=
val
.
rsplit
(
','
,
1
)
val
=
[
parts
[
0
],
parts
[
1
]
if
len
(
parts
)
>
1
else
None
]
try
:
return
LibraryVersionReference
.
from_json
(
val
)
except
InvalidKeyError
:
try
:
friendly_val
=
val
[
0
]
# Just get the library key part, not the version
except
IndexError
:
friendly_val
=
unicode
(
val
)
raise
ValueError
(
_
(
'"{value}" is not a valid library ID.'
)
.
format
(
value
=
friendly_val
))
return
[
parse
(
v
)
for
v
in
values
]
def
to_json
(
self
,
values
):
...
...
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