コード例 #1
0
class QuantityBFilter(PropertyFilterSet):
    who_ = CharFilter(
        field_name='who__username',
        lookup_expr='icontains',
    )
    time_left = PropertyCharFilter(
        field_name='time_left',
        lookup_expr='icontains',
    )
    books_borrowed = PropertyCharFilter(
        field_name='books_borrowed',
        lookup_expr='icontains',
    )
    quantity_borrowed = PropertyNumberFilter(
        field_name='quantity_borrowed',
        lookup_expr='gte',
    )

    class Meta:
        model = models.Quantity_Borrowed
        fields = (
            'who',
            'time_left',
            'books_borrowed',
            'quantity_borrowed',
        )
コード例 #2
0
class AllFiltersPropertyFilterSet(PropertyFilterSet):
    prop_number_AllValuesFilter = PropertyAllValuesFilter(field_name='prop_number', lookup_expr='exact')
    prop_number_PropertyAllValuesMultipleFilter_OR = PropertyAllValuesMultipleFilter(field_name='prop_number', lookup_expr='exact', conjoined=False)  # OR
    prop_number_PropertyAllValuesMultipleFilter_AND = PropertyAllValuesMultipleFilter(field_name='prop_number', lookup_expr='exact', conjoined=True)  # OR
    prop_number_PropertyBaseCSVFilterNumber = PropertyBaseCSVFilterNumber(field_name='prop_number', lookup_expr='in')
    prop_number_PropertyBaseInFilterNumber = PropertyBaseInFilterNumber(field_name='prop_number', lookup_expr='in')
    prop_number_PropertyBaseRangeFilterNumber = PropertyBaseRangeFilterNumber(field_name='prop_number', lookup_expr='range')
    prop_is_true_PropertyBooleanFilter = PropertyBooleanFilter(field_name='prop_is_true', lookup_expr='exact')
    prop_text_PropertyCharFilter = PropertyCharFilter(field_name='prop_text', lookup_expr='exact')
    prop_number_PropertyChoiceFilter = PropertyChoiceFilter(field_name='prop_number', lookup_expr='exact', choices=NUMBER_CHOICES)
    prop_date_PropertyDateFilter = PropertyDateFilter(field_name='prop_date', lookup_expr='exact')
    prop_date_PropertyDateFromToRangeFilter = PropertyDateFromToRangeFilter(field_name='prop_date', lookup_expr='range')
    prop_date_PropertyDateRangeFilter = PropertyDateRangeFilter(field_name='prop_date', lookup_expr='exact')
    prop_date_time_PropertyDateTimeFilter = PropertyDateTimeFilter(field_name='prop_date_time', lookup_expr='exact')
    prop_date_time_PropertyDateTimeFromToRangeFilter = PropertyDateTimeFromToRangeFilter(field_name='prop_date_time', lookup_expr='range')
    prop_duration_PropertyDurationFilter = PropertyDurationFilter(field_name='prop_duration', lookup_expr='exact')
    prop_iso_date_time_PropertyIsoDateTimeFilter = PropertyIsoDateTimeFilter(field_name='prop_iso_date_time', lookup_expr='lt')
    prop_iso_date_time_PropertyIsoDateTimeFromToRangeFilter = PropertyIsoDateTimeFromToRangeFilter(field_name='prop_iso_date_time', lookup_expr='range')
    prop_number_PropertyMultipleChoiceFilter_OR = PropertyMultipleChoiceFilter(field_name='prop_number', lookup_expr='exact', conjoined=False, choices=NUMBER_CHOICES)
    prop_number_PropertyMultipleChoiceFilter_AND = PropertyMultipleChoiceFilter(field_name='prop_number', lookup_expr='exact', conjoined=True, choices=NUMBER_CHOICES)
    prop_number_PropertyNumberFilter = PropertyNumberFilter(field_name='prop_number', lookup_expr='exact')
    prop_number_PropertyOrderingFilter = PropertyOrderingFilter(fields=('prop_number', 'prop_number'))
    prop_number_PropertyRangeFilter = PropertyRangeFilter(field_name='prop_number', lookup_expr='range')
    prop_time_PropertyTimeFilter = PropertyTimeFilter(field_name='prop_time', lookup_expr='exact')
    prop_time_PropertyTimeRangeFilter = PropertyTimeRangeFilter(field_name='prop_time', lookup_expr='range')
    prop_number_PropertyTypedChoiceFilter = PropertyTypedChoiceFilter(field_name='prop_number', lookup_expr='exact', choices=NUMBER_CHOICES)
    prop_number_PropertyTypedMultipleChoiceFilter_OR = PropertyTypedMultipleChoiceFilter(field_name='prop_number', lookup_expr='exact', conjoined=False, choices=NUMBER_CHOICES)
    prop_number_PropertyTypedMultipleChoiceFilter_AND = PropertyTypedMultipleChoiceFilter(field_name='prop_number', lookup_expr='exact', conjoined=True, choices=NUMBER_CHOICES)
    prop_uuid_PropertyUUIDFilter = PropertyUUIDFilter(field_name='prop_uuid', lookup_expr='exact')
    prop_number_PropertyLookupChoiceFilter = PropertyLookupChoiceFilter(field_name='prop_number')

    class Meta:
        model = BenchmarkModel
        exclude = ['number', 'text', 'is_true', 'date', 'date_time', 'duration']
コード例 #3
0
    class PropertyCharFilterSet(PropertyFilterSet):
        name = CharFilter(field_name='name', lookup_expr=lookup_xpr)
        prop_name = PropertyCharFilter(field_name='prop_name',
                                       lookup_expr=lookup_xpr)

        class Meta:
            model = CharFilterModel
            fields = ['prop_name']
コード例 #4
0
class DefaultTaxonFilter(PropertyFilterSet):
    """
    デフォルト分類情報のフィルタセット
    """
    scientific_name = PropertyCharFilter(field_name='scientific_name',
                                         lookup_expr='icontains')

    class Meta:
        model = DefaultTaxon
        fields = [
            'kingdom', 'phylum', 'class_name', 'order', 'suborder', 'family',
            'subfamily', 'tribe', 'subtribe', 'genus', 'subgenus', 'species',
            'subspecies', 'scientific_name_author', 'name_publishedin_year',
            'japanese_name', 'distribution', 'note', 'created_at',
            'scientific_name', 'change_genus_brackets',
            'unknown_author_brackets',
            'unknown_name_publishedin_year_brackets', 'actual_dist_year'
        ]
        filter_overrides = {
            models.CharField: {
                'filter_class': filters.CharFilter,
                'extra': lambda f: {
                    'lookup_expr': 'icontains',
                },
            },
            models.TextField: {
                'filter_class': filters.CharFilter,
                'extra': lambda f: {
                    'lookup_expr': 'icontains',
                },
            },
            models.IntegerField: {
                'filter_class': filters.RangeFilter,
            },
            models.DateTimeField: {
                'filter_class': filters.DateTimeFilter,
                'extra': lambda f: {
                    'lookup_expr': 'date',
                }
            },
            models.BooleanField: {
                'filter_class': filters.BooleanFilter,
            }
        }
コード例 #5
0
def test_default_lookup():
    my_filter = PropertyCharFilter(field_name='fake_field')
    assert my_filter.lookup_expr == 'exact'
コード例 #6
0
def test_unsupported_lookup():
    with pytest.raises(ValueError):
        PropertyCharFilter(field_name='fake_field', lookup_expr='fake-lookup')
コード例 #7
0
def test_supported_lookups(lookup):
    # Test expression not raises exception
    PropertyCharFilter(field_name='fake_field', lookup_expr=lookup)
コード例 #8
0
class SpecimenFilter(PropertyFilterSet):
    """
    標本情報のフィルタセット
    """
    date_identified = filters.DateFromToRangeFilter()
    date_last_modified = filters.DateFromToRangeFilter()
    collection_code = filters.NumberFilter(lookup_expr='exact')
    collection_code_range = filters.RangeFilter(field_name='collection_code')
    kingdom = PropertyCharFilter(field_name='kingdom', lookup_expr='icontains')
    phylum = PropertyCharFilter(field_name='phylum', lookup_expr='icontains')
    class_name = PropertyCharFilter(field_name='class_name',
                                    lookup_expr='icontains')
    order = PropertyCharFilter(field_name='order', lookup_expr='icontains')
    suborder = PropertyCharFilter(field_name='suborder',
                                  lookup_expr='icontains')
    family = PropertyCharFilter(field_name='family', lookup_expr='icontains')
    subfamily = PropertyCharFilter(field_name='subfamily',
                                   lookup_expr='icontains')
    tribe = PropertyCharFilter(field_name='tribe', lookup_expr='icontains')
    subtribe = PropertyCharFilter(field_name='subtribe',
                                  lookup_expr='icontains')
    genus = PropertyCharFilter(field_name='genus', lookup_expr='icontains')
    subgenus = PropertyCharFilter(field_name='subgenus',
                                  lookup_expr='icontains')
    species = PropertyCharFilter(field_name='species', lookup_expr='icontains')
    subspecies = PropertyCharFilter(field_name='subspecies',
                                    lookup_expr='icontains')
    scientific_name_author = PropertyCharFilter(
        field_name='scientific_name_author', lookup_expr='icontains')
    name_publishedin_year = PropertyRangeFilter(
        field_name='name_publishedin_year', lookup_expr='range')
    actual_dist_year = PropertyRangeFilter(field_name='actual_dist_year',
                                           lookup_expr='range')
    japanese_name = PropertyCharFilter(field_name='japanese_name',
                                       lookup_expr='icontains')
    change_genus_brackets = PropertyBooleanFilter(
        field_name='change_genus_brackets')
    unknown_author_brackets = PropertyBooleanFilter(
        field_name='unknown_author_brackets')
    unknown_name_publishedin_year_brackets = PropertyBooleanFilter(
        field_name='unknown_name_publishedin_year_brackets')

    class Meta:
        model = Specimen
        fields = [
            'default_taxon_info__kingdom', 'default_taxon_info__phylum',
            'default_taxon_info__class_name', 'default_taxon_info__order',
            'default_taxon_info__suborder', 'default_taxon_info__family',
            'default_taxon_info__subfamily', 'default_taxon_info__tribe',
            'default_taxon_info__subtribe', 'default_taxon_info__genus',
            'default_taxon_info__subgenus', 'default_taxon_info__species',
            'default_taxon_info__subspecies',
            'default_taxon_info__scientific_name_author',
            'default_taxon_info__name_publishedin_year',
            'default_taxon_info__actual_dist_year',
            'default_taxon_info__change_genus_brackets',
            'default_taxon_info__unknown_author_brackets',
            'default_taxon_info__unknown_name_publishedin_year_brackets',
            'default_taxon_info__japanese_name',
            'default_taxon_info__distribution', 'default_taxon_info__note',
            'custom_taxon_info__kingdom', 'custom_taxon_info__phylum',
            'custom_taxon_info__class_name', 'custom_taxon_info__order',
            'custom_taxon_info__suborder', 'custom_taxon_info__family',
            'custom_taxon_info__subfamily', 'custom_taxon_info__tribe',
            'custom_taxon_info__subtribe', 'custom_taxon_info__genus',
            'custom_taxon_info__subgenus', 'custom_taxon_info__species',
            'custom_taxon_info__subspecies',
            'custom_taxon_info__scientific_name_author',
            'custom_taxon_info__name_publishedin_year',
            'custom_taxon_info__actual_dist_year',
            'custom_taxon_info__change_genus_brackets',
            'custom_taxon_info__unknown_author_brackets',
            'custom_taxon_info__unknown_name_publishedin_year_brackets',
            'custom_taxon_info__japanese_name',
            'custom_taxon_info__distribution', 'custom_taxon_info__note',
            'collect_point_info__contient', 'collect_point_info__island_group',
            'collect_point_info__island', 'collect_point_info__country',
            'collect_point_info__state_provice', 'collect_point_info__county',
            'collect_point_info__municipality',
            'collect_point_info__verbatim_locality',
            'collect_point_info__japanese_place_name',
            'collect_point_info__japanese_place_name_detail',
            'collect_point_info__coordinate_precision',
            'collect_point_info__minimum_elevation',
            'collect_point_info__maximum_elevation',
            'collect_point_info__minimum_depth',
            'collect_point_info__maximum_depth', 'collect_point_info__note',
            'tour__title', 'collection_settings_info__collection_name',
            'collection_settings_info__institution_code', 'collection_code',
            'identified_by', 'date_identified', 'collecter', 'year', 'month',
            'day', 'sex', 'preparation_type', 'disposition',
            'sampling_protocol', 'sampling_effort', 'lifestage',
            'establishment_means', 'rights', 'note', 'kingdom', 'phylum',
            'class_name', 'order', 'suborder', 'family', 'subfamily', 'tribe',
            'subtribe', 'genus', 'subgenus', 'species', 'subspecies',
            'scientific_name_author', 'name_publishedin_year',
            'actual_dist_year', 'allow_kojin_shuzo', 'published_kojin_shuzo',
            'japanese_name', 'change_genus_brackets',
            'unknown_author_brackets',
            'unknown_name_publishedin_year_brackets', 'date_last_modified'
        ]
        property_fields = [
            ('collect_point_info__longitude', PropertyRangeFilter, ['range']),
            ('collect_point_info__latitude', PropertyRangeFilter, ['range']),
        ]
        filter_overrides = {
            models.CharField: {
                'filter_class': filters.CharFilter,
                'extra': lambda f: {
                    'lookup_expr': 'icontains',
                },
            },
            models.TextField: {
                'filter_class': filters.CharFilter,
                'extra': lambda f: {
                    'lookup_expr': 'icontains',
                },
            },
            models.IntegerField: {
                'filter_class': filters.RangeFilter,
            },
            models.FloatField: {
                'filter_class': filters.RangeFilter,
            },
            models.DateField: {
                'filter_class': filters.DateFromToRangeFilter,
            },
            models.DateTimeField: {
                'filter_class': filters.DateFromToRangeFilter,
            },
            models.BooleanField: {
                'filter_class': filters.BooleanFilter,
            }
        }
コード例 #9
0
class SpecimenNameFilter(PropertyFilterSet):
    name = PropertyCharFilter(field_name='name', lookup_expr='icontains')

    class Meta:
        model = Specimen
        fields = ['name']