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
1fb4354a
Commit
1fb4354a
authored
Jul 30, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap malformed course_update rather than silently failing update
parent
27d32f19
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
22 deletions
+32
-22
cms/djangoapps/contentstore/course_info_model.py
+32
-22
No files found.
cms/djangoapps/contentstore/course_info_model.py
View file @
1fb4354a
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
lxml
import
html
from
lxml
import
html
,
etree
import
re
import
re
from
django.http
import
HttpResponseBadRequest
from
django.http
import
HttpResponseBadRequest
import
logging
import
logging
...
@@ -74,34 +74,44 @@ def update_course_updates(location, update, passed_id=None):
...
@@ -74,34 +74,44 @@ def update_course_updates(location, update, passed_id=None):
escaped
=
django
.
utils
.
html
.
escape
(
course_updates
.
data
)
escaped
=
django
.
utils
.
html
.
escape
(
course_updates
.
data
)
course_html_parsed
=
html
.
fromstring
(
"<ol><li>"
+
escaped
+
"</li></ol>"
)
course_html_parsed
=
html
.
fromstring
(
"<ol><li>"
+
escaped
+
"</li></ol>"
)
# if there's no ol, create it
if
course_html_parsed
.
tag
!=
'ol'
:
# surround whatever's there w/ an ol
if
course_html_parsed
.
tag
!=
'li'
:
# but first wrap in an li
li
=
etree
.
Element
(
'li'
)
li
.
append
(
course_html_parsed
)
course_html_parsed
=
li
ol
=
etree
.
Element
(
'ol'
)
ol
.
append
(
course_html_parsed
)
course_html_parsed
=
ol
# No try/catch b/c failure generates an error back to client
# No try/catch b/c failure generates an error back to client
new_html_parsed
=
html
.
fromstring
(
'<li><h2>'
+
update
[
'date'
]
+
'</h2>'
+
update
[
'content'
]
+
'</li>'
)
new_html_parsed
=
html
.
fromstring
(
'<li><h2>'
+
update
[
'date'
]
+
'</h2>'
+
update
[
'content'
]
+
'</li>'
)
# Confirm that root is <ol>, iterate over <li>, pull out <h2> subs and then rest of val
# ??? Should this use the id in the json or in the url or does it matter?
if
course_html_parsed
.
tag
==
'ol'
:
if
passed_id
is
not
None
:
# ??? Should this use the id in the json or in the url or does it matter?
idx
=
get_idx
(
passed_id
)
if
passed_id
is
not
None
:
# idx is count from end of list
idx
=
get_idx
(
passed_id
)
course_html_parsed
[
-
idx
]
=
new_html_parsed
# idx is count from end of list
else
:
course_html_parsed
[
-
idx
]
=
new_html_parsed
course_html_parsed
.
insert
(
0
,
new_html_parsed
)
else
:
course_html_parsed
.
insert
(
0
,
new_html_parsed
)
idx
=
len
(
course_html_parsed
)
idx
=
len
(
course_html_parsed
)
passed_id
=
course_updates
.
location
.
url
()
+
"/"
+
str
(
idx
)
passed_id
=
course_updates
.
location
.
url
()
+
"/"
+
str
(
idx
)
# update db record
# update db record
course_updates
.
data
=
html
.
tostring
(
course_html_parsed
)
course_updates
.
data
=
html
.
tostring
(
course_html_parsed
)
modulestore
(
'direct'
)
.
update_item
(
location
,
course_updates
.
data
)
modulestore
(
'direct'
)
.
update_item
(
location
,
course_updates
.
data
)
if
(
len
(
new_html_parsed
)
==
1
):
if
(
len
(
new_html_parsed
)
==
1
):
content
=
new_html_parsed
[
0
]
.
tail
content
=
new_html_parsed
[
0
]
.
tail
else
:
else
:
content
=
"
\n
"
.
join
([
html
.
tostring
(
ele
)
for
ele
in
new_html_parsed
[
1
:]])
content
=
"
\n
"
.
join
([
html
.
tostring
(
ele
)
for
ele
in
new_html_parsed
[
1
:]])
return
{
"id"
:
passed_id
,
return
{
"id"
:
passed_id
,
"date"
:
update
[
'date'
],
"date"
:
update
[
'date'
],
"content"
:
content
}
"content"
:
content
}
def
delete_course_update
(
location
,
update
,
passed_id
):
def
delete_course_update
(
location
,
update
,
passed_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