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
d95052e1
Commit
d95052e1
authored
Feb 08, 2013
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working proto
parent
4b148f9a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
common/lib/xmodule/xmodule/conditional_module.py
+19
-12
No files found.
common/lib/xmodule/xmodule/conditional_module.py
View file @
d95052e1
...
...
@@ -34,6 +34,9 @@ class ConditionalModule(XModule):
contents
=
String
(
scope
=
Scope
.
content
)
show_modules
=
String
(
scope
=
Scope
.
content
)
conditions_map
=
{
'poll_answer'
:
'poll_answer'
,
'compeleted'
:
'is_competed()'
}
def
_get_required_modules
(
self
):
self
.
required_modules
=
[]
for
loc
in
self
.
descriptor
.
required_module_locations
:
...
...
@@ -42,34 +45,38 @@ class ConditionalModule(XModule):
#log.debug('required_modules=%s' % (self.required_modules))
def
_get_condition
(
self
):
return
self
.
descriptor
.
xml_attributes
.
get
(
'condition'
,
''
)
# get first valid contition
for
key
in
self
.
conditions_map
:
if
self
.
descriptor
.
xml_attributes
.
get
(
key
,
None
):
return
key
def
is_condition_satisfied
(
self
):
self
.
_get_required_modules
()
self
.
condition
=
self
.
_get_condition
()
if
self
.
condition
==
'
require_
completed'
:
if
self
.
condition
==
'completed'
:
# all required modules must be completed, as determined by
# the modules .is_completed() method
for
module
in
self
.
required_modules
:
#log.debug('in is_condition_satisfied; student_answers=%s' % module.lcp.student_answers)
#log.debug('in is_condition_satisfied; instance_state=%s' % module.instance_state)
if
not
hasattr
(
module
,
'is_completed'
):
if
not
hasattr
(
module
,
self
.
conditions_map
.
get
(
'poll_answer'
)
):
raise
Exception
(
'Error in conditional module: required module
%
s has no .is_completed() method'
%
module
)
if
not
module
.
is_completed
():
if
not
getattr
(
module
,
self
.
conditions_map
.
get
(
'completed'
))
():
log
.
debug
(
'conditional module:
%
s not completed'
%
module
)
return
False
else
:
log
.
debug
(
'conditional module:
%
s IS completed'
%
module
)
return
True
elif
self
.
condition
==
'answer'
:
elif
self
.
condition
==
'
poll_
answer'
:
for
module
in
self
.
required_modules
:
if
not
hasattr
(
module
,
'poll_answer'
):
if
not
hasattr
(
module
,
self
.
conditions_map
.
get
(
self
.
condition
)
):
raise
Exception
(
'Error in conditional module: required module
%
s has no poll_answer field'
%
module
)
answer
=
self
.
descriptor
.
xml_attributes
.
get
(
'answer'
)
if
answer
==
'unanswered'
and
module
.
poll_answer
:
module_value
=
getattr
(
module
,
self
.
conditions_map
.
get
(
self
.
condition
))
answer
=
self
.
descriptor
.
xml_attributes
.
get
(
self
.
condition
)
if
answer
==
'unanswered'
and
module_value
:
return
False
if
module
.
poll_answer
!=
answer
:
if
module
_value
!=
answer
:
return
False
return
True
else
:
...
...
@@ -107,10 +114,10 @@ class ConditionalModule(XModule):
return
json
.
dumps
({
'html'
:
[
html
]})
if
self
.
contents
is
None
:
import
ipdb
;
ipdb
.
set_trace
()
#
import ipdb; ipdb.set_trace()
# self.contents = [child.get_html() for child in self.get_display_items()]
self
.
contents
=
[
self
.
system
.
get_module
(
x
)
.
get_html
()
for
x
in
self
.
modules_to_show
]
self
.
contents
+
=
[
self
.
system
.
get_module
(
child_descriptor
.
location
)
.
get_html
()
#
self.contents = [self.system.get_module(x).get_html() for x in self.modules_to_show]
self
.
contents
=
[
self
.
system
.
get_module
(
child_descriptor
.
location
)
.
get_html
()
for
child_descriptor
in
self
.
descriptor
.
get_children
()]
...
...
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