better ordering for tags
[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
22     class Meta:
23         model = Organization
24         fields = []
25
26     def filter_by_tag(self, queryset, name, value):
27         if not value:
28             return queryset
29         return queryset.filter(document__tags__in=value).distinct()