Commit d5ab4d59 authored by Robert's avatar Robert

WIP

parent 4947d9a4
Pipeline #1928 failed with stage
in 3 minutes and 50 seconds
......@@ -9,9 +9,23 @@ from grouprise.features.groups.models import Group
from grouprise.features.images.models import Image
class KeywordFilter(filters.CharFilter):
def __init__(self, *args, lookups=[], **kwargs):
self.lookups = lookups
self.method = 'filter_keywords'
super().__init__(*args, **kwargs)
def filter_keywords(self, queryset, name, value):
keywords = value.split()
for keyword in keywords:
q_expressions = [Q(**{l: keyword}) for l in self.lookups]
queryset = queryset.filter(reduce(lambda q1, q2: q1 | q2, q_expressions))
return queryset
class ContentFilterSet(filters.FilterSet):
keywords = filters.CharFilter(method='filter_keywords')
keywords = KeywordFilter(lookups = ['content__title__icontains', 'slug__icontains'])
type = filters.ChoiceFilter(
choices=(
......@@ -30,14 +44,6 @@ class ContentFilterSet(filters.FilterSet):
},
)
def filter_keywords(self, queryset, name, value):
lookups = ['content__title__icontains', 'slug__icontains']
keywords = value.split()
for keyword in keywords:
q_expressions = [Q(**{l: keyword}) for l in lookups]
queryset = queryset.filter(reduce(lambda q1, q2: q1 | q2, q_expressions))
return queryset
def filter_type(self, queryset, name, value):
if value == 'articles':
queryset = queryset.filter_articles()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment