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
d78f09d1
Commit
d78f09d1
authored
Oct 15, 2014
by
dragonfi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use staticmethod to test if xml content has default value
parent
b4bb9b26
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
6 deletions
+29
-6
mentoring/light_children.py
+8
-4
mentoring/mentoring.py
+21
-2
No files found.
mentoring/light_children.py
View file @
d78f09d1
...
@@ -86,11 +86,15 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
...
@@ -86,11 +86,15 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
block
=
runtime
.
construct_xblock_from_class
(
cls
,
keys
)
block
=
runtime
.
construct_xblock_from_class
(
cls
,
keys
)
cls
.
init_block_from_node
(
block
,
node
,
node
.
items
())
cls
.
init_block_from_node
(
block
,
node
,
node
.
items
())
xml_content_value
=
getattr
(
block
,
'xml_content'
,
None
)
def
_is_default
(
value
):
xml_content_field
=
getattr
(
block
.
__class__
,
'xml_content'
,
None
)
xml_content_field
=
getattr
(
block
.
__class__
,
'xml_content'
,
None
)
default_xml_content
=
getattr
(
xml_content_field
,
'default'
,
None
)
default_value
=
getattr
(
xml_content_field
,
'default'
,
None
)
return
value
==
default_value
if
xml_content_value
==
default_xml_content
:
is_default
=
getattr
(
block
,
'is_default_xml_content'
,
_is_default
)
xml_content
=
getattr
(
block
,
'xml_content'
,
None
)
if
is_default
(
xml_content
):
block
.
xml_content
=
etree
.
tostring
(
node
)
block
.
xml_content
=
etree
.
tostring
(
node
)
return
block
return
block
...
...
mentoring/mentoring.py
View file @
d78f09d1
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
import
logging
import
logging
import
uuid
import
uuid
import
re
from
collections
import
namedtuple
from
collections
import
namedtuple
from
lxml
import
etree
from
lxml
import
etree
...
@@ -48,11 +50,24 @@ from .utils import loader
...
@@ -48,11 +50,24 @@ from .utils import loader
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
default_xml_content
():
def
_
default_xml_content
():
return
loader
.
render_template
(
return
loader
.
render_template
(
'templates/xml/mentoring_default.xml'
,
'templates/xml/mentoring_default.xml'
,
{
'url_name'
:
'mentoring-{}'
.
format
(
uuid
.
uuid4
())})
{
'url_name'
:
'mentoring-{}'
.
format
(
uuid
.
uuid4
())})
def
_is_default_xml_content
(
value
):
UUID_PATTERN
=
'[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}'
DUMMY_UUID
=
'12345678-1234-1234-1234-123456789abc'
expected
=
_default_xml_content
()
expected
=
re
.
sub
(
UUID_PATTERN
,
DUMMY_UUID
,
expected
)
value
=
re
.
sub
(
UUID_PATTERN
,
DUMMY_UUID
,
value
)
return
value
==
expected
# Classes ###########################################################
# Classes ###########################################################
Score
=
namedtuple
(
"Score"
,
[
"raw"
,
"percentage"
,
"correct"
,
"incorrect"
,
"partially_correct"
])
Score
=
namedtuple
(
"Score"
,
[
"raw"
,
"percentage"
,
"correct"
,
"incorrect"
,
"partially_correct"
])
...
@@ -67,6 +82,10 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
...
@@ -67,6 +82,10 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
ok to continue.
ok to continue.
"""
"""
@staticmethod
def
is_default_xml_content
(
value
):
return
_is_default_xml_content
(
value
)
attempted
=
Boolean
(
help
=
"Has the student attempted this mentoring step?"
,
attempted
=
Boolean
(
help
=
"Has the student attempted this mentoring step?"
,
default
=
False
,
scope
=
Scope
.
user_state
)
default
=
False
,
scope
=
Scope
.
user_state
)
completed
=
Boolean
(
help
=
"Has the student completed this mentoring step?"
,
completed
=
Boolean
(
help
=
"Has the student completed this mentoring step?"
,
...
@@ -80,7 +99,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
...
@@ -80,7 +99,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
enforce_dependency
=
Boolean
(
help
=
"Should the next step be the current block to complete?"
,
enforce_dependency
=
Boolean
(
help
=
"Should the next step be the current block to complete?"
,
default
=
False
,
scope
=
Scope
.
content
,
enforce_type
=
True
)
default
=
False
,
scope
=
Scope
.
content
,
enforce_type
=
True
)
display_submit
=
Boolean
(
help
=
"Allow to submit current block?"
,
default
=
True
,
scope
=
Scope
.
content
)
display_submit
=
Boolean
(
help
=
"Allow to submit current block?"
,
default
=
True
,
scope
=
Scope
.
content
)
xml_content
=
String
(
help
=
"XML content"
,
default
=
default_xml_content
()
,
scope
=
Scope
.
content
)
xml_content
=
String
(
help
=
"XML content"
,
default
=
_default_xml_content
,
scope
=
Scope
.
content
)
weight
=
Float
(
help
=
"Defines the maximum total grade of the block."
,
weight
=
Float
(
help
=
"Defines the maximum total grade of the block."
,
default
=
1
,
scope
=
Scope
.
content
,
enforce_type
=
True
)
default
=
1
,
scope
=
Scope
.
content
,
enforce_type
=
True
)
num_attempts
=
Integer
(
help
=
"Number of attempts a user has answered for this questions"
,
num_attempts
=
Integer
(
help
=
"Number of attempts a user has answered for this questions"
,
...
...
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