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
d5e0fb3e
Commit
d5e0fb3e
authored
Jun 07, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renaming item to only_one, and adding documentation
parent
5101e575
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
common/lib/xmodule/capa_module.py
+18
-13
No files found.
common/lib/xmodule/capa_module.py
View file @
d5e0fb3e
...
...
@@ -18,7 +18,12 @@ log = logging.getLogger("mitx.courseware")
TIMEDELTA_REGEX
=
re
.
compile
(
r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?) hour(?:s?))?(\s)?((?P<minutes>\d+?) minute(?:s)?)?(\s)?((?P<seconds>\d+?) second(?:s)?)?$'
)
def
item
(
l
,
default
=
""
,
process
=
lambda
x
:
x
):
def
only_one
(
lst
,
default
=
""
,
process
=
lambda
x
:
x
):
"""
If lst is empty, returns default
If lst has a single element, applies process to that element and returns it
Otherwise, raises an exeception
"""
if
len
(
l
)
==
0
:
return
default
elif
len
(
l
)
==
1
:
...
...
@@ -163,18 +168,18 @@ class Module(XModule):
dom2
=
etree
.
fromstring
(
xml
)
self
.
explanation
=
"problems/"
+
item
(
dom2
.
xpath
(
'/problem/@explain'
),
default
=
"closed"
)
# TODO: Should be converted to: self.explanation=
item
(dom2.xpath('/problem/@explain'), default="closed")
self
.
explain_available
=
item
(
dom2
.
xpath
(
'/problem/@explain_available'
))
self
.
explanation
=
"problems/"
+
only_one
(
dom2
.
xpath
(
'/problem/@explain'
),
default
=
"closed"
)
# TODO: Should be converted to: self.explanation=
only_one
(dom2.xpath('/problem/@explain'), default="closed")
self
.
explain_available
=
only_one
(
dom2
.
xpath
(
'/problem/@explain_available'
))
display_due_date_string
=
item
(
dom2
.
xpath
(
'/problem/@due'
))
display_due_date_string
=
only_one
(
dom2
.
xpath
(
'/problem/@due'
))
if
len
(
display_due_date_string
)
>
0
:
self
.
display_due_date
=
dateutil
.
parser
.
parse
(
display_due_date_string
)
#log.debug("Parsed " + display_due_date_string + " to " + str(self.display_due_date))
else
:
self
.
display_due_date
=
None
grace_period_string
=
item
(
dom2
.
xpath
(
'/problem/@graceperiod'
))
grace_period_string
=
only_one
(
dom2
.
xpath
(
'/problem/@graceperiod'
))
if
len
(
grace_period_string
)
>
0
and
self
.
display_due_date
:
self
.
grace_period
=
parse_timedelta
(
grace_period_string
)
self
.
close_date
=
self
.
display_due_date
+
self
.
grace_period
...
...
@@ -183,18 +188,18 @@ class Module(XModule):
self
.
grace_period
=
None
self
.
close_date
=
self
.
display_due_date
self
.
max_attempts
=
item
(
dom2
.
xpath
(
'/problem/@attempts'
))
self
.
max_attempts
=
only_one
(
dom2
.
xpath
(
'/problem/@attempts'
))
if
len
(
self
.
max_attempts
)
>
0
:
self
.
max_attempts
=
int
(
self
.
max_attempts
)
else
:
self
.
max_attempts
=
None
self
.
show_answer
=
item
(
dom2
.
xpath
(
'/problem/@showanswer'
))
self
.
show_answer
=
only_one
(
dom2
.
xpath
(
'/problem/@showanswer'
))
if
self
.
show_answer
==
""
:
self
.
show_answer
=
"closed"
self
.
rerandomize
=
item
(
dom2
.
xpath
(
'/problem/@rerandomize'
))
self
.
rerandomize
=
only_one
(
dom2
.
xpath
(
'/problem/@rerandomize'
))
if
self
.
rerandomize
==
""
or
self
.
rerandomize
==
"always"
or
self
.
rerandomize
==
"true"
:
self
.
rerandomize
=
"always"
elif
self
.
rerandomize
==
"false"
or
self
.
rerandomize
==
"per_student"
:
...
...
@@ -209,10 +214,10 @@ class Module(XModule):
if
state
!=
None
and
'attempts'
in
state
:
self
.
attempts
=
state
[
'attempts'
]
# TODO: Should be: self.filename=
item
(dom2.xpath('/problem/@filename'))
self
.
filename
=
"problems/"
+
item
(
dom2
.
xpath
(
'/problem/@filename'
))
+
".xml"
self
.
name
=
item
(
dom2
.
xpath
(
'/problem/@name'
))
self
.
weight
=
item
(
dom2
.
xpath
(
'/problem/@weight'
))
# TODO: Should be: self.filename=
only_one
(dom2.xpath('/problem/@filename'))
self
.
filename
=
"problems/"
+
only_one
(
dom2
.
xpath
(
'/problem/@filename'
))
+
".xml"
self
.
name
=
only_one
(
dom2
.
xpath
(
'/problem/@name'
))
self
.
weight
=
only_one
(
dom2
.
xpath
(
'/problem/@weight'
))
if
self
.
rerandomize
==
'never'
:
seed
=
1
else
:
...
...
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