Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
99
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
djangoldp-packages
djangoldp
Commits
8d3fba6b
Commit
8d3fba6b
authored
4 years ago
by
Calum Mackervoy
Browse files
Options
Downloads
Patches
Plain Diff
added FilterBackends for local objects
parent
22a0e910
No related branches found
No related tags found
1 merge request
!123
Container urls not contain backlinks
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp/filters.py
+23
-0
23 additions, 0 deletions
djangoldp/filters.py
with
23 additions
and
0 deletions
djangoldp/filters.py
0 → 100644
+
23
−
0
View file @
8d3fba6b
from
rest_framework.filters
import
BaseFilterBackend
from
djangoldp.models
import
Model
class
LocalObjectFilterBackend
(
BaseFilterBackend
):
"""
Filter which removes external objects (federated backlinks) from the queryset
For querysets which should only include local objects
"""
def
filter_queryset
(
self
,
request
,
queryset
,
view
):
internal_ids
=
[
x
.
pk
for
x
in
queryset
if
not
Model
.
is_external
(
x
)]
return
queryset
.
filter
(
pk__in
=
internal_ids
)
class
LocalObjectOnContainerPathBackend
(
LocalObjectFilterBackend
):
"""
Override of LocalObjectFilterBackend which removes external objects when the view requested
is the model container path
"""
def
filter_queryset
(
self
,
request
,
queryset
,
view
):
if
issubclass
(
view
.
model
,
Model
)
and
request
.
path_info
==
view
.
model
.
get_container_path
():
return
super
(
LocalObjectOnContainerPathBackend
,
self
).
filter_queryset
(
request
,
queryset
,
view
)
return
queryset
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