This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move initial queryset filter logic for sources and collections to Bas…
…e views
- Loading branch information
Showing
4 changed files
with
38 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,5 @@ | ||
from oclapi.filters import ConceptContainerPermissionedSearchFilter | ||
from django.contrib.auth.models import AnonymousUser | ||
|
||
from users.models import USER_OBJECT_TYPE | ||
|
||
|
||
class CollectionSearchFilter(ConceptContainerPermissionedSearchFilter): | ||
def get_filters(self, request, view): | ||
filters = super(CollectionSearchFilter, self).get_filters(request, view) | ||
|
||
user = request.QUERY_PARAMS.get('user', None) | ||
if user: | ||
filters.update({'owner': user, 'ownerType': USER_OBJECT_TYPE}) | ||
|
||
if view.parent_resource: | ||
filters.update({'owner': view.parent_resource.mnemonic}) | ||
filters.update({'ownerType': view.parent_resource.resource_type()}) | ||
|
||
if isinstance(request.user, AnonymousUser): | ||
filters.update({'public_can_view': True}) | ||
|
||
return filters | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,5 @@ | ||
from oclapi.filters import ConceptContainerPermissionedSearchFilter | ||
from django.contrib.auth.models import AnonymousUser | ||
|
||
|
||
class SourceSearchFilter(ConceptContainerPermissionedSearchFilter): | ||
def get_filters(self, request, view): | ||
filters = super(SourceSearchFilter, self).get_filters(request, view) | ||
if view.parent_resource: | ||
filters.update({'owner': view.parent_resource.mnemonic}) | ||
filters.update({'ownerType': view.parent_resource.resource_type()}) | ||
|
||
if isinstance(request.user, AnonymousUser): | ||
filters.update({'public_can_view': True}) | ||
|
||
return filters | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters