示例#1
0
class ImageFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Image list filter label', 'Name'),
                      lookup_expr='icontains')
    category = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Gallery list filter label', 'Category'),
                                         name='category',
                                         queryset=Category.objects.all())
    sort_by = OrderingFilter(label=pgettext_lazy('Image list filter label',
                                                 'Sort by'),
                             fields=IMAGE_SORT_BY_FIELDS.keys(),
                             field_labels=IMAGE_SORT_BY_FIELDS)

    class Meta:
        model = ImageData
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard '
            'image list',
            'Found %(counter)d matching attribute',
            'Found %(counter)d matching attributes',
            number=counter) % {
                'counter': counter
            }
示例#2
0
class EndpointFilter(DojoFilter):
    product = ModelMultipleChoiceFilter(
        queryset=Product.objects.all().order_by('name'), label="Product")
    host = CharFilter(lookup_expr='icontains')
    path = CharFilter(lookup_expr='icontains')
    query = CharFilter(lookup_expr='icontains')
    fragment = CharFilter(lookup_expr='icontains')

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('product', 'product'),
            ('host', 'host'),
        ), )

    def __init__(self, *args, **kwargs):
        self.user = None
        if 'user' in kwargs:
            self.user = kwargs.pop('user')
        super(EndpointFilter, self).__init__(*args, **kwargs)
        if self.user and not self.user.is_staff:
            self.form.fields['product'].queryset = Product.objects.filter(
                authorized_users__in=[self.user]).distinct().order_by('name')

    class Meta:
        model = Endpoint
        exclude = []
示例#3
0
class CategoryFilter(SortedFilterSet):
    name = CharFilter(
        label=pgettext_lazy("Category list filter label", "Name"),
        lookup_expr="icontains",
    )
    sort_by = OrderingFilter(
        label=pgettext_lazy("Category list sorting filter label", "Sort by"),
        fields=SORT_BY_FIELDS.keys(),
        field_labels=SORT_BY_FIELDS,
    )

    class Meta:
        model = Category
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            "Number of matching records in the dashboard categories list",
            "Found %(counter)d matching category",
            "Found %(counter)d matching categories",
            number=counter,
        ) % {
            "counter": counter
        }
class ImageFilter(structure_filters.BaseServicePropertyFilter):

    o = OrderingFilter(fields=('distribution', 'type'))

    class Meta(object):
        model = models.Image
        fields = structure_filters.BaseServicePropertyFilter.Meta.fields + ('distribution', 'type')
示例#5
0
class ProductTypeFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Product type list filter label',
                                          'Name'),
                      lookup_expr='icontains')
    sort_by = OrderingFilter(label=pgettext_lazy(
        'Product type list filter label', 'Sort by'),
                             fields=PRODUCT_TYPE_SORT_BY_FIELDS.keys(),
                             field_labels=PRODUCT_TYPE_SORT_BY_FIELDS)
    product_attributes = ModelMultipleChoiceFilter(
        label=pgettext_lazy('Product type list filter label',
                            'Product attributes'),
        name='product_attributes',
        queryset=ProductAttribute.objects.all())
    variant_attributes = ModelMultipleChoiceFilter(
        label=pgettext_lazy('Product type list filter label',
                            'Variant attributes'),
        name='variant_attributes',
        queryset=ProductAttribute.objects.all())

    class Meta:
        model = ProductType
        fields = ['name', 'product_attributes', 'variant_attributes']

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard product types list',
            'Found %(counter)d matching product type',
            'Found %(counter)d matching product types',
            number=counter) % {
                'counter': counter
            }
示例#6
0
class BrandFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Brand list name filter label',
                                          'Name'),
                      lookup_expr='icontains')
    is_featured = ChoiceFilter(label=pgettext_lazy('Brand list filter label',
                                                   'Is featured'),
                               choices=BOOLEAN_CHOICES,
                               empty_label=pgettext_lazy(
                                   'Filter empty choice label', 'All'),
                               widget=forms.Select)
    sort_by = OrderingFilter(label=pgettext_lazy(
        'Brand list sorting filter label', 'Sort by'),
                             fields=SORT_BY_FIELDS.keys(),
                             field_labels=SORT_BY_FIELDS)

    class Meta:
        model = Brand
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard brands list',
            'Found %(counter)d matching brand',
            'Found %(counter)d matching brands',
            number=counter) % {
                'counter': counter
            }
示例#7
0
class CVEFilter(FilterSet):
    search = CharFilter(method='filter_search')

    def filter_search(self, queryset, name, value):
        return queryset.filter(
            Q(cve_id__icontains=value) | Q(summary__icontains=value))

    sorted_by = OrderingFilter(
        # tuple-mapping retains order
        choices=(
            ('cve_id', _('CVE-ID')),
            ('-cve_id', _('CVE-ID (desc)')),
            ('cvss', _('CVSSv2')),
            ('-cvss', _('CVSSv2 (desc)')),
            ('summary', _('Summary')),
            ('-summary', _('Summary (desc)')),
            ('modified', _('Modified')),
            ('-modified', _('Modified (desc)')),
            ('monitored', _('Monitored')),
            ('-monitored', _('Monitored (desc)')),
        ))

    class Meta:
        model = CVE
        fields = {
            'cve_id': ['icontains', 'exact'],
            'cvss': ['icontains'],
            'summary': ['icontains'],
            # 'search': ['icontains'],
        }
示例#8
0
class SlotFilter(django_filters.FilterSet):

    order_by = OrderingFilter(fields=[("date",
                                       "date"), ("start",
                                                 "start"), ("end", "end")])

    class Meta:
        model = Slot
        fields = {
            "uuid": ["exact"],
            "date": [
                "exact",
                "lt",
                "lte",
                "gt",
                "gte",
                "year",
                "year__lt",
                "year__lte",
                "year__gt",
                "year__gte",
                "month",
                "month__lt",
                "month__lte",
                "month__gt",
                "month__gte",
                "day",
                "day__lt",
                "day__lte",
                "day__gt",
                "day__gte",
            ],
            "start": [
                "exact",
                "lt",
                "lte",
                "gt",
                "gte",
                "hour",
                "hour__lt",
                "hour__lte",
                "hour__gt",
                "hour__gte",
            ],
            "end": [
                "exact",
                "lt",
                "lte",
                "gt",
                "gte",
                "hour",
                "hour__lt",
                "hour__lte",
                "hour__gt",
                "hour__gte",
            ],
            "available": [
                "exact",
            ],
        }
示例#9
0
class AppointmentFilter(django_filters.FilterSet):

    order_by = OrderingFilter(fields=(
        ("slot__date", "slot__date"),
        ("slot__start", "slot__start"),
        ("slot__end", "slot__end"),
    ))

    class Meta:
        model = Appointment
        fields = {
            "uuid": ["exact"],
            "status": ["iexact"],
            "slot__date": [
                "exact",
                "lt",
                "lte",
                "gt",
                "gte",
                "year",
                "year__lt",
                "year__lte",
                "year__gt",
                "year__gte",
                "month",
                "month__lt",
                "month__lte",
                "month__gt",
                "month__gte",
                "day",
                "day__lt",
                "day__lte",
                "day__gt",
                "day__gte",
            ],
            "slot__start": [
                "exact",
                "lt",
                "lte",
                "gt",
                "gte",
                "hour",
                "hour__lt",
                "hour__lte",
                "hour__gt",
                "hour__gte",
            ],
            "slot__end": [
                "exact",
                "lt",
                "lte",
                "gt",
                "gte",
                "hour",
                "hour__lt",
                "hour__lte",
                "hour__gt",
                "hour__gte",
            ],
        }
示例#10
0
class BookFilter(FilterSet):
    """Filter class for book filter view.
    """
    _order_fields = [
        'bookcase_slot__bookcase__name', 'bookcase_slot__bookshelf_number',
        'bookcase_slot__number', 'name', 'author__firstname'
    ]
    ordering = OrderingFilter(fields=tuple(
        (field_name, field_name) for field_name in _order_fields))

    bookcase_name = CharFilter(label=_('Bookcase name'),
                               field_name='bookcase_slot__bookcase__name',
                               lookup_expr='icontains')
    author_name = CharFilter(label=_('Author name'), method='author_filter')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.form.fields['bookcase_slot__bookshelf_number'].label = _(
            'Bookshelf')
        self.form.fields['bookcase_slot__bookshelf_number'].widget.attrs[
            'mine'] = 1
        self.form.fields['bookcase_slot__number'].label = _('Book slot')
        self.form.fields['bookcase_slot__number'].widget.attrs['min'] = 1

    class Meta:
        model = Book
        fields = [
            'bookcase_slot__bookshelf_number', 'bookcase_slot__number', 'name'
        ]
        form = StyledFilterForm

    def author_filter(self, queryset, name, value):
        return queryset.filter(
            Q(author__firstname__icontains=value)
            | Q(author__lastname__icontains=value))
示例#11
0
class DeliveryZoneFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Delivery zones list filter label',
                                          'Delivery zone name'),
                      lookup_expr="icontains")
    price = RangeFilter(label=pgettext_lazy('Delivery zones list filter label',
                                            'Price range'),
                        field_name='delivery_methods__price')
    country = ChoiceFilter(label=pgettext_lazy('Delivery zones filter label',
                                               'Country'),
                           field_name='countries',
                           lookup_expr='contains',
                           choices=COUNTRY_CODE_CHOICES)
    sort_by = OrderingFilter(label=pgettext_lazy(
        'Skill list sorting filter label', 'Sort by'),
                             fields=SORT_BY_FIELDS.keys(),
                             field_labels=SORT_BY_FIELDS)

    class Meta:
        model = DeliveryZone
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard '
            'delivery zones list',
            'Found %(counter)d matching delivery zone',
            'Found %(counter)d matching delivery zones',
            number=counter) % {
                'counter': counter
            }
示例#12
0
class SaleFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Sale list filter label', 'Name'),
                      lookup_expr='icontains')
    categories = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Sale list filter label', 'Categories'),
                                           name='categories',
                                           queryset=Category.objects.all())
    type = ChoiceFilter(label=pgettext_lazy('Sale list filter label',
                                            'Discount type'),
                        choices=DISCOUNT_TYPE_CHOICES,
                        empty_label=pgettext_lazy('Filter empty choice label',
                                                  'All'),
                        widget=forms.Select)
    value = RangeFilter(label=pgettext_lazy('Sale list filter label', 'Value'))
    sort_by = OrderingFilter(label=pgettext_lazy('Sale list filter label',
                                                 'Sort by'),
                             fields=SORT_BY_FIELDS_SALE.keys(),
                             field_labels=SORT_BY_FIELDS_SALE)

    class Meta:
        model = Sale
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard sales list',
            'Found %(counter)d matching sale',
            'Found %(counter)d matching sales',
            number=counter) % {
                'counter': counter
            }
示例#13
0
class MenuItemFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Menu item list filter label',
                                          'Name'),
                      lookup_expr='icontains')
    link = CharFilter(label=pgettext_lazy('Menu item list filter label',
                                          'Points to'),
                      method='filter_by_link')
    sort_by = OrderingFilter(label=pgettext_lazy(
        'Menu item list sorting filter label', 'Sort by'),
                             fields=MENU_ITEM_SORT_BY_FIELDS.keys(),
                             field_labels=MENU_ITEM_SORT_BY_FIELDS)

    class Meta:
        model = MenuItem
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard menu items list',
            'Found %(counter)d matching menu item',
            'Found %(counter)d matching menu items',
            number=counter) % {
                'counter': counter
            }

    def filter_by_link(self, queryset, name, value):
        return queryset.filter(
            Q(collection__name__icontains=value)
            | Q(category__name__icontains=value)
            | Q(page__title__icontains=value) | Q(url__icontains=value))
示例#14
0
class ProductFilterSet(DistinctFilterSet):
    sort_by = OrderingFilter(
        fields=SORT_BY_FIELDS.keys(), field_labels=SORT_BY_FIELDS)

    class Meta:
        model = Product
        fields = {
            'category': ['exact'],
            'price': ['exact', 'range', 'lte', 'gte'],
            'attributes': ['exact'],
            'name': ['exact', 'icontains'],
            'product_type__name': ['exact'],
            'is_published': ['exact'],
            'is_featured': ['exact']}

    @classmethod
    def filter_for_field(cls, f, field_name, lookup_expr='exact'):
        if field_name == 'attributes':
            return ProductAttributeFilter(
                field_name=field_name, lookup_expr=lookup_expr, distinct=True)
        # this class method is called during class construction so we can't
        # reference ProductFilterSet here yet
        # pylint: disable=E1003
        return super(DistinctFilterSet, cls).filter_for_field(
            f, field_name, lookup_expr)
示例#15
0
class ProductFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Product list filter label', 'Name'),
                      lookup_expr='icontains')
    categories = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Product list filter label', 'Categories'),
                                           name='categories',
                                           queryset=Category.objects.all())
    price = RangeFilter(label=pgettext_lazy('Product list filter label',
                                            'Price'),
                        name='price',
                        widget=PriceRangeWidget)
    is_published = ChoiceFilter(
        label=pgettext_lazy('Product list filter label', 'Is published'),
        choices=PUBLISHED_CHOICES,
        empty_label=pgettext_lazy('Filter empty choice label', 'All'),
        widget=forms.Select)
    is_featured = ChoiceFilter(
        label=pgettext_lazy('Product list is featured filter label',
                            'Is featured'),
        choices=FEATURED_CHOICES,
        empty_label=pgettext_lazy('Filter empty choice label', 'All'),
        widget=forms.Select)
    sort_by = OrderingFilter(label=pgettext_lazy('Product list filter label',
                                                 'Sort by'),
                             fields=PRODUCT_SORT_BY_FIELDS.keys(),
                             field_labels=PRODUCT_SORT_BY_FIELDS)

    class Meta:
        model = Product
        fields = []
示例#16
0
class TaxFilter(SortedFilterSet):
    country_code = ChoiceFilter(label=pgettext_lazy('Taxes list filter label',
                                                    'Country name'),
                                empty_label=pgettext_lazy(
                                    'Filter empty choice label', 'All'),
                                widget=forms.Select)
    sort_by = OrderingFilter(label=pgettext_lazy('Taxes list sorting form',
                                                 'Sort by'),
                             fields=SORT_BY_FIELDS.keys(),
                             field_labels=SORT_BY_FIELDS)

    class Meta:
        model = VAT
        fields = []

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.filters['country_code'].extra.update(
            {'choices': get_country_choices_for_vat()})

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard taxes list',
            'Found %(counter)d matching country',
            'Found %(counter)d matching countries',
            number=counter) % {
                'counter': counter
            }
示例#17
0
class NetworkCredentialFilter(FilterSet):
    class Meta:
        model = NetworkCredential
        fields = '__all__'
        # exclude = ('password',)

    filter_fields = {
        'user': [
            'exact',
        ],
        'social_network': ['exact', 'icontains', 'istartswith'],
        'username': ['exact', 'icontains', 'istartswith'],
        'email': ['exact', 'icontains', 'istartswith'],
        'link': ['exact', 'icontains', 'istartswith'],
        'dateCreated': ['exact', 'icontains', 'istartswith'],
    }

    order_by = OrderingFilter(fields=(
        # field and de argument
        ('id', 'id'),
        ('username', 'username'),
        ('social_network', 'social_network'),
        ('email', 'email'),
        ('dateCreated', 'dateCreated'),
    ))
示例#18
0
class ProductTypeFilter(SortedFilterSet):
    name = CharFilter(
        label=pgettext_lazy("Product type list filter label", "Name"),
        lookup_expr="icontains",
    )
    sort_by = OrderingFilter(
        label=pgettext_lazy("Product type list filter label", "Sort by"),
        fields=PRODUCT_TYPE_SORT_BY_FIELDS.keys(),
        field_labels=PRODUCT_TYPE_SORT_BY_FIELDS,
    )
    product_attributes = ModelMultipleChoiceFilter(
        label=pgettext_lazy("Product type list filter label", "Product attributes"),
        field_name="product_attributes",
        queryset=Attribute.objects.all(),
    )
    variant_attributes = ModelMultipleChoiceFilter(
        label=pgettext_lazy("Product type list filter label", "Variant attributes"),
        field_name="variant_attributes",
        queryset=Attribute.objects.all(),
    )

    class Meta:
        model = ProductType
        fields = ["name", "product_attributes", "variant_attributes"]

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            "Number of matching records in the dashboard product types list",
            "Found %(counter)d matching product type",
            "Found %(counter)d matching product types",
            number=counter,
        ) % {"counter": counter}
示例#19
0
class ProductDetailFilter(FilterSet):
    search = CharFilter(method='filter_search')
    monitored = BooleanFilter(method='filter_monitored')

    def filter_search(self, queryset, name, value):
        return queryset.filter(
            Q(vendor__name__icontains=value) | Q(name__icontains=value))

    def filter_monitored(self, queryset, name, value):
        return queryset.filter(monitored=value)

    sorted_by = OrderingFilter(
        # tuple-mapping retains order
        choices=(
            ('vendor__name', _('Vendor')),
            ('-vendor__name', _('Vendor (Desc)')),
            ('name', _('Product Name')),
            ('-name', _('Product Name (Desc)')),
            ('monitored', _('Monitored')),
            ('-monitored', _('Monitored (desc)')),
        ))

    class Meta:
        model = Product
        fields = {
            'name': ['icontains'],
            'vendor__name': ['icontains'],
            # 'monitored': ['exact'],
        }
示例#20
0
class CollectionFilter(SortedFilterSet):
    name = CharFilter(
        label=pgettext_lazy("Collection list name filter label", "Name"),
        lookup_expr="icontains",
    )
    is_published = ChoiceFilter(
        label=pgettext_lazy("Collection list filter label", "Is published"),
        choices=PUBLISHED_CHOICES,
        empty_label=pgettext_lazy("Filter empty choice label", "All"),
        widget=forms.Select,
    )
    sort_by = OrderingFilter(
        label=pgettext_lazy("Collection list sorting filter label", "Sort by"),
        fields=SORT_BY_FIELDS.keys(),
        field_labels=SORT_BY_FIELDS,
    )

    class Meta:
        model = Collection
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            "Number of matching records in the dashboard collections list",
            "Found %(counter)d matching collection",
            "Found %(counter)d matching collections",
            number=counter,
        ) % {
            "counter": counter
        }
示例#21
0
class PackageFilter(FilterSet):
    type = CharFilter(method='filter_type')
    monitored = BooleanFilter(method='filter_monitored')

    def filter_type(self, queryset, name, value):
        return queryset.filter(type__name=value)

    def filter_monitored(self, queryset, name, value):
        return queryset.filter(monitored=value)

    sorted_by = OrderingFilter(choices=(
        ('name', _('Package Name')),
        ('-name', _('Package Name (Desc)')),
        ('type', _('Package Type')),
        ('-type', _('Package Type (Desc)')),
        ('monitored', _('Monitored')),
        ('-monitored', _('Monitored (desc)')),
    ))

    class Meta:
        model = Package
        fields = {
            'name': ['icontains', 'exact'],
            # 'monitored': ['exact'],
        }
示例#22
0
class TransactionFilter(FilterSet):
    amount_top = IntegerFilter(method='filter_amount_top')
    amount_bottom = IntegerFilter(method='filter_amount_bottom')

    def filter_amount_top(self, queryset, name, value):
        return queryset.filter(
            category__is_internal=False).order_by('-amount')[:int(value)]

    def filter_amount_bottom(self, queryset, name, value):
        return queryset.filter(
            category__is_internal=False).order_by('amount')[:int(value)]

    class Meta:
        model = Transaction
        fields = {
            'description': ['icontains'],
            'amount': ['gte', 'lte'],
            'category__name': ['exact'],
            'category__subcategory': ['exact'],
            'date': ['gte', 'lte']
        }

    order_by = OrderingFilter(fields=(
        ('amount', 'amount'),
        ('date', 'date'),
        ('description', 'description'),
    ))
示例#23
0
class ProductFilter(SortedFilterSet):
    sort_by = OrderingFilter(label=pgettext_lazy('Product list sorting form',
                                                 'Sort by'),
                             fields=SORT_BY_FIELDS.keys(),
                             field_labels=SORT_BY_FIELDS)

    class Meta:
        model = Product
        fields = ['price']
        filter_overrides = {PriceField: {'filter_class': RangeFilter}}

    def __init__(self, *args, **kwargs):
        self.category = kwargs.pop('category')
        super().__init__(*args, **kwargs)
        self.product_attributes, self.variant_attributes = (
            self._get_attributes())
        self.filters.update(self._get_product_attributes_filters())
        self.filters.update(self._get_product_variants_attributes_filters())
        self.filters = OrderedDict(sorted(self.filters.items()))
        self.form.fields['sort_by'].validators.append(self.validate_sort_by)

    def _get_attributes(self):
        product_attributes = (
            ProductAttribute.objects.all().prefetch_related('values').filter(
                product_types__products__category=self.category).distinct())
        variant_attributes = (
            ProductAttribute.objects.all().prefetch_related('values').filter(
                product_variant_types__products__category=self.category).
            distinct())
        return product_attributes, variant_attributes

    def _get_product_attributes_filters(self):
        filters = {}
        for attribute in self.product_attributes:
            filters[attribute.slug] = MultipleChoiceFilter(
                name='attributes__%s' % attribute.pk,
                label=attribute.name,
                widget=CheckboxSelectMultiple,
                choices=self._get_attribute_choices(attribute))
        return filters

    def _get_product_variants_attributes_filters(self):
        filters = {}
        for attribute in self.variant_attributes:
            filters[attribute.slug] = MultipleChoiceFilter(
                name='variants__attributes__%s' % attribute.pk,
                label=attribute.name,
                widget=CheckboxSelectMultiple,
                choices=self._get_attribute_choices(attribute))
        return filters

    def _get_attribute_choices(self, attribute):
        return [(choice.pk, choice.name) for choice in attribute.values.all()]

    def validate_sort_by(self, value):
        if value.strip('-') not in SORT_BY_FIELDS:
            raise ValidationError(pgettext_lazy(
                'Validation error for sort_by filter',
                '%(value)s is not a valid sorting option'),
                                  params={'value': value})
示例#24
0
class VendorFilter(FilterSet):

    order_by = OrderingFilter(fields=[('name', 'name')])

    class Meta:
        fields = {'name': ['icontains']}
        model = Vendor
示例#25
0
class ProductFilter(DojoFilter):
    name = CharFilter(lookup_expr='icontains', label="Product Name")
    prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all().order_by('name'),
        label="Product Type")

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('name', 'name'),
            ('prod_type__name', 'prod_type__name'),
        ),
        field_labels={
            'name': 'Product Name',
            'prod_type__name': 'Product Type',
        })

    # tags = CharFilter(lookup_expr='icontains', label="Tags")

    def __init__(self, *args, **kwargs):
        self.user = None
        if 'user' in kwargs:
            self.user = kwargs.pop('user')

        super(ProductFilter, self).__init__(*args, **kwargs)

        if self.user is not None and not self.user.is_staff:
            self.form.fields[
                'prod_type'].queryset = Product_Type.objects.filter(
                    prod_type__authorized_users__in=[self.user])

    class Meta:
        model = Product
        fields = ['name', 'prod_type']
        exclude = ['tags']
示例#26
0
class TaxFilter(SortedFilterSet):
    country_code = ChoiceFilter(
        label=pgettext_lazy("Taxes list filter label", "Country name"),
        empty_label=pgettext_lazy("Filter empty choice label", "All"),
        widget=forms.Select,
    )
    sort_by = OrderingFilter(
        label=pgettext_lazy("Taxes list sorting form", "Sort by"),
        fields=SORT_BY_FIELDS.keys(),
        field_labels=SORT_BY_FIELDS,
    )

    class Meta:
        model = VAT
        fields = []

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.filters["country_code"].extra.update(
            {"choices": get_country_choices_for_vat()})

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            "Number of matching records in the dashboard taxes list",
            "Found %(counter)d matching country",
            "Found %(counter)d matching countries",
            number=counter,
        ) % {
            "counter": counter
        }
示例#27
0
class EngineerFilter(DojoFilter):
    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('username', 'username'),
            ('last_name', 'last_name'),
            ('first_name', 'first_name'),
            ('email', 'email'),
            ('is_active', 'is_active'),
            ('is_staff', 'is_staff'),
            ('is_superuser', 'is_superuser'),
        ),
        field_labels={
            'username': '******',
            'is_active': 'Active',
            'is_staff': 'Staff',
            'is_superuser': '******',
        })

    class Meta:
        model = Dojo_User
        fields = [
            'is_staff', 'is_superuser', 'is_active', 'username', 'email',
            'last_name', 'first_name'
        ]
        exclude = [
            'password', 'last_login', 'groups', 'user_permissions',
            'date_joined'
        ]
示例#28
0
class EngagementFilter(DojoFilter):
    engagement__lead = ModelChoiceFilter(
        queryset=User.objects.filter(
            engagement__lead__isnull=False).distinct(),
        label="Lead")
    name = CharFilter(lookup_expr='icontains')
    prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all().order_by('name'),
        label="Product Type")

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('name', 'name'),
            ('prod_type__name', 'prod_type__name'),
        ),
        field_labels={
            'name': 'Product Name',
            'prod_type__name': 'Product Type',
        }

    )

    class Meta:
        model = Product
        fields = ['name', 'prod_type']
示例#29
0
class SuperCollectionFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy(
        'SuperCollection list name filter label', 'Name'),
                      lookup_expr='icontains')
    is_published = ChoiceFilter(
        label=pgettext_lazy('SuperCollection list filter label',
                            'Is published'),
        choices=PUBLISHED_CHOICES,
        empty_label=pgettext_lazy('Filter empty choice label', 'All'),
        widget=forms.Select)
    sort_by = OrderingFilter(label=pgettext_lazy(
        'SuperCollection list sorting filter label', 'Sort by'),
                             fields=SORT_BY_FIELDS.keys(),
                             field_labels=SORT_BY_FIELDS)

    class Meta:
        model = SuperCollection
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard super collections list',
            'Found %(counter)d matching super collection',
            'Found %(counter)d matching super collections',
            number=counter) % {
                'counter': counter
            }
示例#30
0
class OrderFilter(SortedFilterSet):
    id = NumberFilter(
        label=pgettext_lazy('Order list filter label', 'ID'))
    name_or_email = CharFilter(
        label=pgettext_lazy(
            'Order list filter label', 'Email'),
        method='filter_by_order_customer')
    created = DateFromToRangeFilter(
        label=pgettext_lazy('Order list filter label', 'Placed on'),
        name='created', widget=DateRangeWidget)
    status = ChoiceFilter(
        label=pgettext_lazy(
            'Order list filter label', 'Order status'),
        choices=OrderStatus.CHOICES,
        empty_label=pgettext_lazy('Filter empty choice label', 'All'),
        widget=forms.Select)
    sort_by = OrderingFilter(
        label=pgettext_lazy('Order list filter label', 'Sort by'),
        fields=SORT_BY_FIELDS,
        field_labels=SORT_BY_FIELDS_LABELS)

    class Meta:
        model = Order
        fields = []

    def filter_by_order_customer(self, queryset, name, value):
        return queryset.filter(
            Q(user__email__icontains=value))