more filters (type, subject)
[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     language = tag_filter('language')
19     license = tag_filter('rights')
20     audience = tag_filter('audience')
21     resource_type = tag_filter('type')
22     subject = tag_filter('subject')
23
24     class Meta:
25         model = Organization
26         fields = []
27
28     def filter_by_tag(self, queryset, name, value):
29         if not value:
30             return queryset
31         return queryset.filter(document__tags__in=value).distinct()