class CommunityHealthUnitFilter(CommonFieldsFilterset): def chu_pending_approval(self, value): if value in TRUTH_NESS: return self.filter( Q(is_approved=False, is_rejected=False, has_edits=False) | Q(is_approved=True, is_rejected=False, has_edits=True) | Q(is_approved=False, is_rejected=True, has_edits=True)) else: return self.filter( Q(is_approved=True, is_rejected=False, has_edits=False) | Q(is_approved=False, is_rejected=True, has_edits=False)) name = django_filters.CharFilter(lookup_type='icontains') ward = ListCharFilter(name='facility__ward') constituency = ListCharFilter(name='facility__ward__constituency') county = ListCharFilter(name='facility__ward__constituency__county') is_approved = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_rejected = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) has_edits = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) pending_approval = django_filters.MethodFilter(action=chu_pending_approval) class Meta(object): model = CommunityHealthUnit
class FacilityExportExcelMaterialViewFilter(django_filters.FilterSet): search = SearchFilter(name='search') county = ListCharFilter(lookup_type='exact') code = ListCharFilter(lookup_type='exact') constituency = ListCharFilter(lookup_type='exact') ward = ListCharFilter(lookup_type='exact') owner = ListCharFilter(lookup_type='exact') owner_type = ListCharFilter(lookup_type='exact') number_of_beds = ListIntegerFilter(lookup_type='exact') number_of_cots = ListIntegerFilter(lookup_type='exact') open_whole_day = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_late_night = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_weekends = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_public_holidays = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) keph_level = ListCharFilter(lookup_type='exact') facility_type = ListCharFilter(lookup_type='exact') operation_status = ListCharFilter(lookup_type='exact') service = ListUUIDFilter(lookup_type='exact', name='services') service_category = ListUUIDFilter(lookup_type='exact', name='categories') class Meta(object): model = FacilityExportExcelMaterialView
class CommonFieldsFilterset(django_filters.FilterSet): """ Every model that descends from AbstractBase should have this """ active = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) deleted = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) updated_before = IsoDateTimeFilter( field_name='updated_at', lookup_expr='lte', input_formats=DATE_INPUT_FORMATS) created_before = IsoDateTimeFilter( field_name='created_at', lookup_expr='lte', input_formats=DATE_INPUT_FORMATS) updated_after = IsoDateTimeFilter( field_name='updated_at', lookup_expr='gte', input_formats=DATE_INPUT_FORMATS) created_after = IsoDateTimeFilter( field_name='created_at', lookup_expr='gte', input_formats=DATE_INPUT_FORMATS) updated_on = IsoDateTimeFilter( field_name='updated_at', lookup_expr='exact', input_formats=DATE_INPUT_FORMATS) created_on = IsoDateTimeFilter( field_name='created_at', lookup_expr='exact', input_formats=DATE_INPUT_FORMATS)
class FacilityFilter(CommonFieldsFilterset): name = django_filters.CharFilter(lookup_type='icontains') code = django_filters.NumberFilter(lookup_type='exact') description = django_filters.CharFilter(lookup_type='icontains') facility_type = django_filters.AllValuesFilter(lookup_type='exact') operation_status = django_filters.AllValuesFilter(lookup_type='exact') ward = django_filters.AllValuesFilter(lookup_type='exact') owner = django_filters.AllValuesFilter(lookup_type='exact') officer_in_charge = django_filters.AllValuesFilter(lookup_type='exact') number_of_beds = django_filters.NumberFilter(lookup_type='exact') number_of_cots = django_filters.NumberFilter(lookup_type='exact') open_whole_day = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_whole_week = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_classified = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_published = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(object): model = Facility
class FacilityUpgradeFilter(CommonFieldsFilterset): is_confirmed = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_cancelled = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(object): model = FacilityUpgrade
class FacilityServiceFilter(CommonFieldsFilterset): facility = django_filters.AllValuesFilter(lookup_type='exact') option = django_filters.AllValuesFilter(lookup_type='exact') is_confirmed = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_cancelled = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(object): model = FacilityService
class FacilityInfrastructureFilter(CommonFieldsFilterset): facility = django_filters.AllValuesFilter(lookup_expr='exact') infrastructure = django_filters.AllValuesFilter(lookup_expr='exact') is_confirmed = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_cancelled = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(CommonFieldsFilterset.Meta): model = FacilityInfrastructure
class CommonFieldsFilterset(django_filters.FilterSet): """Every model that descends from AbstractBase should have this The usage pattern for this is presently simplistic; mix it in, then add to the `fields` in the filter's `Meta` `'updated', 'created', updated_before', 'created_before', 'updated_after', 'created_after'' and any other applicable / extra fields. When you inherit this, DO NOT add a `fields` declaration. Let the implicit filter fields ( every model field gets one ) stay in place. """ updated_before = IsoDateTimeFilter(name='updated', lookup_expr='lte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) created_before = IsoDateTimeFilter(name='created', lookup_expr='lte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) updated_after = IsoDateTimeFilter(name='updated', lookup_expr='gte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) created_after = IsoDateTimeFilter(name='created', lookup_expr='gte', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) updated_on = IsoDateTimeFilter(name='updated', lookup_expr='exact', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) created_on = IsoDateTimeFilter(name='created', lookup_expr='exact', input_formats=(ISO_8601, '%m/%d/%Y %H:%M:%S')) is_deleted = django_filters.TypedChoiceFilter(name='deleted', choices=BOOLEAN_CHOICES, coerce=strtobool) is_active = django_filters.TypedChoiceFilter(name='active', choices=BOOLEAN_CHOICES, coerce=strtobool) search = ClassicSearchFilter(name='name') q = ClassicSearchFilter(name='name') search_auto = AutoCompleteSearchFilter(name='name') q_auto = AutoCompleteSearchFilter(name='name') class Meta: fields = '__all__'
class SampleFilter(django_filters.FilterSet): class Meta: model = Sample fields = ['md5', 'sha1', 'sha2', 'name', 'size', 'file_type'] md5 = django_filters.CharFilter(label='MD5', lookup_expr='icontains') sha1 = django_filters.CharFilter(label='SHA1', lookup_expr='icontains') sha2 = django_filters.CharFilter(label='SHA2', lookup_expr='icontains') name = django_filters.CharFilter(label='File name', lookup_expr='icontains') size_gte = django_filters.NumberFilter(label='Minimum Size', field_name='size', lookup_expr='gte') size_lte = django_filters.NumberFilter(label='Maximum Size', field_name='size', lookup_expr='lte') uploaded_on = django_filters.DateTimeFromToRangeFilter(widget=RangeWidget(attrs={'placeholder': 'MM/DD/YYYY'})) file_type = django_filters.TypedChoiceFilter(choices=FILE_TYPE_CHOICES) redisjob__status = django_filters.TypedChoiceFilter(choices=REDIS_JOB_CHOICES, label='Status') result__processed_on = django_filters.DateTimeFromToRangeFilter(widget=RangeWidget(attrs={'placeholder': 'MM/DD/YYYY'}))
class CustomerFilter(django_filters.FilterSet): papers = django_filters.TypedChoiceFilter(label='Doklady DPH', widget=widgets.BooleanWidget, choices=PAPERS_CHOICES) road_tax = django_filters.TypedChoiceFilter(label='Silniční daň', widget=widgets.BooleanWidget, choices=ROAD_TAX_CHOICES) name = django_filters.CharFilter(label='Název subjektu', lookup_expr='icontains') ico = django_filters.CharFilter(label='IČO', lookup_expr='startswith') tax_term = django_filters.TypedChoiceFilter(choices=TAX_CHOICES) class Meta: model = Customer fields = []
class ListingFilter(df.FilterSet): tags = df.Filter(field_name='tags', lookup_expr='icontains') categories = df.Filter(field_name='categories', lookup_expr='icontains') rating = df.Filter(field_name='rating_average', lookup_expr='gte') connection = df.TypedChoiceFilter(field_name='profile__connection_type', choices=Profile.CONNECTION_TYPE_CHOICES) condition_type = df.ChoiceFilter(choices=Listing.CONDITION_TYPE_CHOICES) contract_type = df.NumberFilter(field_name='contract_type', lookup_expr='icontains') moderator_count = df.NumberFilter( method='filter_listing_by_moderator_count') moderator_verified = df.Filter(field_name='moderators__verified', widget=TruthyWidget()) online = df.Filter(field_name='profile__online', widget=TruthyWidget()) class Meta: model = Listing exclude = ['nsfw'] order_by = True filter_overrides = { ArrayField: { 'filter_class': df.CharFilter, 'extra': lambda f: { 'lookup_expr': 'icontains', }, }, } def filter_listing_contract_type(self, queryset, name, value): return queryset.filter(contract_type=value) def filter_listing_by_moderator_count(self, queryset, name, value): return queryset.filter(moderators_count__gte=value)
class MFLUserFilter(CommonFieldsFilterset): is_active = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(CommonFieldsFilterset.Meta): model = MflUser fields = ('is_active', )
class ServiceRatingFilter(CommonFieldsFilterset): facility_service = django_filters.AllValuesFilter(lookup_type='exact') cleanliness = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) attitude = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) will_return = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) occupation = django_filters.CharFilter(lookup_type='icontains') comment = django_filters.CharFilter(lookup_type='icontains') service = django_filters.AllValuesFilter(name='facility_service__service', lookup_type='exact') facility = django_filters.AllValuesFilter( name='facility_service__facility', lookup_type='exact') class Meta(object): model = ServiceRating
class ArtistFilter(django_filters.FilterSet): name = django_filters.CharFilter(action=search_name) instruments = django_filters.ModelChoiceFilter( queryset=Instrument.objects.all()) is_invited = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, action=is_invited) has_registered = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, action=has_registered) has_photo = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, name="photo", action=has_photo) signed_legal_agreement = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, action=has_signed) class Meta: fields = [ 'name', 'is_invited', 'has_registered', 'has_photo', 'signed_legal_agreement', 'instruments' ] model = Artist order_by = ( ('last_name', 'Last name'), ('-last_name', 'Last name desc'), ('events_count', 'Events count'), ('-events_count', 'Events count desc'), ('instruments', 'Instrument'), ('-instruments', 'Instrument desc'), ) strict = False def __init__(self, *args, **kwargs): super(ArtistFilter, self).__init__(*args, **kwargs) self.filters['has_registered'].label = 'Registered' self.filters['has_photo'].label = 'Has photo' self.filters['signed_legal_agreement'].label = 'Signed' @property def form(self): form = super(ArtistFilter, self).form # it's a property, so there's no method call for field in self.Meta.fields: form.fields[field].widget.attrs[ 'class'] = 'form-control selectpicker' form.fields['name'].widget.attrs['class'] = 'form-control search' form.fields['name'].widget.attrs['placeholder'] = 'Search by name' return form
class FacilityApprovalFilter(CommonFieldsFilterset): facility = django_filters.AllValuesFilter(lookup_type='exact') comment = django_filters.CharFilter(lookup_type='icontains') is_cancelled = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(object): model = FacilityApproval
class OptionFilter(CommonFieldsFilterset): value = django_filters.CharFilter(lookup_type='icontains') display_text = django_filters.CharFilter(lookup_type='icontains') option_type = django_filters.CharFilter(lookup_type='icontains') is_exclusive_option = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(object): model = Option
class UserFilter(django_filters.FilterSet): is_manager = django_filters.TypedChoiceFilter(choices=[('true', 'true'), ('false', 'false')], coerce=strtobool) class Meta: model = User fields = [ 'is_manager', ]
class TranMainFilter(django_filters.FilterSet): TranNo = CharFilter(label='بحث برقم القيد',field_name='TranNo', lookup_expr='icontains') Post = django_filters.TypedChoiceFilter(label='الحالة',field_name='Post',choices=BOOLEAN_CHOICES, coerce=strtobool) start_date = DateFilter(label='من تاريخ',field_name="TranDate", lookup_expr='gte') end_date = DateFilter(label='الى',field_name="TranDate", lookup_expr='lte') class Meta: model= TranTableMain fields=['TranNo', ]
class FacilityExportExcelMaterialViewFilter(django_filters.FilterSet): def filter_number_beds(self, qs, name, value): return qs.filter(beds__gte=1) def filter_number_cots(self, qs, name, value): return qs.filter(cots__gte=1) search = ClassicSearchFilter(name='search') county = ListCharFilter(lookup_expr='exact') code = ListCharFilter(lookup_expr='exact') constituency = ListCharFilter(lookup_expr='exact') ward = ListCharFilter(lookup_expr='exact') owner = ListCharFilter(lookup_expr='exact') owner_type = ListCharFilter(lookup_expr='exact') number_of_beds = django_filters.CharFilter(method='filter_number_beds') number_of_cots = django_filters.CharFilter(method='filter_number_cots') open_whole_day = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) open_late_night = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) open_weekends = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) open_public_holidays = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) keph_level = ListCharFilter(lookup_expr='exact') facility_type = ListCharFilter(lookup_expr='exact') operation_status = ListCharFilter(lookup_expr='exact') service = ListUUIDFilter(lookup_expr='exact', name='services') service_category = ListUUIDFilter(lookup_expr='exact', name='categories') service_name = ClassicSearchFilter(name='service_names') approved_national_level = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta(CommonFieldsFilterset.Meta): model = FacilityExportExcelMaterialView exclude = ('services', 'categories', 'service_names', )
class EntryFilter(django_filters.FilterSet): title = django_filters.CharFilter(name="title", lookup_type="icontains") date = django_filters.DateFilter(name="date", lookup_type="exact") date_lt = django_filters.DateFilter(name="date", lookup_type="lt") date_gt = django_filters.DateFilter(name="date", lookup_type="gt") sticky = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) search_summary = django_filters.CharFilter(name="summary", lookup_type="icontains") class Meta: model = Entry fields = ("status", "date", "sticky", "section", "category", "tags",)
class StationFilter(flt.FilterSet): mindate = flt.IsoDateTimeFilter(name='time', lookup_expr='date__gte') maxdate = flt.IsoDateTimeFilter(name='time', lookup_expr='date__lte') month = flt.TypedChoiceFilter(name='time', lookup_expr='month', choices=[(x, x) for x in MONTHS], coerce=month_number) season = flt.TypedChoiceFilter(name='time', lookup_expr='month__in', choices=[(x, x) for x in SEASONS.keys()], coerce=season_month_numbers) minlat = flt.NumberFilter(name='location', lookup_expr='lat__gte') maxlat = flt.NumberFilter(name='location', lookup_expr='lat__lte') minlon = flt.NumberFilter(name='location', lookup_expr='lon__gte') maxlon = flt.NumberFilter(name='location', lookup_expr='lon__lte') class Meta: model = Station fields = []
class ContasFilter(django_filters.FilterSet): descricao = django_filters.CharFilter(lookup_expr='icontains') data_inicial = DateFilter(field_name="vencimento", lookup_expr='gte') data_final = DateFilter(field_name="vencimento", lookup_expr='lte') pago = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) class Meta: model = ContaPagamento fields = [ 'descricao', 'centro_de_custo', 'pago', 'fornecedor', ]
class ProfileFilter(django_filters.FilterSet): #acceptedCurrencies = django_filters.Filter(name='moderator_accepted_currencies', lookup_expr='icontains') rating = django_filters.Filter(name='rating_average', lookup_expr='gte') version = django_filters.Filter(name='user_agent', lookup_expr='icontains') moderator_languages = django_filters.Filter(name='moderator_languages', lookup_expr='contains') has_email = django_filters.Filter(name='email', lookup_expr='isnull', exclude=True, widget=BooleanWidget()) has_website = django_filters.Filter(name='website', lookup_expr='isnull', exclude=True, widget=BooleanWidget()) is_moderator = django_filters.BooleanFilter(name='moderator', lookup_expr='exact', widget=BooleanWidget()) is_verified = django_filters.Filter(name='verified', exclude=False, widget=TruthyWidget()) has_verified = django_filters.Filter(name='listing__moderators__verified', widget=TruthyWidget()) moderator_count = django_filters.NumberFilter( method='filter_listing_by_moderator_count') connection = django_filters.TypedChoiceFilter( name='connection_type', choices=Profile.CONNECTION_TYPE_CHOICES) online = django_filters.Filter(name='online', widget=TruthyWidget()) #pgp_block = django_filters.BooleanFilter(name='description', method='filter_published') class Meta: model = Profile exclude = () order_by = True filter_overrides = { ArrayField: { 'filter_class': django_filters.CharFilter, 'extra': lambda f: { 'lookup_expr': 'icontains', }, }, } def filter_listing_by_moderator_count(self, queryset, name, value): return queryset.filter(moderators_count__gte=value)
class EventRequestFilter(django_filters.FilterSet): assigned_to = ForeignKeyAllValuesFilter(Person) country = AllCountriesFilter() active = django_filters.TypedChoiceFilter( choices=(('true', 'Open'), ('false', 'Closed')), coerce=strtobool, label='Status', widget=django.forms.widgets.RadioSelect, ) class Meta: model = EventRequest fields = [ 'assigned_to', 'workshop_type', 'active', 'country', ] order_by = ['-created_at', 'created_at']
class ListingFilter(django_filters.FilterSet): acceptedCurrencies = django_filters.Filter(name='accepted_currencies', lookup_expr='icontains') tags = django_filters.Filter(name='tags', lookup_expr='icontains') categories = django_filters.Filter(name='categories', lookup_expr='icontains') rating = django_filters.Filter(name='rating_average', lookup_expr='gte') connection = django_filters.TypedChoiceFilter( name='profile__connection_type', choices=Profile.CONNECTION_TYPE_CHOICES) condition_type = django_filters.ChoiceFilter( choices=Listing.CONDITION_TYPE_CHOICES) contract_type = django_filters.NumberFilter(name='contract_type', lookup_expr='icontains') moderator_count = django_filters.NumberFilter( method='filter_listing_by_moderator_count') moderator_verified = django_filters.Filter(name='moderators__verified', widget=TruthyWidget()) online = django_filters.Filter(name='profile__online', widget=TruthyWidget()) #dust = django_filters.BooleanFilter(name='dust', widget=FalsyWidget()) class Meta: model = Listing exclude = () order_by = True strict = STRICTNESS.IGNORE filter_overrides = { ArrayField: { 'filter_class': django_filters.CharFilter, 'extra': lambda f: { 'lookup_expr': 'icontains', }, }, } def filter_listing_contract_type(self, queryset, name, value): return queryset.filter(contract_type=value) def filter_listing_by_moderator_count(self, queryset, name, value): return queryset.filter(moderators_count__gte=value)
class ProfileFilter(df.FilterSet): rating = df.Filter(field_name='rating_average', lookup_expr='gte') user_agent = df.Filter(field_name='user_agent', lookup_expr='icontains') moderator_languages = df.Filter(field_name='moderator_languages', lookup_expr='contains') has_email = df.Filter(field_name='email', lookup_expr='isnull', exclude=True, widget=BooleanWidget()) has_website = df.Filter(field_name='website', lookup_expr='isnull', exclude=True, widget=BooleanWidget()) is_moderator = df.BooleanFilter(field_name='moderator', lookup_expr='exact', widget=BooleanWidget()) is_verified = df.Filter(field_name='verified', exclude=False, widget=TruthyWidget()) has_verified = df.Filter(field_name='listing__moderators__verified', widget=TruthyWidget()) moderator_count = df.NumberFilter( method='filter_listing_by_moderator_count') connection = df.TypedChoiceFilter(field_name='connection_type', choices=Profile.CONNECTION_TYPE_CHOICES) online = df.Filter(field_name='online', widget=TruthyWidget()) class Meta: model = Profile filter_overrides = { ArrayField: { 'filter_class': df.CharFilter, 'extra': lambda f: { 'lookup_expr': 'icontains', }, }, } exclude = ['nsfw'] order_by = True def filter_listing_by_moderator_count(self, queryset, name, value): return queryset.filter(moderators_count__gte=value)
class JobOfferFilter(django_filters.FilterSet): title = django_filters.CharFilter( name='title', label=_('title').capitalize(), lookup_expr='icontains', ) description = django_filters.CharFilter( name='description', label=_('description').capitalize(), lookup_expr='icontains', ) contract_type = django_filters.TypedChoiceFilter( name='contract_type', label=_('contract_type').capitalize(), lookup_expr='icontains', choices=JobOffer.JOB_TYPES, ) class Meta: model = JobOffer fields = []
class CompanyFilter(CrispyFilterMixin, django_filters.FilterSet): verified = django_filters.TypedChoiceFilter( choices=((None, _("----")), (True, _("Tak")), (False, _("Nie"))), coerce=strtobool, label=_(u"Dane zweryfikowane")) class Meta: model = Company fields = { 'nip': ['icontains'], 'name': ['icontains'], 'official_name': ['icontains'], 'common_name': ['icontains'], 'Editor_notes': ['icontains'], } order_by = ( ('name', _('Nazwa (A-Z)')), ('-name', _('Nazwa (Z-A)')), ('query_count', _(u'Liczba zapytań (rosnąco)')), ('-query_count', _(u'Liczba zapytań (malejąco)')), )
class FacilityFilter(CommonFieldsFilterset): def service_filter(self, value): categories = value.split(',') facility_ids = [] for facility in self.filter(): for cat in categories: service_count = FacilityService.objects.filter( service__category=cat, facility=facility).count() if service_count > 0: facility_ids.append(facility.id) return self.filter(id__in=list(set(facility_ids))) def filter_approved_facilities(self, value): if value in TRUTH_NESS: return self.filter(Q(approved=True) | Q(rejected=True)) else: return self.filter(rejected=False, approved=False) def facilities_pending_approval(self, value): if value in TRUTH_NESS: return self.filter(Q(rejected=False), Q(has_edits=True) | Q(approved=False)) else: return self.filter( Q(rejected=True) | Q(has_edits=False) & Q(approved=True)) id = ListCharFilter(lookup_type='icontains') name = django_filters.CharFilter(lookup_type='icontains') code = ListIntegerFilter(lookup_type='exact') description = ListCharFilter(lookup_type='icontains') facility_type = ListCharFilter(lookup_type='icontains') keph_level = ListCharFilter(lookup_type='exact') operation_status = ListCharFilter(lookup_type='icontains') ward = ListCharFilter(lookup_type='icontains') sub_county = ListCharFilter(lookup_type='exact') sub_county_code = ListCharFilter(name="sub_county__code", lookup_type='exact') ward_code = ListCharFilter(name="ward__code", lookup_type='icontains') county_code = ListCharFilter(name='ward__constituency__county__code', lookup_type='icontains') constituency_code = ListCharFilter(name='ward__constituency__code', lookup_type='icontains') county = ListCharFilter(name='ward__constituency__county', lookup_type='exact') constituency = ListCharFilter(name='ward__constituency', lookup_type='icontains') owner = ListCharFilter(lookup_type='icontains') owner_type = ListCharFilter(name='owner__owner_type', lookup_type='exact') officer_in_charge = ListCharFilter(lookup_type='icontains') number_of_beds = ListIntegerFilter(lookup_type='exact') number_of_cots = ListIntegerFilter(lookup_type='exact') open_whole_day = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_late_night = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_weekends = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) open_public_holidays = django_filters.TypedChoiceFilter( choices=BOOLEAN_CHOICES, coerce=strtobool) is_classified = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_published = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) is_approved = django_filters.MethodFilter( action=filter_approved_facilities) service_category = django_filters.MethodFilter(action=service_filter) has_edits = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) rejected = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) regulated = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) approved = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) closed = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES, coerce=strtobool) pending_approval = django_filters.MethodFilter( action=facilities_pending_approval) class Meta(object): model = Facility
class ItemFilter(django_filters.FilterSet): description = django_filters.CharFilter(label='Item',field_name='description',lookup_expr='icontains') item = django_filters.TypedChoiceFilter(label='Item',field_name='item',choices=[('','')]) class Meta: model = Lead fields = ['item','description']