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
c6bb02f5
Commit
c6bb02f5
authored
Jan 28, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate some code and speed up StepParentMixin
parent
b6f6a971
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
21 deletions
+36
-21
mentoring/components/step.py
+3
-8
mentoring/components/table.py
+4
-11
mentoring/components/utils.py
+19
-0
mentoring/tests/unit/test_step.py
+10
-2
No files found.
mentoring/components/step.py
View file @
c6bb02f5
...
...
@@ -17,6 +17,7 @@
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
from
.utils
import
child_isinstance
class
StepParentMixin
(
object
):
...
...
@@ -27,15 +28,9 @@ class StepParentMixin(object):
@property
def
steps
(
self
):
"""
Generator returning the usage_id for all of this XBlock's
children that are "Steps"
Get the usage_ids of all of this XBlock's children that are "Steps"
"""
step_ids
=
[]
for
child_id
in
self
.
children
:
child
=
self
.
runtime
.
get_block
(
child_id
)
if
isinstance
(
child
,
StepMixin
):
step_ids
.
append
(
child_id
)
return
step_ids
return
[
child_id
for
child_id
in
self
.
children
if
child_isinstance
(
self
,
child_id
,
StepMixin
)]
class
StepMixin
(
object
):
...
...
mentoring/components/table.py
View file @
c6bb02f5
...
...
@@ -25,6 +25,8 @@
import
errno
from
.utils
import
child_isinstance
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
String
from
xblock.fragment
import
Fragment
...
...
@@ -120,7 +122,7 @@ class MentoringTableColumnBlock(XBlock):
"""
return
self
.
_render_table_view
(
view_name
=
'mentoring_table_view'
,
id_filter
=
lambda
child_id
:
not
issubclass
(
self
.
_get_child_class
(
child_id
)
,
MentoringTableColumnHeaderBlock
),
id_filter
=
lambda
child_id
:
not
child_isinstance
(
self
,
child_id
,
MentoringTableColumnHeaderBlock
),
template
=
'mentoring-table-column.html'
,
context
=
context
)
...
...
@@ -131,20 +133,11 @@ class MentoringTableColumnBlock(XBlock):
"""
return
self
.
_render_table_view
(
view_name
=
'mentoring_table_header_view'
,
id_filter
=
lambda
child_id
:
issubclass
(
self
.
_get_child_class
(
child_id
)
,
MentoringTableColumnHeaderBlock
),
id_filter
=
lambda
child_id
:
child_isinstance
(
self
,
child_id
,
MentoringTableColumnHeaderBlock
),
template
=
'mentoring-table-header.html'
,
context
=
context
)
def
_get_child_class
(
self
,
child_id
):
"""
Helper method to get a block type from a usage_id without loading the block.
Returns the XBlock subclass of the child block.
"""
type_name
=
self
.
runtime
.
id_reader
.
get_block_type
(
self
.
runtime
.
id_reader
.
get_definition_id
(
child_id
))
return
self
.
runtime
.
load_block_type
(
type_name
)
class
MentoringTableColumnHeaderBlock
(
XBlock
):
"""
...
...
mentoring/components/utils.py
0 → 100644
View file @
c6bb02f5
"""
Helper methods
Should eventually be moved to xblock-utils.
"""
def
child_isinstance
(
block
,
child_id
,
block_class_or_mixin
):
"""
Is "block"'s child identified by usage_id "child_id" an instance of
"block_class_or_mixin"?
This is a bit complicated since it avoids the need to actually
instantiate the child block.
"""
def_id
=
block
.
runtime
.
id_reader
.
get_definition_id
(
child_id
)
type_name
=
block
.
runtime
.
id_reader
.
get_block_type
(
def_id
)
child_class
=
block
.
runtime
.
load_block_type
(
type_name
)
return
issubclass
(
child_class
,
block_class_or_mixin
)
mentoring/tests/unit/test_step.py
View file @
c6bb02f5
...
...
@@ -12,7 +12,11 @@ class Parent(StepParentMixin):
@property
def
runtime
(
self
):
return
Mock
(
get_block
=
lambda
i
:
self
.
_children
[
i
])
return
Mock
(
get_block
=
lambda
i
:
self
.
_children
[
i
],
load_block_type
=
lambda
i
:
type
(
self
.
_children
[
i
]),
id_reader
=
Mock
(
get_definition_id
=
lambda
i
:
i
,
get_block_type
=
lambda
i
:
i
)
)
def
_set_children_for_test
(
self
,
*
children
):
self
.
_children
=
children
...
...
@@ -24,7 +28,11 @@ class Parent(StepParentMixin):
pass
class
Step
(
StepMixin
):
class
BaseClass
(
object
):
pass
class
Step
(
BaseClass
,
StepMixin
):
def
__init__
(
self
):
pass
...
...
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