update requirements
[redakcja.git] / apps / organizations / filters.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 import django_filters
7 from django.forms.widgets import TextInput
8 from django.utils.translation import ugettext_lazy as _
9
10 from catalogue.filters import tag_filter
11 from organizations.models import Organization
12
13
14 class OrganizationFilterSet(django_filters.FilterSet):
15     name = django_filters.CharFilter(
16         lookup_expr='icontains', label='',
17         widget=TextInput(attrs={'placeholder': _('name')}))
18     subject = tag_filter('subject')
19
20     class Meta:
21         model = Organization
22         fields = []
23
24     def filter_by_tag(self, queryset, name, value):
25         if not value:
26             return queryset
27         return queryset.filter(document__tags__in=value).distinct()