Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
thin logic
  • Loading branch information
Shtarev committed Jun 25, 2015
commit e8b23c47890d110071c2d26105596db6e9b94ac8
28 changes: 16 additions & 12 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class AutoFilterSet(self.default_filter_set):
class Meta:
model = queryset.model
fields = filter_fields

return AutoFilterSet

return None
Expand Down Expand Up @@ -98,22 +99,24 @@ def filter_queryset(self, request, queryset, view):

if not search_fields:
return queryset

if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle":
# Remember queryset for Oracle db users
original_queryset = queryset
orm_lookups = [self.construct_search(six.text_type(search_field))
for search_field in search_fields]
and_queries = []

for search_term in self.get_search_terms(request):
or_queries = [models.Q(**{orm_lookup: search_term})
for orm_lookup in orm_lookups]
and_queries.append(reduce(operator.or_, or_queries))

if and_queries:
# According to Oracle DB limits there is no capability to make a DISTINT on *LOB
if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle":
pk_list = queryset.filter(reduce(operator.and_, and_queries)).values_list('pk', flat=True)
return queryset.filter(pk__in=frozenset(pk_list))
else:
return queryset.filter(reduce(operator.and_, and_queries)).distinct()
queryset = queryset.filter(reduce(operator.or_, or_queries))
if settings.DATABASES[queryset.db]["ENGINE"] != "django.db.backends.oracle":
# Oracle db don't support distinct on *LOB fields
queryset = queryset.distinct()

if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle":
# distinct analogue for Oracle users
queryset = original_queryset.filter(pk__in=set(queryset.values_list('pk', flat=True)))

return queryset


Expand Down Expand Up @@ -160,7 +163,7 @@ def remove_invalid_fields(self, queryset, fields, view):
field.source or field_name
for field_name, field in serializer_class().fields.items()
if not getattr(field, 'write_only', False)
]
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be indented another level.

This is what is causing Flake8 to fail by the way.

elif valid_fields == '__all__':
# View explicitly allows filtering on any model field
valid_fields = [field.name for field in queryset.model._meta.fields]
Expand All @@ -182,6 +185,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
A filter backend that limits results to those where the requesting user
has read object level permissions.
"""

def __init__(self):
assert guardian, 'Using DjangoObjectPermissionsFilter, but django-guardian is not installed'

Expand Down