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
b3051ced
Commit
b3051ced
authored
Dec 21, 2016
by
Cliff Dyer
Committed by
GitHub
Dec 21, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14195 from edx/cdyer/save-cl-data
Save content library selected blocks during transform phase.
parents
4ead911f
b90c21b1
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 @
b3051ced
...
...
@@ -76,18 +76,34 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
module
=
self
.
_get_student_module
(
usage_info
.
user
,
usage_info
.
course_key
,
block_key
)
if
module
:
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
# library module to the selected list.
for
state
in
state_dict
[
'selected'
]:
usage_key
=
usage_info
.
course_key
.
make_usage_key
(
state
[
0
],
state
[
1
]
)
if
usage_key
in
library_children
:
selected
.
append
((
state
[
0
],
state
[
1
])
)
block_type
,
block_id
=
selected_block
usage_key
=
usage_info
.
course_key
.
make_usage_key
(
block_type
,
block_id
)
if
usage_key
in
library_children
:
selected
.
append
(
selected_block
)
#
u
pdate selected
#
U
pdate selected
previous_count
=
len
(
selected
)
block_keys
=
LibraryContentModule
.
make_selection
(
selected
,
library_children
,
max_count
,
mode
)
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
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
)
...
...
@@ -125,7 +141,6 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
student
=
user
,
course_id
=
course_key
,
module_state_key
=
block_key
,
state__contains
=
'"selected": [['
)
except
StudentModule
.
DoesNotExist
:
return
None
...
...
lms/djangoapps/course_blocks/transformers/tests/test_library_content.py
View file @
b3051ced
"""
Tests for ContentLibraryTransformer.
"""
import
mock
from
student.tests.factories
import
CourseEnrollmentFactory
from
openedx.core.djangoapps.content.block_structure.api
import
clear_course_from_cache
...
...
@@ -138,14 +138,14 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
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
self
.
assertTrue
(
vertical2_selected
or
vertical3_selected
)
# Check course structure again, with mocked selected modules for a user.
with
mock
.
patch
(
'lms.djangoapps.course_blocks.transformers.library_content.ContentLibraryTransformer._get_student_module'
,
return_value
=
MockedModule
(
'{"selected": [["vertical", "vertical_vertical2"]]}'
),
):
clear_course_from_cache
(
self
.
course
.
id
)
self
.
assertNotEquals
(
vertical2_selected
,
vertical3_selected
)
# only one of them should be selected
selected_vertical
=
'vertical2'
if
vertical2_selected
else
'vertical3'
selected_child
=
'html1'
if
vertical2_selected
else
'html2'
# Check course structure again.
clear_course_from_cache
(
self
.
course
.
id
)
for
i
in
range
(
5
):
trans_block_structure
=
get_course_blocks
(
self
.
user
,
self
.
course
.
location
,
...
...
@@ -160,7 +160,8 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
'lesson1'
,
'vertical1'
,
'library_content1'
,
'vertical2'
,
'html1'
)
selected_vertical
,
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