Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
37fc450b
Commit
37fc450b
authored
8 years ago
by
J. Cliff Dyer
Browse files
Options
Downloads
Patches
Plain Diff
Add version to VisibleBlocks model.
TNL-5600
parent
0b7ec75a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/grades/models.py
+10
-6
10 additions, 6 deletions
lms/djangoapps/grades/models.py
lms/djangoapps/grades/tests/test_models.py
+8
-5
8 additions, 5 deletions
lms/djangoapps/grades/tests/test_models.py
with
18 additions
and
11 deletions
lms/djangoapps/grades/models.py
+
10
−
6
View file @
37fc450b
...
...
@@ -23,6 +23,8 @@ from xmodule_django.models import CourseKeyField, UsageKeyField
log
=
logging
.
getLogger
(
__name__
)
BLOCK_RECORD_LIST_VERSION
=
1
# Used to serialize information about a block at the time it was used in
# grade calculation.
BlockRecord
=
namedtuple
(
'
BlockRecord
'
,
[
'
locator
'
,
'
weight
'
,
'
max_score
'
])
...
...
@@ -33,12 +35,13 @@ class BlockRecordList(tuple):
An immutable ordered list of BlockRecord objects.
"""
def
__new__
(
cls
,
blocks
,
course_key
):
# pylint: disable=unused-argument
def
__new__
(
cls
,
blocks
,
course_key
,
version
=
None
):
# pylint: disable=unused-argument
return
super
(
BlockRecordList
,
cls
).
__new__
(
cls
,
blocks
)
def
__init__
(
self
,
blocks
,
course_key
):
def
__init__
(
self
,
blocks
,
course_key
,
version
=
None
):
super
(
BlockRecordList
,
self
).
__init__
(
blocks
)
self
.
course_key
=
course_key
self
.
version
=
version
or
BLOCK_RECORD_LIST_VERSION
def
__eq__
(
self
,
other
):
assert
isinstance
(
other
,
BlockRecordList
)
...
...
@@ -73,8 +76,9 @@ class BlockRecordList(tuple):
for
block_dict
in
list_of_block_dicts
:
block_dict
[
'
locator
'
]
=
unicode
(
block_dict
[
'
locator
'
])
# BlockUsageLocator is not json-serializable
data
=
{
'
course_key
'
:
unicode
(
self
.
course_key
),
'
blocks
'
:
list_of_block_dicts
,
u
'
blocks
'
:
list_of_block_dicts
,
u
'
course_key
'
:
unicode
(
self
.
course_key
),
u
'
version
'
:
self
.
version
,
}
return
json
.
dumps
(
data
,
...
...
@@ -98,7 +102,7 @@ class BlockRecordList(tuple):
)
for
block
in
block_dicts
)
return
cls
(
record_generator
,
course_key
)
return
cls
(
record_generator
,
course_key
,
version
=
data
[
'
version
'
]
)
@classmethod
def
from_list
(
cls
,
blocks
,
course_key
):
...
...
@@ -121,7 +125,7 @@ class VisibleBlocksQuerySet(models.QuerySet):
"""
model
,
_
=
self
.
get_or_create
(
hashed
=
blocks
.
hash_value
,
defaults
=
{
'
blocks_json
'
:
blocks
.
json_value
,
'
course_id
'
:
blocks
.
course_key
},
defaults
=
{
u
'
blocks_json
'
:
blocks
.
json_value
,
u
'
course_id
'
:
blocks
.
course_key
},
)
return
model
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/grades/tests/test_models.py
+
8
−
5
View file @
37fc450b
...
...
@@ -14,6 +14,7 @@ from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator
from
lms.djangoapps.grades.models
import
(
BlockRecord
,
BlockRecordList
,
BLOCK_RECORD_LIST_VERSION
,
PersistentSubsectionGrade
,
VisibleBlocks
)
...
...
@@ -32,7 +33,10 @@ class BlockRecordListTestCase(TestCase):
)
def
test_empty_block_record_set
(
self
):
empty_json
=
'
{0}
"
blocks
"
:[],
"
course_key
"
:
"
{1}
"
{2}
'
.
format
(
'
{
'
,
unicode
(
self
.
course_key
),
'
}
'
)
empty_json
=
u
'
{
"
blocks
"
:[],
"
course_key
"
:
"
%s
"
,
"
version
"
:%s}
'
%
(
unicode
(
self
.
course_key
),
BLOCK_RECORD_LIST_VERSION
,
)
brs
=
BlockRecordList
((),
self
.
course_key
)
self
.
assertFalse
(
brs
)
...
...
@@ -100,7 +104,7 @@ class BlockRecordTest(GradesModelTestCase):
@ddt.unpack
def
test_serialization
(
self
,
weight
,
max_score
,
block_key
):
"""
Tests serialization of a BlockRecord using the
to_
dict() method.
Tests serialization of a BlockRecord using the
_as
dict() method.
"""
record
=
BlockRecord
(
block_key
,
weight
,
max_score
)
expected
=
OrderedDict
([
...
...
@@ -130,10 +134,9 @@ class VisibleBlocksTest(GradesModelTestCase):
for
block_dict
in
list_of_block_dicts
:
block_dict
[
'
locator
'
]
=
unicode
(
block_dict
[
'
locator
'
])
# BlockUsageLocator is not json-serializable
expected_data
=
{
'
blocks
'
:
[{
'
locator
'
:
unicode
(
self
.
record_a
.
locator
),
'
max_score
'
:
10
,
'
weight
'
:
1
}],
'
course_key
'
:
unicode
(
self
.
record_a
.
locator
.
course_key
),
'
blocks
'
:
[
{
'
locator
'
:
unicode
(
self
.
record_a
.
locator
),
'
max_score
'
:
10
,
'
weight
'
:
1
},
],
'
version
'
:
BLOCK_RECORD_LIST_VERSION
,
}
expected_json
=
json
.
dumps
(
expected_data
,
separators
=
(
'
,
'
,
'
:
'
),
sort_keys
=
True
)
expected_hash
=
b64encode
(
sha1
(
expected_json
).
digest
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment