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
4223bf70
Unverified
Commit
4223bf70
authored
Nov 16, 2017
by
Brian Mesick
Committed by
GitHub
Nov 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16567 from edx/bmedx/django111_get_prep_lookup
Change get_prep_lookup to a Lookup
parents
ebe85737
31f11709
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
openedx/core/djangoapps/xmodule_django/models.py
+14
-10
No files found.
openedx/core/djangoapps/xmodule_django/models.py
View file @
4223bf70
...
@@ -6,6 +6,7 @@ import warnings
...
@@ -6,6 +6,7 @@ import warnings
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
from
django.db
import
models
from
django.db.models.lookups
import
IsNull
from
opaque_keys.edx.keys
import
BlockTypeKey
,
CourseKey
,
UsageKey
from
opaque_keys.edx.keys
import
BlockTypeKey
,
CourseKey
,
UsageKey
from
openedx.core.djangoapps.util.model_utils
import
CreatorMixin
from
openedx.core.djangoapps.util.model_utils
import
CreatorMixin
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
...
@@ -116,16 +117,6 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
...
@@ -116,16 +117,6 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
else
:
else
:
return
value
return
value
def
get_prep_lookup
(
self
,
lookup
,
value
):
if
lookup
==
'isnull'
:
raise
TypeError
(
'Use {0}.Empty rather than None to query for a missing {0}'
.
format
(
self
.
__class__
.
__name__
))
return
super
(
OpaqueKeyField
,
self
)
.
get_prep_lookup
(
lookup
,
# strip key before comparing
_strip_value
(
value
,
lookup
)
)
def
get_prep_value
(
self
,
value
):
def
get_prep_value
(
self
,
value
):
if
value
is
self
.
Empty
or
value
is
None
:
if
value
is
self
.
Empty
or
value
is
None
:
return
''
# CharFields should use '' as their empty value, rather than None
return
''
# CharFields should use '' as their empty value, rather than None
...
@@ -159,6 +150,19 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
...
@@ -159,6 +150,19 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
return
super
(
OpaqueKeyField
,
self
)
.
run_validators
(
value
)
return
super
(
OpaqueKeyField
,
self
)
.
run_validators
(
value
)
class
OpaqueKeyFieldEmptyLookupIsNull
(
IsNull
):
"""
This overrides the default __isnull model filter to help enforce the special way
we handle null / empty values in OpaqueKeyFields.
"""
def
get_prep_lookup
(
self
):
raise
TypeError
(
"Use this field's .Empty member rather than None or __isnull "
"to query for missing objects of this type."
)
OpaqueKeyField
.
register_lookup
(
OpaqueKeyFieldEmptyLookupIsNull
)
class
CourseKeyField
(
OpaqueKeyField
):
class
CourseKeyField
(
OpaqueKeyField
):
"""
"""
A django Field that stores a CourseKey object as a string.
A django Field that stores a CourseKey object as a string.
...
...
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