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
05fc6738
Commit
05fc6738
authored
Jan 12, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add in "previous_count" and "max_count"
parent
10fe9c01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
common/lib/xmodule/xmodule/library_content_module.py
+18
-18
common/lib/xmodule/xmodule/tests/test_library_content.py
+4
-0
No files found.
common/lib/xmodule/xmodule/library_content_module.py
View file @
05fc6738
...
@@ -221,35 +221,39 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
...
@@ -221,35 +221,39 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
# Already done:
# Already done:
return
self
.
_selected_set
# pylint: disable=access-member-before-definition
return
self
.
_selected_set
# pylint: disable=access-member-before-definition
selected
=
set
(
tuple
(
k
)
for
k
in
self
.
selected
)
# set of (block_type, block_id) tuples assigned to this student
previous_count
=
len
(
selected
)
lib_tools
=
self
.
runtime
.
service
(
self
,
'library_tools'
)
lib_tools
=
self
.
runtime
.
service
(
self
,
'library_tools'
)
format_block_keys
=
lambda
keys
:
lib_tools
.
create_block_analytics_summary
(
self
.
location
.
course_key
,
keys
)
format_block_keys
=
lambda
keys
:
lib_tools
.
create_block_analytics_summary
(
self
.
location
.
course_key
,
keys
)
def
publish_event
(
event_name
,
**
kwargs
):
""" Publish an event for analytics purposes """
event_data
=
{
"location"
:
unicode
(
self
.
location
),
"result"
:
format_block_keys
(
selected
),
"previous_count"
:
previous_count
,
"max_count"
:
self
.
max_count
,
}
event_data
.
update
(
kwargs
)
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.{}"
.
format
(
event_name
),
event_data
)
# Determine which of our children we will show:
# Determine which of our children we will show:
selected
=
set
(
tuple
(
k
)
for
k
in
self
.
selected
)
# set of (block_type, block_id) tuples
valid_block_keys
=
set
([(
c
.
block_type
,
c
.
block_id
)
for
c
in
self
.
children
])
# pylint: disable=no-member
valid_block_keys
=
set
([(
c
.
block_type
,
c
.
block_id
)
for
c
in
self
.
children
])
# pylint: disable=no-member
# Remove any selected blocks that are no longer valid:
# Remove any selected blocks that are no longer valid:
invalid_block_keys
=
(
selected
-
valid_block_keys
)
invalid_block_keys
=
(
selected
-
valid_block_keys
)
if
invalid_block_keys
:
if
invalid_block_keys
:
selected
-=
invalid_block_keys
selected
-=
invalid_block_keys
# Publish an event for analytics purposes:
# Publish an event for analytics purposes:
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.removed"
,
{
# reason "invalid" means deleted from library or a different library is now being used.
"location"
:
unicode
(
self
.
location
),
publish_event
(
"removed"
,
removed
=
format_block_keys
(
invalid_block_keys
),
reason
=
"invalid"
)
"removed"
:
format_block_keys
(
invalid_block_keys
),
"reason"
:
"invalid"
,
# Deleted from library or library being used has changed
"result"
:
format_block_keys
(
selected
),
})
# If max_count has been decreased, we may have to drop some previously selected blocks:
# If max_count has been decreased, we may have to drop some previously selected blocks:
overlimit_block_keys
=
set
()
overlimit_block_keys
=
set
()
while
len
(
selected
)
>
self
.
max_count
:
while
len
(
selected
)
>
self
.
max_count
:
overlimit_block_keys
.
add
(
selected
.
pop
())
overlimit_block_keys
.
add
(
selected
.
pop
())
if
overlimit_block_keys
:
if
overlimit_block_keys
:
# Publish an event for analytics purposes:
# Publish an event for analytics purposes:
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.removed"
,
{
publish_event
(
"removed"
,
removed
=
format_block_keys
(
overlimit_block_keys
),
reason
=
"overlimit"
)
"location"
:
unicode
(
self
.
location
),
"removed"
:
format_block_keys
(
overlimit_block_keys
),
"reason"
:
"overlimit"
,
"result"
:
format_block_keys
(
selected
),
})
# Do we have enough blocks now?
# Do we have enough blocks now?
num_to_add
=
self
.
max_count
-
len
(
selected
)
num_to_add
=
self
.
max_count
-
len
(
selected
)
if
num_to_add
>
0
:
if
num_to_add
>
0
:
...
@@ -265,11 +269,7 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
...
@@ -265,11 +269,7 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
selected
|=
added_block_keys
selected
|=
added_block_keys
if
added_block_keys
:
if
added_block_keys
:
# Publish an event for analytics purposes:
# Publish an event for analytics purposes:
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.assigned"
,
{
publish_event
(
"assigned"
,
added
=
format_block_keys
(
added_block_keys
))
"location"
:
unicode
(
self
.
location
),
"added"
:
format_block_keys
(
added_block_keys
),
"result"
:
format_block_keys
(
selected
),
})
# Save our selections to the user state, to ensure consistency:
# Save our selections to the user state, to ensure consistency:
self
.
selected
=
list
(
selected
)
# TODO: this doesn't save from the LMS "Progress" page.
self
.
selected
=
list
(
selected
)
# TODO: this doesn't save from the LMS "Progress" page.
# Cache the results
# Cache the results
...
...
common/lib/xmodule/xmodule/tests/test_library_content.py
View file @
05fc6738
...
@@ -351,6 +351,8 @@ class TestLibraryContentAnalytics(LibraryContentTest):
...
@@ -351,6 +351,8 @@ class TestLibraryContentAnalytics(LibraryContentTest):
"location"
:
unicode
(
self
.
lc_block
.
location
),
"location"
:
unicode
(
self
.
lc_block
.
location
),
"added"
:
[
block_info
],
"added"
:
[
block_info
],
"result"
:
[
block_info
],
"result"
:
[
block_info
],
"previous_count"
:
0
,
"max_count"
:
1
,
})
})
self
.
publisher
.
reset_mock
()
self
.
publisher
.
reset_mock
()
...
@@ -364,6 +366,8 @@ class TestLibraryContentAnalytics(LibraryContentTest):
...
@@ -364,6 +366,8 @@ class TestLibraryContentAnalytics(LibraryContentTest):
event_data
=
self
.
_assert_event_was_published
(
"assigned"
)
event_data
=
self
.
_assert_event_was_published
(
"assigned"
)
self
.
assertEqual
(
event_data
[
"added"
][
0
][
"usage_key"
],
unicode
(
new_child
.
location
))
self
.
assertEqual
(
event_data
[
"added"
][
0
][
"usage_key"
],
unicode
(
new_child
.
location
))
self
.
assertEqual
(
len
(
event_data
[
"result"
]),
2
)
self
.
assertEqual
(
len
(
event_data
[
"result"
]),
2
)
self
.
assertEqual
(
event_data
[
"previous_count"
],
1
)
self
.
assertEqual
(
event_data
[
"max_count"
],
2
)
def
test_assigned_descendants
(
self
):
def
test_assigned_descendants
(
self
):
"""
"""
...
...
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