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
1ec4ae7c
Commit
1ec4ae7c
authored
Apr 24, 2015
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more documentation to XBlockUserStateClient interface
parent
4c3fb2d0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
4 deletions
+56
-4
lms/djangoapps/courseware/user_state_client.py
+56
-4
No files found.
lms/djangoapps/courseware/user_state_client.py
View file @
1ec4ae7c
...
@@ -29,19 +29,71 @@ class DjangoXBlockUserStateClient(DjangoXBlockUserStateClient):
...
@@ -29,19 +29,71 @@ class DjangoXBlockUserStateClient(DjangoXBlockUserStateClient):
"""
"""
pass
pass
def
get
(
username
,
block_key
,
scope
=
Scope
.
user_state
):
def
get
(
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
return
self
.
get_many
(
username
,
[
block_key
],
scope
)
"""
Retrieve the stored XBlock state for a single xblock usage.
Arguments:
username: The name of the user whose state should be retrieved
block_key (UsageKey): The UsageKey identifying which xblock state to load.
scope (Scope): The scope to load data from
fields: A list of field values to retrieve. If None, retrieve all stored fields.
Returns:
dict: A dictionary mapping field names to values
Raises:
DoesNotExist if no entry is found.
"""
try
:
_usage_key
,
state
=
next
(
self
.
get_many
(
username
,
[
block_key
],
scope
,
fields
=
fields
))
except
StopIteration
:
raise
self
.
DoesNotExist
()
return
state
def
set
(
username
,
block_key
,
state
,
scope
=
Scope
.
user_state
):
def
set
(
username
,
block_key
,
state
,
scope
=
Scope
.
user_state
):
"""
Set fields for a particular XBlock.
Arguments:
username: The name of the user whose state should be retrieved
block_key (UsageKey): The UsageKey identifying which xblock state to load.
state (dict): A dictionary mapping field names to values
scope (Scope): The scope to load data from
"""
self
.
set_many
(
username
,
{
block_key
:
state
},
scope
)
self
.
set_many
(
username
,
{
block_key
:
state
},
scope
)
def
get_many
(
username
,
block_keys
,
scope
=
Scope
.
user_state
):
def
get_many
(
username
,
block_keys
,
scope
=
Scope
.
user_state
,
fields
=
None
):
"""Returns dict of block_id -> state."""
"""
Retrieve the stored XBlock state for a single xblock usage.
Arguments:
username: The name of the user whose state should be retrieved
block_keys ([UsageKey]): A list of UsageKeys identifying which xblock states to load.
scope (Scope): The scope to load data from
fields: A list of field values to retrieve. If None, retrieve all stored fields.
Yields:
(UsageKey, field_state) tuples for each specified UsageKey in block_keys.
field_state is a dict mapping field names to values.
"""
if
scope
!=
Scope
.
user_state
:
if
scope
!=
Scope
.
user_state
:
raise
ValueError
(
"Only Scope.user_state is supported"
)
raise
ValueError
(
"Only Scope.user_state is supported"
)
raise
NotImplementedError
()
raise
NotImplementedError
()
def
set_many
(
username
,
block_keys_to_state
,
scope
=
Scope
.
user_state
):
def
set_many
(
username
,
block_keys_to_state
,
scope
=
Scope
.
user_state
):
"""
Set fields for a particular XBlock.
Arguments:
username: The name of the user whose state should be retrieved
block_keys_to_state (dict): A dict mapping UsageKeys to state dicts.
Each state dict maps field names to values. These state dicts
are overlaid over the stored state. To delete fields, use
:meth:`delete` or :meth:`delete_many`.
scope (Scope): The scope to load data from
"""
if
scope
!=
Scope
.
user_state
:
if
scope
!=
Scope
.
user_state
:
raise
ValueError
(
"Only Scope.user_state is supported"
)
raise
ValueError
(
"Only Scope.user_state is supported"
)
raise
NotImplementedError
()
raise
NotImplementedError
()
...
...
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