Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
OpenEdx
problem-builder
Commits
c5879dde
Commit
c5879dde
authored
Jul 24, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow toggling show_title behaviour during upgrade
parent
80f90e37
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
9 deletions
+39
-9
problem_builder/v1/tests/test_upgrade.py
+2
-2
problem_builder/v1/upgrade.py
+14
-4
problem_builder/v1/xml_changes.py
+23
-3
No files found.
problem_builder/v1/tests/test_upgrade.py
View file @
c5879dde
...
...
@@ -23,7 +23,7 @@ Test that we can upgrade from mentoring v1 to problem builder (v2).
import
ddt
from
lxml
import
etree
from
problem_builder
import
MentoringBlock
from
problem_builder.v1.xml_changes
import
convert_xml_
v1_
to_v2
from
problem_builder.v1.xml_changes
import
convert_xml_to_v2
import
os.path
from
StringIO
import
StringIO
import
unittest
...
...
@@ -66,7 +66,7 @@ class TestUpgrade(unittest.TestCase):
parser
=
etree
.
XMLParser
(
remove_blank_text
=
True
)
xml_root
=
etree
.
parse
(
StringIO
(
old_block
.
xml_content
),
parser
=
parser
)
.
getroot
()
convert_xml_
v1_
to_v2
(
xml_root
)
convert_xml_to_v2
(
xml_root
)
converted_block
=
self
.
create_block_from_node
(
xml_root
)
with
open
(
"{}/{}_new.xml"
.
format
(
xml_path
,
file_name
))
as
xmlfile
:
...
...
problem_builder/v1/upgrade.py
View file @
c5879dde
...
...
@@ -25,6 +25,9 @@ optimized for editing in Studio.
To run the script on devstack:
SERVICE_VARIANT=cms DJANGO_SETTINGS_MODULE="cms.envs.devstack" python -m problem_builder.v1.upgrade [course id here]
You can add "--version=v0" at the end of the command to upgrade from the oldest xblock-mentoring
instance which was kept on gsehub's GitHub account.
"""
import
logging
from
lxml
import
etree
...
...
@@ -35,10 +38,10 @@ import sys
import
warnings
from
courseware.models
import
StudentModule
from
.studio_xml_utils
import
studio_update_from_node
from
.xml_changes
import
convert_xml_
v1_
to_v2
from
.xml_changes
import
convert_xml_to_v2
def
upgrade_block
(
store
,
block
):
def
upgrade_block
(
store
,
block
,
from_version
=
"v1"
):
"""
Given a MentoringBlock "block" with old-style (v1) data in its "xml_content" field, parse
the XML and re-create the block with new-style (v2) children and settings.
...
...
@@ -51,7 +54,7 @@ def upgrade_block(store, block):
assert
root
.
tag
==
"mentoring"
with
warnings
.
catch_warnings
(
record
=
True
)
as
warnings_caught
:
warnings
.
simplefilter
(
"always"
)
convert_xml_
v1_to_v2
(
root
)
convert_xml_
to_v2
(
root
,
from_version
=
from_version
)
for
warning
in
warnings_caught
:
print
(
u" ➔ {}"
.
format
(
unicode
(
warning
.
message
)))
...
...
@@ -140,6 +143,13 @@ if __name__ == '__main__':
except
(
IndexError
,
InvalidKeyError
):
sys
.
exit
(
"Need a course ID argument like 'HarvardX/GSE1.1x/3T2014' or 'course-v1:HarvardX+B101+2015'"
)
from_version
=
"v1"
if
len
(
sys
.
argv
)
>
2
:
if
sys
.
argv
[
2
]
==
"--version=v0"
:
from_version
=
"v0"
else
:
sys
.
exit
(
"invalid second argument: {}"
.
format
(
' '
.
join
(
sys
.
argv
[
2
:])))
store
=
modulestore
()
course
=
store
.
get_course
(
course_id
)
if
course
is
None
:
...
...
@@ -196,6 +206,6 @@ if __name__ == '__main__':
block
=
course
.
runtime
.
get_block
(
block_id
)
print
(
u" ➔ Upgrading block {} of {} -
\"
{}
\"
"
.
format
(
count
,
total
,
block
.
url_name
))
count
+=
1
upgrade_block
(
store
,
block
)
upgrade_block
(
store
,
block
,
from_version
)
print
(
u" ➔ Complete."
)
problem_builder/v1/xml_changes.py
View file @
c5879dde
...
...
@@ -380,8 +380,21 @@ class CommaSeparatedListToJson(Change):
self
.
node
.
attrib
[
attribute
]
=
self
.
_convert_value
(
self
.
node
.
attrib
[
attribute
])
class
OptionalShowTitleDefaultToFalse
(
Change
):
"""
In recent versions of mentoring, show_title defaults to True. In old versions there were no
titles. If upgrading an old version, show_title should be set False.
"""
@staticmethod
def
applies_to
(
node
):
return
node
.
tag
in
(
"pb-answer"
,
"pb-mrq"
,
"pb-mcq"
,
"pb-rating"
)
and
(
"show_title"
not
in
node
.
attrib
)
def
apply
(
self
):
self
.
node
.
attrib
[
"show_title"
]
=
"false"
# An *ordered* list of all XML schema changes:
xml_changes
=
(
xml_changes
=
[
RenameMentoringTag
,
PrefixTags
,
HideTitle
,
...
...
@@ -398,13 +411,20 @@ xml_changes = (
AlternatingHTMLToQuestions
,
SharedHeaderToHTML
,
CommaSeparatedListToJson
,
)
]
def
convert_xml_
v1_to_v2
(
node
):
def
convert_xml_
to_v2
(
node
,
from_version
=
"v1"
):
"""
Given an XML node, re-structure it as needed to convert it from v1 style to v2 style XML.
If from_version is set to "v0", then the "show_title" attribute on each question will be set
to False, for compatibility with old versions of the mentoring block that didn't have
question titles at all.
"""
if
from_version
==
"v0"
:
xml_changes
.
append
(
OptionalShowTitleDefaultToFalse
)
# Apply each individual type of change one at a time:
for
change
in
xml_changes
:
# Walk the XML tree once and figure out all the changes we will need.
...
...
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