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
39d292a0
Commit
39d292a0
authored
Dec 15, 2012
by
chrisndodge
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1166 from MITx/bug/dhm/dec12
Fixed course info bug (and simplified parsing). Incidentally fixed 2
parents
f5d07b15
7223c8ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
18 deletions
+34
-18
cms/djangoapps/contentstore/course_info_model.py
+21
-13
cms/static/js/models/course_relative.js
+12
-4
cms/static/js/views/settings/main_settings_view.js
+1
-1
No files found.
cms/djangoapps/contentstore/course_info_model.py
View file @
39d292a0
...
@@ -30,20 +30,21 @@ def get_course_updates(location):
...
@@ -30,20 +30,21 @@ def get_course_updates(location):
# Confirm that root is <ol>, iterate over <li>, pull out <h2> subs and then rest of val
# Confirm that root is <ol>, iterate over <li>, pull out <h2> subs and then rest of val
course_upd_collection
=
[]
course_upd_collection
=
[]
if
course_html_parsed
.
tag
==
'ol'
:
if
course_html_parsed
.
tag
==
'ol'
:
# 0 is the
oldest so that new ones get unique idx
# 0 is the
newest
for
idx
,
update
in
enumerate
(
course_html_parsed
.
iter
(
"li"
)
):
for
idx
,
update
in
enumerate
(
course_html_parsed
):
if
(
len
(
update
)
==
0
):
if
(
len
(
update
)
==
0
):
continue
continue
elif
(
len
(
update
)
==
1
):
elif
(
len
(
update
)
==
1
):
content
=
update
.
find
(
"h2"
)
.
tail
# could enforce that update[0].tag == 'h2'
content
=
update
[
0
]
.
tail
else
:
else
:
content
=
etree
.
tostring
(
update
[
1
])
content
=
etree
.
tostring
(
update
[
1
])
course_upd_collection
.
append
({
"id"
:
location_base
+
"/"
+
str
(
idx
),
# make the id on the client be 1..len w/ 1 being the oldest and len being the newest
course_upd_collection
.
append
({
"id"
:
location_base
+
"/"
+
str
(
len
(
course_html_parsed
)
-
idx
),
"date"
:
update
.
findtext
(
"h2"
),
"date"
:
update
.
findtext
(
"h2"
),
"content"
:
content
})
"content"
:
content
})
# return newest to oldest
course_upd_collection
.
reverse
()
return
course_upd_collection
return
course_upd_collection
def
update_course_updates
(
location
,
update
,
passed_id
=
None
):
def
update_course_updates
(
location
,
update
,
passed_id
=
None
):
...
@@ -72,7 +73,9 @@ def update_course_updates(location, update, passed_id=None):
...
@@ -72,7 +73,9 @@ def update_course_updates(location, update, passed_id=None):
if
course_html_parsed
.
tag
==
'ol'
:
if
course_html_parsed
.
tag
==
'ol'
:
# ??? Should this use the id in the json or in the url or does it matter?
# ??? Should this use the id in the json or in the url or does it matter?
if
passed_id
:
if
passed_id
:
element
=
course_html_parsed
.
findall
(
"li"
)[
get_idx
(
passed_id
)]
idx
=
get_idx
(
passed_id
)
# idx is count from end of list
element
=
course_html_parsed
[
-
idx
]
element
[
0
]
.
text
=
update
[
'date'
]
element
[
0
]
.
text
=
update
[
'date'
]
if
(
len
(
element
)
==
1
):
if
(
len
(
element
)
==
1
):
if
new_html_parsed
is
not
None
:
if
new_html_parsed
is
not
None
:
...
@@ -87,15 +90,17 @@ def update_course_updates(location, update, passed_id=None):
...
@@ -87,15 +90,17 @@ def update_course_updates(location, update, passed_id=None):
element
.
pop
(
1
)
element
.
pop
(
1
)
element
[
0
]
.
tail
=
update
[
'content'
]
element
[
0
]
.
tail
=
update
[
'content'
]
else
:
else
:
idx
=
len
(
course_html_parsed
.
findall
(
"li"
))
element
=
etree
.
Element
(
"li"
)
passed_id
=
course_updates
.
location
.
url
()
+
"/"
+
str
(
idx
)
course_html_parsed
.
insert
(
0
,
element
)
element
=
etree
.
SubElement
(
course_html_parsed
,
"li"
)
date_element
=
etree
.
SubElement
(
element
,
"h2"
)
date_element
=
etree
.
SubElement
(
element
,
"h2"
)
date_element
.
text
=
update
[
'date'
]
date_element
.
text
=
update
[
'date'
]
if
new_html_parsed
is
not
None
:
if
new_html_parsed
is
not
None
:
element
.
append
(
new_html_parsed
)
element
.
append
(
new_html_parsed
)
else
:
else
:
date_element
.
tail
=
update
[
'content'
]
date_element
.
tail
=
update
[
'content'
]
idx
=
len
(
course_html_parsed
)
passed_id
=
course_updates
.
location
.
url
()
+
"/"
+
str
(
idx
)
# update db record
# update db record
course_updates
.
definition
[
'data'
]
=
etree
.
tostring
(
course_html_parsed
)
course_updates
.
definition
[
'data'
]
=
etree
.
tostring
(
course_html_parsed
)
...
@@ -127,9 +132,11 @@ def delete_course_update(location, update, passed_id):
...
@@ -127,9 +132,11 @@ def delete_course_update(location, update, passed_id):
if
course_html_parsed
.
tag
==
'ol'
:
if
course_html_parsed
.
tag
==
'ol'
:
# ??? Should this use the id in the json or in the url or does it matter?
# ??? Should this use the id in the json or in the url or does it matter?
element_to_delete
=
course_html_parsed
.
xpath
(
'/ol/li[position()='
+
str
(
get_idx
(
passed_id
)
+
1
)
+
"]"
)
idx
=
get_idx
(
passed_id
)
# idx is count from end of list
element_to_delete
=
course_html_parsed
[
-
idx
]
if
element_to_delete
:
if
element_to_delete
:
course_html_parsed
.
remove
(
element_to_delete
[
0
]
)
course_html_parsed
.
remove
(
element_to_delete
)
# update db record
# update db record
course_updates
.
definition
[
'data'
]
=
etree
.
tostring
(
course_html_parsed
)
course_updates
.
definition
[
'data'
]
=
etree
.
tostring
(
course_html_parsed
)
...
@@ -143,6 +150,6 @@ def get_idx(passed_id):
...
@@ -143,6 +150,6 @@ def get_idx(passed_id):
From the url w/ idx appended, get the idx.
From the url w/ idx appended, get the idx.
"""
"""
# TODO compile this regex into a class static and reuse for each call
# TODO compile this regex into a class static and reuse for each call
idx_matcher
=
re
.
search
(
r'.*/(\d
)+
$'
,
passed_id
)
idx_matcher
=
re
.
search
(
r'.*/(\d
+)
$'
,
passed_id
)
if
idx_matcher
:
if
idx_matcher
:
return
int
(
idx_matcher
.
group
(
1
))
return
int
(
idx_matcher
.
group
(
1
))
\ No newline at end of file
cms/static/js/models/course_relative.js
View file @
39d292a0
...
@@ -34,10 +34,10 @@ CMS.Models.Location = Backbone.Model.extend({
...
@@ -34,10 +34,10 @@ CMS.Models.Location = Backbone.Model.extend({
this
.
_fieldPattern
.
lastIndex
=
this
.
_tagPattern
.
lastIndex
+
1
;
// skip over the colon
this
.
_fieldPattern
.
lastIndex
=
this
.
_tagPattern
.
lastIndex
+
1
;
// skip over the colon
return
{
return
{
tag
:
foundTag
[
0
],
tag
:
foundTag
[
0
],
org
:
this
.
_fieldPattern
.
exec
(
payload
)[
0
]
,
org
:
this
.
getNextField
(
payload
)
,
course
:
this
.
_fieldPattern
.
exec
(
payload
)[
0
]
,
course
:
this
.
getNextField
(
payload
)
,
category
:
this
.
_fieldPattern
.
exec
(
payload
)[
0
]
,
category
:
this
.
getNextField
(
payload
)
,
name
:
this
.
_fieldPattern
.
exec
(
payload
)[
0
]
name
:
this
.
getNextField
(
payload
)
}
}
}
}
else
return
null
;
else
return
null
;
...
@@ -45,6 +45,14 @@ CMS.Models.Location = Backbone.Model.extend({
...
@@ -45,6 +45,14 @@ CMS.Models.Location = Backbone.Model.extend({
else
{
else
{
return
payload
;
return
payload
;
}
}
},
getNextField
:
function
(
payload
)
{
try
{
return
this
.
_fieldPattern
.
exec
(
payload
)[
0
];
}
catch
(
err
)
{
return
""
;
}
}
}
});
});
...
...
cms/static/js/views/settings/main_settings_view.js
View file @
39d292a0
...
@@ -331,7 +331,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
...
@@ -331,7 +331,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
// instantiates an editor template for each update in the collection
// instantiates an editor template for each update in the collection
// Because this calls render, put it after everything which render may depend upon to prevent race condition.
// Because this calls render, put it after everything which render may depend upon to prevent race condition.
window
.
templateLoader
.
loadRemoteTemplate
(
"course_
info_update
"
,
window
.
templateLoader
.
loadRemoteTemplate
(
"course_
grade_policy
"
,
"/static/client_templates/course_grade_policy.html"
,
"/static/client_templates/course_grade_policy.html"
,
function
(
raw_template
)
{
function
(
raw_template
)
{
self
.
template
=
_
.
template
(
raw_template
);
self
.
template
=
_
.
template
(
raw_template
);
...
...
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