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
9e18dd86
Commit
9e18dd86
authored
Feb 08, 2013
by
Vasyl Nakvasiuk
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
47094a1f
d95052e1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
common/lib/xmodule/xmodule/conditional_module.py
+21
-15
No files found.
common/lib/xmodule/xmodule/conditional_module.py
View file @
9e18dd86
...
@@ -38,6 +38,9 @@ class ConditionalModule(XModule):
...
@@ -38,6 +38,9 @@ class ConditionalModule(XModule):
contents
=
String
(
scope
=
Scope
.
content
)
contents
=
String
(
scope
=
Scope
.
content
)
show_modules
=
String
(
scope
=
Scope
.
content
)
show_modules
=
String
(
scope
=
Scope
.
content
)
conditions_map
=
{
'poll_answer'
:
'poll_answer'
,
'compeleted'
:
'is_competed()'
}
def
_get_required_modules
(
self
):
def
_get_required_modules
(
self
):
self
.
required_modules
=
[]
self
.
required_modules
=
[]
for
loc
in
self
.
descriptor
.
required_module_locations
:
for
loc
in
self
.
descriptor
.
required_module_locations
:
...
@@ -46,34 +49,38 @@ class ConditionalModule(XModule):
...
@@ -46,34 +49,38 @@ class ConditionalModule(XModule):
#log.debug('required_modules=%s' % (self.required_modules))
#log.debug('required_modules=%s' % (self.required_modules))
def
_get_condition
(
self
):
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
):
def
is_condition_satisfied
(
self
):
self
.
_get_required_modules
()
self
.
_get_required_modules
()
self
.
condition
=
self
.
_get_condition
()
self
.
condition
=
self
.
_get_condition
()
if
self
.
condition
==
'
require_
completed'
:
if
self
.
condition
==
'completed'
:
# all required modules must be completed, as determined by
# all required modules must be completed, as determined by
# the modules .is_completed() method
# the modules .is_completed() method
for
module
in
self
.
required_modules
:
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; student_answers=%s' % module.lcp.student_answers)
#log.debug('in is_condition_satisfied; instance_state=%s' % module.instance_state)
#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
)
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
)
log
.
debug
(
'conditional module:
%
s not completed'
%
module
)
return
False
return
False
else
:
else
:
log
.
debug
(
'conditional module:
%
s IS completed'
%
module
)
log
.
debug
(
'conditional module:
%
s IS completed'
%
module
)
return
True
return
True
elif
self
.
condition
==
'answer'
:
elif
self
.
condition
==
'
poll_
answer'
:
for
module
in
self
.
required_modules
:
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
)
raise
Exception
(
'Error in conditional module: required module
%
s has no poll_answer field'
%
module
)
answer
=
self
.
descriptor
.
xml_attributes
.
get
(
'answer'
)
module_value
=
getattr
(
module
,
self
.
conditions_map
.
get
(
self
.
condition
))
if
answer
==
'unanswered'
and
module
.
poll_answer
:
answer
=
self
.
descriptor
.
xml_attributes
.
get
(
self
.
condition
)
if
answer
==
'unanswered'
and
module_value
:
return
False
return
False
if
module
.
poll_answer
!=
answer
:
if
module
_value
!=
answer
:
return
False
return
False
return
True
return
True
else
:
else
:
...
@@ -110,8 +117,8 @@ class ConditionalModule(XModule):
...
@@ -110,8 +117,8 @@ class ConditionalModule(XModule):
if
self
.
contents
is
None
:
if
self
.
contents
is
None
:
# self.contents = [child.get_html() for child in self.get_display_items()]
# 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(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
(
child_descriptor
.
location
)
.
get_html
()
for
child_descriptor
in
self
.
descriptor
.
get_children
()]
for
child_descriptor
in
self
.
descriptor
.
get_children
()]
html
=
self
.
contents
html
=
self
.
contents
...
@@ -140,7 +147,6 @@ class ConditionalDescriptor(SequenceDescriptor):
...
@@ -140,7 +147,6 @@ class ConditionalDescriptor(SequenceDescriptor):
loc
[
'category'
]
=
tag
loc
[
'category'
]
=
tag
loc
[
'name'
]
=
name
loc
[
'name'
]
=
name
self
.
required_module_locations
.
append
(
Location
(
loc
))
self
.
required_module_locations
.
append
(
Location
(
loc
))
# import ipdb; ipdb.set_trace()
log
.
debug
(
'ConditionalDescriptor required_module_locations=
%
s'
%
self
.
required_module_locations
)
log
.
debug
(
'ConditionalDescriptor required_module_locations=
%
s'
%
self
.
required_module_locations
)
def
get_required_module_descriptors
(
self
):
def
get_required_module_descriptors
(
self
):
...
@@ -156,10 +162,10 @@ class ConditionalDescriptor(SequenceDescriptor):
...
@@ -156,10 +162,10 @@ class ConditionalDescriptor(SequenceDescriptor):
sources
=
child
.
get
(
'sources'
)
sources
=
child
.
get
(
'sources'
)
if
sources
:
if
sources
:
for
url
in
[
url
.
strip
()
for
url
in
sources
.
split
(
';'
)]:
for
url
in
[
url
.
strip
()
for
url
in
sources
.
split
(
';'
)]:
try
:
# Check valid location url.
Location
(
url
)
if
Location
.
is_valid
(
url
):
urls
.
append
(
url
)
urls
.
append
(
url
)
e
xcept
:
e
lse
:
log
.
exception
(
"Bad location url - {0}"
.
format
(
url
))
log
.
exception
(
"Bad location url - {0}"
.
format
(
url
))
return
urls
return
urls
...
...
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