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
d1fae17c
Commit
d1fae17c
authored
Apr 15, 2015
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the logic from `find` into the methods that use it
parent
3bcd5ceb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
22 deletions
+37
-22
lms/djangoapps/courseware/model_data.py
+37
-22
No files found.
lms/djangoapps/courseware/model_data.py
View file @
d1fae17c
...
...
@@ -584,7 +584,16 @@ class FieldDataCache(object):
Returns: The found value
Raises: KeyError if key isn't found in the cache
'''
field_object
=
self
.
find
(
key
)
if
key
.
scope
.
user
==
UserScope
.
ONE
and
not
self
.
user
.
is_anonymous
():
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert
key
.
user_id
==
self
.
user
.
id
if
key
.
scope
not
in
self
.
cache
:
raise
KeyError
(
key
.
field_name
)
field_object
=
self
.
cache
[
key
.
scope
]
.
get
(
key
)
if
field_object
is
None
:
raise
KeyError
(
key
.
field_name
)
...
...
@@ -603,6 +612,7 @@ class FieldDataCache(object):
kv_dict (dict): dict mapping from `DjangoKeyValueStore.Key`s to field values
Raises: DatabaseError if any fields fail to save
"""
saved_fields
=
[]
# field_objects maps a field_object to a list of associated fields
field_objects
=
dict
()
...
...
@@ -645,7 +655,16 @@ class FieldDataCache(object):
Raises: KeyError if key isn't found in the cache
"""
field_object
=
self
.
find
(
key
)
if
key
.
scope
.
user
==
UserScope
.
ONE
and
not
self
.
user
.
is_anonymous
():
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert
key
.
user_id
==
self
.
user
.
id
if
key
.
scope
not
in
self
.
cache
:
raise
KeyError
(
key
.
field_name
)
field_object
=
self
.
cache
[
key
.
scope
]
.
get
(
key
)
if
field_object
is
None
:
raise
KeyError
(
key
.
field_name
)
...
...
@@ -667,7 +686,16 @@ class FieldDataCache(object):
Returns: bool
"""
field_object
=
self
.
find
(
key
)
if
key
.
scope
.
user
==
UserScope
.
ONE
and
not
self
.
user
.
is_anonymous
():
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert
key
.
user_id
==
self
.
user
.
id
if
key
.
scope
not
in
self
.
cache
:
return
False
field_object
=
self
.
cache
[
key
.
scope
]
.
get
(
key
)
if
field_object
is
None
:
return
False
...
...
@@ -676,31 +704,21 @@ class FieldDataCache(object):
else
:
return
True
def
find
(
self
,
key
):
def
find_or_create
(
self
,
key
):
'''
Look for a model data object using an DjangoKeyValueStore.Key object
key: An `DjangoKeyValueStore.Key` object selecting the object to find
returns the found object, or None if the object doesn't exist
Find a model data object in this cache, or create a new one if it doesn't
exist
'''
if
key
.
scope
.
user
==
UserScope
.
ONE
and
not
self
.
user
.
is_anonymous
():
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert
key
.
user_id
==
self
.
user
.
id
if
key
.
scope
not
in
self
.
cache
:
return
None
return
self
.
cache
[
key
.
scope
]
.
get
(
key
)
return
def
find_or_create
(
self
,
key
):
'''
Find a model data object in this cache, or create it if it doesn't
exist
'''
field_object
=
self
.
find
(
key
)
field_object
=
self
.
cache
[
key
.
scope
]
.
get
(
key
)
if
field_object
is
not
None
:
return
field_object
...
...
@@ -732,8 +750,5 @@ class FieldDataCache(object):
student_id
=
key
.
user_id
,
)
if
key
.
scope
not
in
self
.
cache
:
return
self
.
cache
[
key
.
scope
]
.
set
(
key
,
field_object
)
return
field_object
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