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
6088a926
Commit
6088a926
authored
Jan 20, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add showanswer="past_due" and tests
parent
ea091a6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
17 deletions
+65
-17
common/lib/xmodule/xmodule/capa_module.py
+20
-15
common/lib/xmodule/xmodule/tests/test_capa_module.py
+45
-2
No files found.
common/lib/xmodule/xmodule/capa_module.py
View file @
6088a926
...
...
@@ -389,38 +389,43 @@ class CapaModule(XModule):
})
return
json
.
dumps
(
d
,
cls
=
ComplexEncoder
)
def
is_past_due
(
self
):
"""
Is it now past this problem's due date, including grace period?
"""
return
(
self
.
close_date
is
not
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
close_date
)
def
closed
(
self
):
''' Is the student still allowed to submit answers? '''
if
self
.
attempts
==
self
.
max_attempts
:
return
True
if
self
.
close_date
is
not
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
close_date
:
if
self
.
is_past_due
()
:
return
True
return
False
def
answer_available
(
self
):
''' Is the user allowed to see an answer?
'''
Is the user allowed to see an answer?
'''
if
self
.
show_answer
==
''
:
return
False
if
self
.
show_answer
==
"never"
:
elif
self
.
show_answer
==
"never"
:
return
False
# Admins can see the answer, unless the problem explicitly prevents it
if
self
.
system
.
user_is_staff
:
elif
self
.
system
.
user_is_staff
:
# This i after the 'never' check because admins can see the answer
# unless the problem explicitly prevents it
return
True
if
self
.
show_answer
==
'attempted'
:
elif
self
.
show_answer
==
'attempted'
:
return
self
.
attempts
>
0
if
self
.
show_answer
==
'answered'
:
elif
self
.
show_answer
==
'answered'
:
return
self
.
lcp
.
done
if
self
.
show_answer
==
'closed'
:
elif
self
.
show_answer
==
'closed'
:
return
self
.
closed
()
if
self
.
show_answer
==
'always'
:
elif
self
.
show_answer
==
'past_due'
:
return
self
.
is_past_due
()
elif
self
.
show_answer
==
'always'
:
return
True
return
False
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
6088a926
...
...
@@ -138,10 +138,11 @@ class CapaModuleTest(unittest.TestCase):
def
test_showanswer_closed
(
self
):
# can see after attempts used up
# can see after attempts used up
, even with due date in the future
used_all_attempts
=
CapaFactory
.
create
(
showanswer
=
'closed'
,
max_attempts
=
"1"
,
attempts
=
"1"
)
attempts
=
"1"
,
due
=
self
.
tomorrow_str
)
self
.
assertTrue
(
used_all_attempts
.
answer_available
())
...
...
@@ -152,6 +153,7 @@ class CapaModuleTest(unittest.TestCase):
due
=
self
.
yesterday_str
)
self
.
assertTrue
(
after_due_date
.
answer_available
())
# can't see because attempts left
attempts_left_open
=
CapaFactory
.
create
(
showanswer
=
'closed'
,
max_attempts
=
"1"
,
...
...
@@ -169,4 +171,45 @@ class CapaModuleTest(unittest.TestCase):
def
test_showanswer_past_due
(
self
):
"""
With showanswer="past_due" should only show answer after the problem is closed
for everyone--e.g. after due date + grace period.
"""
# can see after attempts used up, even with due date in the future
used_all_attempts
=
CapaFactory
.
create
(
showanswer
=
'past_due'
,
max_attempts
=
"1"
,
attempts
=
"1"
,
due
=
self
.
tomorrow_str
)
self
.
assertFalse
(
used_all_attempts
.
answer_available
())
# can see after due date
past_due_date
=
CapaFactory
.
create
(
showanswer
=
'past_due'
,
max_attempts
=
"1"
,
attempts
=
"0"
,
due
=
self
.
yesterday_str
)
self
.
assertTrue
(
past_due_date
.
answer_available
())
# can't see because attempts left
attempts_left_open
=
CapaFactory
.
create
(
showanswer
=
'past_due'
,
max_attempts
=
"1"
,
attempts
=
"0"
,
due
=
self
.
tomorrow_str
)
self
.
assertFalse
(
attempts_left_open
.
answer_available
())
# Can't see because grace period hasn't expired, even though have no more
# attempts.
still_in_grace
=
CapaFactory
.
create
(
showanswer
=
'past_due'
,
max_attempts
=
"1"
,
attempts
=
"1"
,
due
=
self
.
yesterday_str
,
graceperiod
=
self
.
two_day_delta_str
)
self
.
assertFalse
(
still_in_grace
.
answer_available
())
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