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
4223bf70
Unverified
Commit
4223bf70
authored
7 years ago
by
Brian Mesick
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #16567 from edx/bmedx/django111_get_prep_lookup
Change get_prep_lookup to a Lookup
parents
ebe85737
31f11709
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/djangoapps/xmodule_django/models.py
+14
-10
14 additions, 10 deletions
openedx/core/djangoapps/xmodule_django/models.py
with
14 additions
and
10 deletions
openedx/core/djangoapps/xmodule_django/models.py
+
14
−
10
View file @
4223bf70
...
...
@@ -6,6 +6,7 @@ import warnings
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
from
django.db.models.lookups
import
IsNull
from
opaque_keys.edx.keys
import
BlockTypeKey
,
CourseKey
,
UsageKey
from
openedx.core.djangoapps.util.model_utils
import
CreatorMixin
from
xmodule.modulestore.django
import
modulestore
...
...
@@ -116,16 +117,6 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
else
:
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
):
if
value
is
self
.
Empty
or
value
is
None
:
return
''
# CharFields should use '' as their empty value, rather than None
...
...
@@ -159,6 +150,19 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
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
):
"""
A django Field that stores a CourseKey object as a string.
...
...
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