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
891e350a
Commit
891e350a
authored
Feb 08, 2013
by
chrisndodge
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1464 from MITx/bug/bug161
On first request for handouts, create the db record. (bug 160)
parents
2cdfed9e
fa5537ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
76 deletions
+72
-76
cms/djangoapps/contentstore/module_info_model.py
+72
-76
No files found.
cms/djangoapps/contentstore/module_info_model.py
View file @
891e350a
import
logging
from
static_replace
import
replace_static_urls
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
lxml
import
etree
import
re
from
django.http
import
HttpResponseBadRequest
,
Http404
from
django.http
import
Http404
def
get_module_info
(
store
,
location
,
parent_location
=
None
,
rewrite_static_links
=
False
):
try
:
if
location
.
revision
is
None
:
module
=
store
.
get_item
(
location
)
else
:
module
=
store
.
get_item
(
location
)
except
ItemNotFoundError
:
raise
Http404
try
:
if
location
.
revision
is
None
:
module
=
store
.
get_item
(
location
)
else
:
module
=
store
.
get_item
(
location
)
except
ItemNotFoundError
:
# create a new one
template_location
=
Location
([
'i4x'
,
'edx'
,
'templates'
,
location
.
category
,
'Empty'
])
module
=
store
.
clone_item
(
template_location
,
location
)
data
=
module
.
definition
[
'data'
]
if
rewrite_static_links
:
data
=
replace_static_urls
(
module
.
definition
[
'data'
],
None
,
course_namespace
=
Location
([
module
.
location
.
tag
,
module
.
location
.
org
,
module
.
location
.
course
,
data
=
module
.
definition
[
'data'
]
if
rewrite_static_links
:
data
=
replace_static_urls
(
module
.
definition
[
'data'
],
None
,
None
])
)
course_namespace
=
Location
([
module
.
location
.
tag
,
module
.
location
.
org
,
module
.
location
.
course
,
None
,
None
])
)
return
{
return
{
'id'
:
module
.
location
.
url
(),
'data'
:
data
,
'metadata'
:
module
.
metadata
...
...
@@ -39,58 +37,56 @@ def get_module_info(store, location, parent_location=None, rewrite_static_links=
def
set_module_info
(
store
,
location
,
post_data
):
module
=
None
isNew
=
False
try
:
if
location
.
revision
is
None
:
module
=
store
.
get_item
(
location
)
else
:
module
=
store
.
get_item
(
location
)
except
:
pass
module
=
None
try
:
if
location
.
revision
is
None
:
module
=
store
.
get_item
(
location
)
else
:
module
=
store
.
get_item
(
location
)
except
:
pass
if
module
is
None
:
# new module at this location
# presume that we have an 'Empty' template
template_location
=
Location
([
'i4x'
,
'edx'
,
'templates'
,
location
.
category
,
'Empty'
])
module
=
store
.
clone_item
(
template_location
,
location
)
isNew
=
True
if
module
is
None
:
# new module at this location
# presume that we have an 'Empty' template
template_location
=
Location
([
'i4x'
,
'edx'
,
'templates'
,
location
.
category
,
'Empty'
])
module
=
store
.
clone_item
(
template_location
,
location
)
if
post_data
.
get
(
'data'
)
is
not
None
:
data
=
post_data
[
'data'
]
store
.
update_item
(
location
,
data
)
if
post_data
.
get
(
'data'
)
is
not
None
:
data
=
post_data
[
'data'
]
store
.
update_item
(
location
,
data
)
# cdodge: note calling request.POST.get('children') will return None if children is an empty array
# so it lead to a bug whereby the last component to be deleted in the UI was not actually
# deleting the children object from the children collection
if
'children'
in
post_data
and
post_data
[
'children'
]
is
not
None
:
children
=
post_data
[
'children'
]
store
.
update_children
(
location
,
children
)
# cdodge: note calling request.POST.get('children') will return None if children is an empty array
# so it lead to a bug whereby the last component to be deleted in the UI was not actually
# deleting the children object from the children collection
if
'children'
in
post_data
and
post_data
[
'children'
]
is
not
None
:
children
=
post_data
[
'children'
]
store
.
update_children
(
location
,
children
)
# cdodge: also commit any metadata which might have been passed along in the
# POST from the client, if it is there
# NOTE, that the postback is not the complete metadata, as there's system metadata which is
# not presented to the end-user for editing. So let's fetch the original and
# 'apply' the submitted metadata, so we don't end up deleting system metadata
if
post_data
.
get
(
'metadata'
)
is
not
None
:
posted_metadata
=
post_data
[
'metadata'
]
# update existing metadata with submitted metadata (which can be partial)
# IMPORTANT NOTE: if the client passed pack 'null' (None) for a piece of metadata that means 'remove it'
for
metadata_key
in
posted_metadata
.
keys
():
# let's strip out any metadata fields from the postback which have been identified as system metadata
# and therefore should not be user-editable, so we should accept them back from the client
if
metadata_key
in
module
.
system_metadata_fields
:
del
posted_metadata
[
metadata_key
]
elif
posted_metadata
[
metadata_key
]
is
None
:
# remove both from passed in collection as well as the collection read in from the modulestore
if
metadata_key
in
module
.
metadata
:
del
module
.
metadata
[
metadata_key
]
del
posted_metadata
[
metadata_key
]
# overlay the new metadata over the modulestore sourced collection to support partial updates
module
.
metadata
.
update
(
posted_metadata
)
# commit to datastore
store
.
update_metadata
(
location
,
module
.
metadata
)
# cdodge: also commit any metadata which might have been passed along in the
# POST from the client, if it is there
# NOTE, that the postback is not the complete metadata, as there's system metadata which is
# not presented to the end-user for editing. So let's fetch the original and
# 'apply' the submitted metadata, so we don't end up deleting system metadata
if
post_data
.
get
(
'metadata'
)
is
not
None
:
posted_metadata
=
post_data
[
'metadata'
]
# update existing metadata with submitted metadata (which can be partial)
# IMPORTANT NOTE: if the client passed pack 'null' (None) for a piece of metadata that means 'remove it'
for
metadata_key
in
posted_metadata
.
keys
():
# let's strip out any metadata fields from the postback which have been identified as system metadata
# and therefore should not be user-editable, so we should accept them back from the client
if
metadata_key
in
module
.
system_metadata_fields
:
del
posted_metadata
[
metadata_key
]
elif
posted_metadata
[
metadata_key
]
is
None
:
# remove both from passed in collection as well as the collection read in from the modulestore
if
metadata_key
in
module
.
metadata
:
del
module
.
metadata
[
metadata_key
]
del
posted_metadata
[
metadata_key
]
# overlay the new metadata over the modulestore sourced collection to support partial updates
module
.
metadata
.
update
(
posted_metadata
)
# commit to datastore
store
.
update_metadata
(
location
,
module
.
metadata
)
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