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
badf86f7
Commit
badf86f7
authored
Jul 17, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have save_item parse json formatted field values by type
including allowing javascript to serialize date/time natively.
parent
025a9588
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
9 deletions
+36
-9
cms/djangoapps/contentstore/views/item.py
+34
-3
cms/static/js/base.js
+2
-6
No files found.
cms/djangoapps/contentstore/views/item.py
View file @
badf86f7
...
...
@@ -59,17 +59,21 @@ def save_item(request):
# 'apply' the submitted metadata, so we don't end up deleting system metadata
existing_item
=
modulestore
()
.
get_item
(
item_location
)
for
metadata_key
in
request
.
POST
.
get
(
'nullout'
,
[]):
setattr
(
existing_item
,
metadata_key
,
None
)
# [dhm] see comment on _get_xblock_field
_get_xblock_field
(
existing_item
,
metadata_key
)
.
write_to
(
existing_item
,
None
)
# update existing metadata with submitted metadata (which can be partial)
# IMPORTANT NOTE: if the client passed 'null' (None) for a piece of metadata that means 'remove it'. If
# the intent is to make it None, use the nullout field
for
metadata_key
,
value
in
request
.
POST
.
get
(
'metadata'
,
{})
.
items
():
# [dhm] see comment on _get_xblock_field
field
=
_get_xblock_field
(
existing_item
,
metadata_key
)
if
value
is
None
:
delattr
(
existing_item
,
metadata_key
)
field
.
delete_from
(
existing_item
)
else
:
setattr
(
existing_item
,
metadata_key
,
value
)
value
=
field
.
from_json
(
value
)
field
.
write_to
(
existing_item
,
value
)
# Save the data that we've just changed to the underlying
# MongoKeyValueStore before we update the mongo datastore.
existing_item
.
save
()
...
...
@@ -79,6 +83,33 @@ def save_item(request):
return
HttpResponse
()
# [DHM] A hack until we implement a permanent soln. Proposed perm solution is to make namespace fields also top level
# fields in xblocks rather than requiring dereference through namespace but we'll need to consider whether there are
# plausible use cases for distinct fields w/ same name in different namespaces on the same blocks.
# The idea is that consumers of the xblock, and particularly the web client, shouldn't know about our internal
# representation (namespaces as means of decorating all modules).
# Given top-level access, the calls can simply be setattr(existing_item, field, value) ...
# Really, this method should be elsewhere (e.g., xblock). We also need methods for has_value (v is_default)...
def
_get_xblock_field
(
xblock
,
field_name
):
"""
A temporary function to get the xblock field either from the xblock or one of its namespaces by name.
:param xblock:
:param field_name:
"""
def
find_field
(
fields
):
for
field
in
fields
:
if
field
.
name
==
field_name
:
return
field
found
=
find_field
(
xblock
.
fields
)
if
found
:
return
found
for
namespace
in
xblock
.
namespaces
:
found
=
find_field
(
getattr
(
xblock
,
namespace
)
.
fields
)
if
found
:
return
found
@login_required
@expect_json
def
create_item
(
request
):
...
...
cms/static/js/base.js
View file @
badf86f7
...
...
@@ -253,17 +253,13 @@ function syncReleaseDate(e) {
}
function
getEdxTimeFromDateTimeVals
(
date_val
,
time_val
)
{
var
edxTimeStr
=
null
;
if
(
date_val
!=
''
)
{
if
(
time_val
==
''
)
time_val
=
'00:00'
;
// Note, we are using date.js utility which has better parsing abilities than the built in JS date parsing
var
date
=
Date
.
parse
(
date_val
+
" "
+
time_val
);
edxTimeStr
=
date
.
toString
(
'yyyy-MM-ddTHH:mm'
);
return
new
Date
(
date_val
+
" "
+
time_val
+
"Z"
);
}
return
edxTimeStr
;
else
return
null
;
}
function
getEdxTimeFromDateTimeInputs
(
date_id
,
time_id
)
{
...
...
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