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
b90c21b1
Commit
b90c21b1
authored
Dec 20, 2016
by
Nimisha Asthagiri
Committed by
J. Cliff Dyer
Dec 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure selected blocks get saved into StudentModule when running
transform phase TNL-6198
parent
e860205e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
18 deletions
+34
-18
lms/djangoapps/course_blocks/transformers/library_content.py
+21
-6
lms/djangoapps/course_blocks/transformers/tests/test_library_content.py
+13
-12
No files found.
lms/djangoapps/course_blocks/transformers/library_content.py
View file @
b90c21b1
...
@@ -76,18 +76,34 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
...
@@ -76,18 +76,34 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
module
=
self
.
_get_student_module
(
usage_info
.
user
,
usage_info
.
course_key
,
block_key
)
module
=
self
.
_get_student_module
(
usage_info
.
user
,
usage_info
.
course_key
,
block_key
)
if
module
:
if
module
:
state_dict
=
json
.
loads
(
module
.
state
)
state_dict
=
json
.
loads
(
module
.
state
)
else
:
state_dict
=
{}
for
selected_block
in
state_dict
.
get
(
'selected'
,
[]):
# Add all selected entries for this user for this
# Add all selected entries for this user for this
# library module to the selected list.
# library module to the selected list.
for
state
in
state_dict
[
'selected'
]:
block_type
,
block_id
=
selected_block
usage_key
=
usage_info
.
course_key
.
make_usage_key
(
state
[
0
],
state
[
1
]
)
usage_key
=
usage_info
.
course_key
.
make_usage_key
(
block_type
,
block_id
)
if
usage_key
in
library_children
:
if
usage_key
in
library_children
:
selected
.
append
((
state
[
0
],
state
[
1
])
)
selected
.
append
(
selected_block
)
#
u
pdate selected
#
U
pdate selected
previous_count
=
len
(
selected
)
previous_count
=
len
(
selected
)
block_keys
=
LibraryContentModule
.
make_selection
(
selected
,
library_children
,
max_count
,
mode
)
block_keys
=
LibraryContentModule
.
make_selection
(
selected
,
library_children
,
max_count
,
mode
)
selected
=
block_keys
[
'selected'
]
selected
=
block_keys
[
'selected'
]
# Save back any changes
if
any
(
block_keys
[
changed
]
for
changed
in
(
'invalid'
,
'overlimit'
,
'added'
)):
state_dict
[
'selected'
]
=
list
(
selected
)
StudentModule
.
objects
.
update_or_create
(
# pylint: disable=no-member
student
=
usage_info
.
user
,
course_id
=
usage_info
.
course_key
,
module_state_key
=
block_key
,
defaults
=
{
'state'
:
json
.
dumps
(
state_dict
),
},
)
# publish events for analytics
# publish events for analytics
self
.
_publish_events
(
block_structure
,
block_key
,
previous_count
,
max_count
,
block_keys
)
self
.
_publish_events
(
block_structure
,
block_key
,
previous_count
,
max_count
,
block_keys
)
all_selected_children
.
update
(
usage_info
.
course_key
.
make_usage_key
(
s
[
0
],
s
[
1
])
for
s
in
selected
)
all_selected_children
.
update
(
usage_info
.
course_key
.
make_usage_key
(
s
[
0
],
s
[
1
])
for
s
in
selected
)
...
@@ -125,7 +141,6 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
...
@@ -125,7 +141,6 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
student
=
user
,
student
=
user
,
course_id
=
course_key
,
course_id
=
course_key
,
module_state_key
=
block_key
,
module_state_key
=
block_key
,
state__contains
=
'"selected": [['
)
)
except
StudentModule
.
DoesNotExist
:
except
StudentModule
.
DoesNotExist
:
return
None
return
None
...
...
lms/djangoapps/course_blocks/transformers/tests/test_library_content.py
View file @
b90c21b1
"""
"""
Tests for ContentLibraryTransformer.
Tests for ContentLibraryTransformer.
"""
"""
import
mock
from
student.tests.factories
import
CourseEnrollmentFactory
from
student.tests.factories
import
CourseEnrollmentFactory
from
openedx.core.djangoapps.content.block_structure.api
import
clear_course_from_cache
from
openedx.core.djangoapps.content.block_structure.api
import
clear_course_from_cache
...
@@ -138,14 +138,14 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
...
@@ -138,14 +138,14 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
vertical2_selected
=
self
.
get_block_key_set
(
self
.
blocks
,
'vertical2'
)
.
pop
()
in
trans_keys
vertical2_selected
=
self
.
get_block_key_set
(
self
.
blocks
,
'vertical2'
)
.
pop
()
in
trans_keys
vertical3_selected
=
self
.
get_block_key_set
(
self
.
blocks
,
'vertical3'
)
.
pop
()
in
trans_keys
vertical3_selected
=
self
.
get_block_key_set
(
self
.
blocks
,
'vertical3'
)
.
pop
()
in
trans_keys
self
.
assertTrue
(
vertical2_selected
or
vertical3_selected
)
self
.
assertNotEquals
(
vertical2_selected
,
vertical3_selected
)
# only one of them should be selected
# Check course structure again, with mocked selected modules for a user.
selected_vertical
=
'vertical2'
if
vertical2_selected
else
'vertical3'
with
mock
.
patch
(
selected_child
=
'html1'
if
vertical2_selected
else
'html2'
'lms.djangoapps.course_blocks.transformers.library_content.ContentLibraryTransformer._get_student_module'
,
return_value
=
MockedModule
(
'{"selected": [["vertical", "vertical_vertical2"]]}'
),
# Check course structure again.
):
clear_course_from_cache
(
self
.
course
.
id
)
clear_course_from_cache
(
self
.
course
.
id
)
for
i
in
range
(
5
):
trans_block_structure
=
get_course_blocks
(
trans_block_structure
=
get_course_blocks
(
self
.
user
,
self
.
user
,
self
.
course
.
location
,
self
.
course
.
location
,
...
@@ -160,7 +160,8 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
...
@@ -160,7 +160,8 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
'lesson1'
,
'lesson1'
,
'vertical1'
,
'vertical1'
,
'library_content1'
,
'library_content1'
,
'vertical2'
,
selected_vertical
,
'html1'
selected_child
,
)
),
"Expected 'selected' equality failed in iteration {}."
.
format
(
i
)
)
)
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