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
71f39bc4
Commit
71f39bc4
authored
Sep 25, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #751 from MITx/cdodge/meta-data-cms-editing
Cdodge/meta data cms editing
parents
e50cc77a
a85b2552
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
70 additions
and
11 deletions
+70
-11
cms/djangoapps/contentstore/views.py
+15
-0
cms/static/coffee/src/models/module.coffee
+12
-0
cms/templates/widgets/html-edit.html
+1
-0
cms/templates/widgets/metadata-edit.html
+10
-0
cms/templates/widgets/raw-edit.html
+1
-0
cms/templates/widgets/sequence-edit.html
+1
-0
common/djangoapps/util/json_request.py
+3
-1
common/lib/xmodule/xmodule/editing_module.py
+8
-8
common/lib/xmodule/xmodule/mako_module.py
+12
-1
common/lib/xmodule/xmodule/seq_module.py
+3
-1
common/lib/xmodule/xmodule/x_module.py
+4
-0
No files found.
cms/djangoapps/contentstore/views.py
View file @
71f39bc4
...
@@ -104,12 +104,14 @@ def edit_item(request):
...
@@ -104,12 +104,14 @@ def edit_item(request):
item
=
modulestore
()
.
get_item
(
item_location
)
item
=
modulestore
()
.
get_item
(
item_location
)
item
.
get_html
=
wrap_xmodule
(
item
.
get_html
,
item
,
"xmodule_edit.html"
)
item
.
get_html
=
wrap_xmodule
(
item
.
get_html
,
item
,
"xmodule_edit.html"
)
return
render_to_response
(
'unit.html'
,
{
return
render_to_response
(
'unit.html'
,
{
'contents'
:
item
.
get_html
(),
'contents'
:
item
.
get_html
(),
'js_module'
:
item
.
js_module_name
,
'js_module'
:
item
.
js_module_name
,
'category'
:
item
.
category
,
'category'
:
item
.
category
,
'url_name'
:
item
.
url_name
,
'url_name'
:
item
.
url_name
,
'previews'
:
get_module_previews
(
request
,
item
),
'previews'
:
get_module_previews
(
request
,
item
),
'metadata'
:
item
.
metadata
})
})
...
@@ -284,6 +286,19 @@ def save_item(request):
...
@@ -284,6 +286,19 @@ def save_item(request):
children
=
request
.
POST
[
'children'
]
children
=
request
.
POST
[
'children'
]
modulestore
()
.
update_children
(
item_location
,
children
)
modulestore
()
.
update_children
(
item_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
request
.
POST
[
'metadata'
]:
posted_metadata
=
request
.
POST
[
'metadata'
]
# fetch original
existing_item
=
modulestore
()
.
get_item
(
item_location
)
# update existing metadata with submitted metadata (which can be partial)
existing_item
.
metadata
.
update
(
posted_metadata
)
modulestore
()
.
update_metadata
(
item_location
,
existing_item
.
metadata
)
# Export the course back to github
# Export the course back to github
# This uses wildcarding to find the course, which requires handling
# This uses wildcarding to find the course, which requires handling
# multiple courses returned, but there should only ever be one
# multiple courses returned, but there should only ever be one
...
...
cms/static/coffee/src/models/module.coffee
View file @
71f39bc4
...
@@ -3,14 +3,26 @@ class CMS.Models.Module extends Backbone.Model
...
@@ -3,14 +3,26 @@ class CMS.Models.Module extends Backbone.Model
defaults
:
defaults
:
data
:
''
data
:
''
children
:
''
children
:
''
metadata
:
{}
loadModule
:
(
element
)
->
loadModule
:
(
element
)
->
elt
=
$
(
element
).
find
(
'.xmodule_edit'
).
first
()
elt
=
$
(
element
).
find
(
'.xmodule_edit'
).
first
()
@
module
=
XModule
.
loadModule
(
elt
)
@
module
=
XModule
.
loadModule
(
elt
)
# find the metadata edit region which should be setup server side,
# so that we can wire up posting back those changes
@
metadata_elt
=
$
(
element
).
find
(
'.metadata_edit'
)
editUrl
:
->
editUrl
:
->
"/edit_item?
#{
$
.
param
(
id
:
@
get
(
'id'
))
}
"
"/edit_item?
#{
$
.
param
(
id
:
@
get
(
'id'
))
}
"
save
:
(
args
...)
->
save
:
(
args
...)
->
@
set
(
data
:
@
module
.
save
())
if
@
module
@
set
(
data
:
@
module
.
save
())
if
@
module
# cdodge: package up metadata which is separated into a number of input fields
# there's probably a better way to do this, but at least this lets me continue to move onwards
if
@
metadata_elt
_metadata
=
{}
# walk through the set of elments which have the 'xmetadata_name' attribute and
# build up a object to pass back to the server on the subsequent POST
_metadata
[
$
(
el
).
data
(
"metadata-name"
)]
=
el
.
value
for
el
in
$
(
'[data-metadata-name]'
,
@
metadata_elt
)
@
set
(
metadata
:
_metadata
)
super
(
args
...)
super
(
args
...)
cms/templates/widgets/html-edit.html
View file @
71f39bc4
<
%
include
file=
"metadata-edit.html"
/>
<section
class=
"html-edit"
>
<section
class=
"html-edit"
>
<textarea
name=
""
class=
"edit-box"
rows=
"8"
cols=
"40"
>
${data}
</textarea>
<textarea
name=
""
class=
"edit-box"
rows=
"8"
cols=
"40"
>
${data}
</textarea>
</section>
</section>
cms/templates/widgets/metadata-edit.html
0 → 100644
View file @
71f39bc4
% if metadata:
<section
class=
"metadata_edit"
>
<h3>
Metadata
</h3>
<ul>
% for keyname in editable_metadata_fields:
<li>
${keyname}:
<input
type=
'text'
data-metadata-name=
'${keyname}'
value=
'${metadata[keyname]}'
size=
'60'
/></li>
% endfor
</ul>
</section>
% endif
cms/templates/widgets/raw-edit.html
View file @
71f39bc4
<
%
include
file=
"metadata-edit.html"
/>
<section
class=
"raw-edit"
>
<section
class=
"raw-edit"
>
<textarea
name=
""
class=
"edit-box"
rows=
"8"
cols=
"40"
>
${data | h}
</textarea>
<textarea
name=
""
class=
"edit-box"
rows=
"8"
cols=
"40"
>
${data | h}
</textarea>
</section>
</section>
cms/templates/widgets/sequence-edit.html
View file @
71f39bc4
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
</ul>
</ul>
</section>
</section>
<
%
include
file=
"metadata-edit.html"
/>
<div
class=
"content"
>
<div
class=
"content"
>
<section
class=
"modules"
>
<section
class=
"modules"
>
<ol>
<ol>
...
...
common/djangoapps/util/json_request.py
View file @
71f39bc4
...
@@ -6,7 +6,9 @@ import json
...
@@ -6,7 +6,9 @@ import json
def
expect_json
(
view_function
):
def
expect_json
(
view_function
):
@wraps
(
view_function
)
@wraps
(
view_function
)
def
expect_json_with_cloned_request
(
request
,
*
args
,
**
kwargs
):
def
expect_json_with_cloned_request
(
request
,
*
args
,
**
kwargs
):
if
request
.
META
[
'CONTENT_TYPE'
]
==
"application/json"
:
# cdodge: fix postback errors in CMS. The POST 'content-type' header can include additional information
# e.g. 'charset', so we can't do a direct string compare
if
request
.
META
[
'CONTENT_TYPE'
]
.
lower
()
.
startswith
(
"application/json"
):
cloned_request
=
copy
.
copy
(
request
)
cloned_request
=
copy
.
copy
(
request
)
cloned_request
.
POST
=
cloned_request
.
POST
.
copy
()
cloned_request
.
POST
=
cloned_request
.
POST
.
copy
()
cloned_request
.
POST
.
update
(
json
.
loads
(
request
.
body
))
cloned_request
.
POST
.
update
(
json
.
loads
(
request
.
body
))
...
...
common/lib/xmodule/xmodule/editing_module.py
View file @
71f39bc4
...
@@ -17,13 +17,13 @@ class EditingDescriptor(MakoModuleDescriptor):
...
@@ -17,13 +17,13 @@ class EditingDescriptor(MakoModuleDescriptor):
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/raw/edit.coffee'
)]}
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/raw/edit.coffee'
)]}
js_module_name
=
"RawDescriptor"
js_module_name
=
"RawDescriptor"
# cdodge: a little refactoring here, since we're basically doing the same thing
# here as with our parent class, let's call into it to get the basic fields
# set and then add our additional fields. Trying to keep it DRY.
def
get_context
(
self
):
def
get_context
(
self
):
return
{
_context
=
MakoModuleDescriptor
.
get_context
(
self
)
'module'
:
self
,
# Add our specific template information (the raw data body)
'data'
:
self
.
definition
.
get
(
'data'
,
''
),
_context
.
update
({
'data'
:
self
.
definition
.
get
(
'data'
,
''
)
})
# TODO (vshnayder): allow children and metadata to be edited.
return
_context
#'children' : self.definition.get('children, ''),
# TODO: show both own metadata and inherited?
#'metadata' : self.own_metadata,
}
common/lib/xmodule/xmodule/mako_module.py
View file @
71f39bc4
from
x_module
import
XModuleDescriptor
,
DescriptorSystem
from
x_module
import
XModuleDescriptor
,
DescriptorSystem
import
logging
class
MakoDescriptorSystem
(
DescriptorSystem
):
class
MakoDescriptorSystem
(
DescriptorSystem
):
...
@@ -31,8 +32,18 @@ class MakoModuleDescriptor(XModuleDescriptor):
...
@@ -31,8 +32,18 @@ class MakoModuleDescriptor(XModuleDescriptor):
"""
"""
Return the context to render the mako template with
Return the context to render the mako template with
"""
"""
return
{
'module'
:
self
}
return
{
'module'
:
self
,
'metadata'
:
self
.
metadata
,
'editable_metadata_fields'
:
self
.
editable_metadata_fields
}
def
get_html
(
self
):
def
get_html
(
self
):
return
self
.
system
.
render_template
(
return
self
.
system
.
render_template
(
self
.
mako_template
,
self
.
get_context
())
self
.
mako_template
,
self
.
get_context
())
# cdodge: encapsulate a means to expose "editable" metadata fields (i.e. not internal system metadata)
@property
def
editable_metadata_fields
(
self
):
subset
=
[
name
for
name
in
self
.
metadata
.
keys
()
if
name
not
in
self
.
system_metadata_fields
]
return
subset
common/lib/xmodule/xmodule/seq_module.py
View file @
71f39bc4
...
@@ -9,6 +9,7 @@ from xmodule.x_module import XModule
...
@@ -9,6 +9,7 @@ from xmodule.x_module import XModule
from
xmodule.progress
import
Progress
from
xmodule.progress
import
Progress
from
xmodule.exceptions
import
NotFoundError
from
xmodule.exceptions
import
NotFoundError
from
pkg_resources
import
resource_string
from
pkg_resources
import
resource_string
from
.editing_module
import
EditingDescriptor
log
=
logging
.
getLogger
(
"mitx.common.lib.seq_module"
)
log
=
logging
.
getLogger
(
"mitx.common.lib.seq_module"
)
...
@@ -95,7 +96,8 @@ class SequenceModule(XModule):
...
@@ -95,7 +96,8 @@ class SequenceModule(XModule):
'element_id'
:
self
.
location
.
html_id
(),
'element_id'
:
self
.
location
.
html_id
(),
'item_id'
:
self
.
id
,
'item_id'
:
self
.
id
,
'position'
:
self
.
position
,
'position'
:
self
.
position
,
'tag'
:
self
.
location
.
category
}
'tag'
:
self
.
location
.
category
}
self
.
content
=
self
.
system
.
render_template
(
'seq_module.html'
,
params
)
self
.
content
=
self
.
system
.
render_template
(
'seq_module.html'
,
params
)
self
.
rendered
=
True
self
.
rendered
=
True
...
...
common/lib/xmodule/xmodule/x_module.py
View file @
71f39bc4
...
@@ -352,6 +352,10 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
...
@@ -352,6 +352,10 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
'data_dir'
'data_dir'
)
)
# cdodge: this is a list of metadata names which are 'system' metadata
# and should not be edited by an end-user
system_metadata_fields
=
[
'data_dir'
]
# A list of descriptor attributes that must be equal for the descriptors to
# A list of descriptor attributes that must be equal for the descriptors to
# be equal
# be equal
equality_attributes
=
(
'definition'
,
'metadata'
,
'location'
,
equality_attributes
=
(
'definition'
,
'metadata'
,
'location'
,
...
...
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