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
7d2909c5
Commit
7d2909c5
authored
Apr 29, 2015
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add contracts to DjangoXBlockUserStateClient interface methods
parent
2bfbd57e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
3 deletions
+37
-3
lms/djangoapps/courseware/user_state_client.py
+37
-3
No files found.
lms/djangoapps/courseware/user_state_client.py
View file @
7d2909c5
...
@@ -11,9 +11,13 @@ try:
...
@@ -11,9 +11,13 @@ try:
except
ImportError
:
except
ImportError
:
import
json
import
json
from
xblock.fields
import
Scope
from
xblock.fields
import
Scope
,
ScopeBase
from
xblock_user_state.interface
import
XBlockUserStateClient
from
xblock_user_state.interface
import
XBlockUserStateClient
from
courseware.models
import
StudentModule
from
courseware.models
import
StudentModule
from
contracts
import
contract
,
new_contract
from
opaque_keys.edx.keys
import
UsageKey
new_contract
(
'UsageKey'
,
UsageKey
)
class
DjangoXBlockUserStateClient
(
XBlockUserStateClient
):
class
DjangoXBlockUserStateClient
(
XBlockUserStateClient
):
...
@@ -42,6 +46,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -42,6 +46,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
def
__init__
(
self
,
user
):
def
__init__
(
self
,
user
):
self
.
user
=
user
self
.
user
=
user
@contract
(
username
=
"basestring"
,
block_key
=
UsageKey
,
scope
=
ScopeBase
,
fields
=
"seq(basestring)|set(basestring)|None"
)
def
get
(
self
,
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
def
get
(
self
,
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
"""
"""
Retrieve the stored XBlock state for a single xblock usage.
Retrieve the stored XBlock state for a single xblock usage.
...
@@ -66,6 +76,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -66,6 +76,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
return
state
return
state
@contract
(
username
=
"basestring"
,
block_key
=
UsageKey
,
state
=
"dict(basestring: *)"
,
scope
=
ScopeBase
)
def
set
(
self
,
username
,
block_key
,
state
,
scope
=
Scope
.
user_state
):
def
set
(
self
,
username
,
block_key
,
state
,
scope
=
Scope
.
user_state
):
"""
"""
Set fields for a particular XBlock.
Set fields for a particular XBlock.
...
@@ -79,6 +90,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -79,6 +90,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
assert
self
.
user
.
username
==
username
assert
self
.
user
.
username
==
username
self
.
set_many
(
username
,
{
block_key
:
state
},
scope
)
self
.
set_many
(
username
,
{
block_key
:
state
},
scope
)
@contract
(
username
=
"basestring"
,
block_key
=
UsageKey
,
scope
=
ScopeBase
,
fields
=
"seq(basestring)|set(basestring)|None"
)
def
delete
(
self
,
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
def
delete
(
self
,
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
"""
"""
Delete the stored XBlock state for a single xblock usage.
Delete the stored XBlock state for a single xblock usage.
...
@@ -92,7 +109,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -92,7 +109,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
assert
self
.
user
.
username
==
username
assert
self
.
user
.
username
==
username
return
self
.
delete_many
(
username
,
[
block_key
],
scope
,
fields
=
fields
)
return
self
.
delete_many
(
username
,
[
block_key
],
scope
,
fields
=
fields
)
@contract
(
username
=
"basestring"
,
block_key
=
UsageKey
,
scope
=
ScopeBase
,
fields
=
"seq(basestring)|set(basestring)|None"
)
@contract
(
username
=
"basestring"
,
block_key
=
UsageKey
,
scope
=
ScopeBase
,
fields
=
"seq(basestring)|set(basestring)|None"
)
def
get_mod_date
(
self
,
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
def
get_mod_date
(
self
,
username
,
block_key
,
scope
=
Scope
.
user_state
,
fields
=
None
):
"""
"""
Get the last modification date for fields from the specified blocks.
Get the last modification date for fields from the specified blocks.
...
@@ -140,7 +162,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -140,7 +162,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
usage_key
=
student_module
.
module_state_key
.
map_into_course
(
student_module
.
course_id
)
usage_key
=
student_module
.
module_state_key
.
map_into_course
(
student_module
.
course_id
)
yield
(
student_module
,
usage_key
)
yield
(
student_module
,
usage_key
)
@contract
(
username
=
"basestring"
,
block_keys
=
"seq(UsageKey)|set(UsageKey)"
,
scope
=
ScopeBase
,
fields
=
"seq(basestring)|set(basestring)|None"
)
def
get_many
(
self
,
username
,
block_keys
,
scope
=
Scope
.
user_state
,
fields
=
None
):
def
get_many
(
self
,
username
,
block_keys
,
scope
=
Scope
.
user_state
,
fields
=
None
):
"""
"""
Retrieve the stored XBlock state for a single xblock usage.
Retrieve the stored XBlock state for a single xblock usage.
...
@@ -167,6 +194,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -167,6 +194,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
state
=
json
.
loads
(
module
.
state
)
state
=
json
.
loads
(
module
.
state
)
yield
(
usage_key
,
state
)
yield
(
usage_key
,
state
)
@contract
(
username
=
"basestring"
,
block_keys_to_state
=
"dict(UsageKey: dict(basestring: *))"
,
scope
=
ScopeBase
)
def
set_many
(
self
,
username
,
block_keys_to_state
,
scope
=
Scope
.
user_state
):
def
set_many
(
self
,
username
,
block_keys_to_state
,
scope
=
Scope
.
user_state
):
"""
"""
Set fields for a particular XBlock.
Set fields for a particular XBlock.
...
@@ -208,6 +236,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
...
@@ -208,6 +236,12 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
# We just read this object, so we know that we can do an update
# We just read this object, so we know that we can do an update
student_module
.
save
(
force_update
=
True
)
student_module
.
save
(
force_update
=
True
)
@contract
(
username
=
"basestring"
,
block_keys
=
"seq(UsageKey)|set(UsageKey)"
,
scope
=
ScopeBase
,
fields
=
"seq(basestring)|set(basestring)|None"
)
def
delete_many
(
self
,
username
,
block_keys
,
scope
=
Scope
.
user_state
,
fields
=
None
):
def
delete_many
(
self
,
username
,
block_keys
,
scope
=
Scope
.
user_state
,
fields
=
None
):
"""
"""
Delete the stored XBlock state for a many xblock usages.
Delete the stored XBlock state for a many xblock usages.
...
...
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