Ejemplo n.º 1
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
            }
Ejemplo n.º 2
0
class MonitoringResultTableFilter(FilterSet):
    q = CharFilter(
        method='search',
        label='Search',
    )
    metadata = ModelMultipleChoiceFilter(
        queryset=Metadata.objects.filter(
            metadata_type=MetadataEnum.SERVICE.value),
        widget=autocomplete.ModelSelect2Multiple(
            url='resource:autocomplete_metadata_service'))
    monitoring_run = ModelMultipleChoiceFilter(
        queryset=MonitoringRun.objects.all(),
        widget=autocomplete.ModelSelect2Multiple(
            url='monitoring:autocomplete_monitoring_run'))
    monitoring_result = ModelMultipleChoiceFilter(
        label=_('Monitoring result'),
        queryset=MonitoringResult.objects.all(),
        widget=autocomplete.ModelSelect2Multiple(
            url='monitoring:autocomplete_monitoring_result'))

    class Meta:
        model = MonitoringResult
        fields = ['q', 'available']

    def search(self, queryset, name, value):
        if not value.strip():
            return queryset
        qs_filter = (Q(error_msg__icontains=value)
                     | Q(monitored_uri__icontains=value))
        return queryset.filter(qs_filter)
Ejemplo n.º 3
0
class ReportAuthedFindingFilter(DojoFilter):
    title = CharFilter(lookup_type='icontains', label='Name')
    test__engagement__product = ModelMultipleChoiceFilter(
        queryset=Product.objects.all(), label="Product")
    test__engagement__product__prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all(), label="Product Type")
    severity = MultipleChoiceFilter(choices=SEVERITY_CHOICES)
    active = ReportBooleanFilter()
    mitigated = MitigatedDateRangeFilter()
    verified = ReportBooleanFilter()
    false_p = ReportBooleanFilter(label="False Positive")
    test__engagement__risk_acceptance = ReportRiskAcceptanceFilter(
        label="Risk Accepted")
    duplicate = ReportBooleanFilter()
    out_of_scope = ReportBooleanFilter()

    def __init__(self, *args, **kwargs):
        self.user = None
        if 'user' in kwargs:
            self.user = kwargs.pop('user')
        super(ReportAuthedFindingFilter, self).__init__(*args, **kwargs)
        if not self.user.is_staff:
            self.form.fields[
                'test__engagement__product'].queryset = Product.objects.filter(
                    authorized_users__in=[self.user])

    class Meta:
        model = Finding
        exclude = [
            'date', 'cwe', 'url', 'description', 'mitigation', 'impact',
            'endpoint', 'references', 'test', 'is_template', 'thread_id',
            'notes', 'endpoints', 'numerical_severity', 'reporter',
            'last_reviewed'
        ]
Ejemplo n.º 4
0
class ChallengeFilter(TitleDescriptionModalityStructureFilter):
    task_types = ModelMultipleChoiceFilter(
        queryset=TaskType.objects.all(),
        widget=Select2MultipleWidget,
        label="Task Type",
    )
    series = ModelMultipleChoiceFilter(
        queryset=ChallengeSeries.objects.all(),
        widget=Select2MultipleWidget,
        label="Challenge Series",
    )

    class Meta(TitleDescriptionModalityStructureFilter.Meta):
        model = Challenge
        fields = (
            *TitleDescriptionModalityStructureFilter.Meta.fields,
            "series",
            "task_types",
            "educational",
        )
        search_fields = (
            *TitleDescriptionModalityStructureFilter.Meta.search_fields,
            "short_name",
            "event_name",
        )
Ejemplo n.º 5
0
class ReportFilter(FilterSet):
    center_point = MethodFilter(action='center_point')
    status_choices = (
        ('', '---------'),
        ('fixed', 'Fixed'),
        ('not-fixed', 'Not fixed'),
        ('in-progress', 'In progress'),
    )
    status = ChoiceFilter(choices=status_choices)
    from_date = DateTimeFilter(name='created_at', lookup_type='gte')
    to_date = DateTimeFilter(name='created_at', lookup_type='lte')
    from_date_unix = UnixTimeFilter(name='created_at', lookup_type='gte')
    to_date_unix = UnixTimeFilter(name='created_at', lookup_type='lte')
    order_by_field = 'order_by'
    city = ModelMultipleChoiceFilter(name='ward__city',
                                     queryset=City.objects.all(),
                                     widget=forms.CheckboxSelectMultiple())
    ward = ModelMultipleChoiceFilter(queryset=Ward.objects.all(),
                                     widget=forms.CheckboxSelectMultiple())

    class Meta:
        model = Report
        fields = [
            'ward', 'city', 'category', 'from_date', 'to_date',
            'from_date_unix', 'to_date_unix'
        ]
        order_by = (('-created_at', _('Latest First')), ('created_at',
                                                         _('Oldest First')))
Ejemplo n.º 6
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 tradingroom product types list",
            "Found %(counter)d matching product type",
            "Found %(counter)d matching product types",
            number=counter,
        ) % {"counter": counter}
Ejemplo n.º 7
0
class AcceptedFindingFilter(DojoFilter):
    title = CharFilter(lookup_expr='icontains')
    sourcefile = CharFilter(lookup_expr='icontains')
    sourcefilepath = CharFilter(lookup_expr='icontains')
    param = CharFilter(lookup_expr='icontains')
    payload = CharFilter(lookup_expr='icontains')
    test__engagement__risk_acceptance__created = \
        DateRangeFilter(label="Acceptance Date")
    date = DateRangeFilter(label="Finding Date")
    cwe = MultipleChoiceFilter(choices=[])
    severity = MultipleChoiceFilter(choices=[])
    test__test_type = ModelMultipleChoiceFilter(
        queryset=Test_Type.objects.all())
    test__engagement__product = ModelMultipleChoiceFilter(
        queryset=Product.objects.all(), label="Product")
    test__engagement__product__prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all(), label="Product Type")

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('numerical_severity', 'numerical_severity'),
            ('date', 'date'),
            ('test__engagement__risk_acceptance__created',
             'test__engagement__risk_acceptance__created'),
            ('title', 'title'),
            ('test__engagement__product__name',
             'test__engagement__product__name'),
        ),
        field_labels={
            'numerical_severity': 'Severity',
            'date': 'Finding Date',
            'test__engagement__risk_acceptance__created': 'Acceptance Date',
            'title': 'Finding Name',
            'test__engagement__product__name': 'Product Name',
        })

    class Meta:
        model = Finding
        fields = ['title', 'test__engagement__risk_acceptance__created']
        exclude = [
            'url', 'description', 'mitigation', 'impact', 'endpoint',
            'references', 'test', 'is_template', 'active', 'verified',
            'out_of_scope', 'false_p', 'duplicate', 'thread_id', 'mitigated',
            'notes', 'numerical_severity', 'reporter', 'endpoints',
            'last_reviewed', 'o', 'jira_creation', 'jira_change'
        ]

    def __init__(self, *args, **kwargs):
        super(AcceptedFindingFilter, self).__init__(*args, **kwargs)
        cwe = dict()
        cwe = dict([finding.cwe, finding.cwe]
                   for finding in self.queryset.distinct()
                   if type(finding.cwe) is int and finding.cwe is not None
                   and finding.cwe > 0 and finding.cwe not in cwe)
        cwe = collections.OrderedDict(sorted(cwe.items()))
        self.form.fields['cwe'].choices = list(cwe.items())
        self.form.fields['severity'].choices = self.queryset.order_by(
            'numerical_severity').values_list('severity',
                                              'severity').distinct()
Ejemplo n.º 8
0
class BlogFilter(FilterSet):
    search = CharFilter(method="search_filter", label="Title or Content")
    tags = ModelMultipleChoiceFilter(queryset=Tag.objects.all(),
                                     widget=Select2MultipleWidget,
                                     label="Tags")
    authors = ModelMultipleChoiceFilter(
        queryset=get_user_model().objects.filter(
            blog_authors__isnull=False,
            blog_authors__published=True).distinct().order_by("username"),
        widget=Select2MultipleWidget,
        label="Authors",
    )

    class Meta:
        model = Post
        form = FilterForm
        fields = ("search", "authors", "tags")
        search_fields = ("title", "content")

    def search_filter(self, queryset, name, value):
        return queryset.filter(
            reduce(
                or_,
                [
                    Q(**{f"{f}__icontains": value})
                    for f in self.Meta.search_fields
                ],
                Q(),
            ))
Ejemplo n.º 9
0
class OpenFindingFilter(DojoFilter):
    title = CharFilter(lookup_expr='icontains')
    duplicate = ReportBooleanFilter()
    sourcefile = CharFilter(lookup_expr='icontains')
    sourcefilepath = CharFilter(lookup_expr='icontains')
    param = CharFilter(lookup_expr='icontains')
    payload = CharFilter(lookup_expr='icontains')
    date = DateRangeFilter()
    last_reviewed = DateRangeFilter()
    cwe = MultipleChoiceFilter(choices=[])
    severity = MultipleChoiceFilter(choices=[])
    test__test_type = ModelMultipleChoiceFilter(
        queryset=Test_Type.objects.all())
    test__engagement__product = ModelMultipleChoiceFilter(
        queryset=Product.objects.all(), label="Product")

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('numerical_severity', 'numerical_severity'),
            ('date', 'date'),
            ('last_reviewed', 'last_reviewed'),
            ('title', 'title'),
            ('test__engagement__product__name',
             'test__engagement__product__name'),
        ), )

    class Meta:
        model = Finding
        exclude = [
            'url', 'description', 'mitigation', 'impact', 'endpoint',
            'references', 'test', 'is_template', 'active', 'verified',
            'out_of_scope', 'false_p', 'thread_id', 'mitigated', 'notes',
            'numerical_severity', 'reporter', 'last_reviewed'
        ]

    def __init__(self, *args, **kwargs):
        self.user = None
        if 'user' in kwargs:
            self.user = kwargs.pop('user')
        super(OpenFindingFilter, self).__init__(*args, **kwargs)
        cwe = dict()
        cwe = dict([finding.cwe, finding.cwe]
                   for finding in self.queryset.distinct()
                   if finding.cwe > 0 and finding.cwe not in cwe)
        cwe = collections.OrderedDict(sorted(cwe.items()))
        self.form.fields['cwe'].choices = cwe.items()
        sevs = dict()
        sevs = dict([finding.severity, finding.severity]
                    for finding in self.queryset.distinct()
                    if finding.severity not in sevs)
        self.form.fields['severity'].choices = sevs.items()
        if self.user is not None and not self.user.is_staff:
            self.form.fields[
                'test__engagement__product'].queryset = Product.objects.filter(
                    authorized_users__in=[self.user])
            self.form.fields['endpoints'].queryset = Endpoint.objects.filter(
                product__authorized_users__in=[self.user]).distinct()
Ejemplo n.º 10
0
class ImageFilterSet(FilterSet):
    archive = ModelMultipleChoiceFilter(
        queryset=Archive.objects.all(),
        widget=Select2MultipleWidget,
        label="Archive",
        help_text="Filter images that belong to an archive",
        field_name="componentinterfacevalue__archive_items__archive__pk",
        to_field_name="pk",
    )
    job_input = ModelMultipleChoiceFilter(
        queryset=Job.objects.all(),
        widget=Select2MultipleWidget,
        label="Job Input",
        help_text="Filter images that are used as input to an algorithm job",
        field_name="componentinterfacevalue__algorithm_jobs_as_input__pk",
        to_field_name="pk",
    )
    job_output = ModelMultipleChoiceFilter(
        queryset=Job.objects.all(),
        widget=Select2MultipleWidget,
        label="Job Output",
        help_text=
        "Filter images that are produced as output from an algorithm job",
        field_name="componentinterfacevalue__algorithm_jobs_as_output__pk",
        to_field_name="pk",
    )
    reader_study = ModelMultipleChoiceFilter(
        queryset=ReaderStudy.objects.all(),
        widget=Select2MultipleWidget,
        label="Reader Study",
        help_text="Filter images that belong to a reader study",
        field_name="readerstudies__pk",
        to_field_name="pk",
    )
    patient_id__isempty = EmptyStringFilter(field_name="patient_id")
    study_description__isempty = EmptyStringFilter(
        field_name="study_description")

    class Meta:
        model = Image
        fields = (
            "origin",
            "job_input",
            "job_output",
            "archive",
            "reader_study",
            "name",
            "patient_id",
            "patient_name",
            "patient_birth_date",
            "patient_age",
            "patient_sex",
            "study_date",
            "study_instance_uid",
            "series_instance_uid",
            "study_description",
            "series_description",
        )
Ejemplo n.º 11
0
class ChallengeFilter(FilterSet):
    search = CharFilter(method="search_filter", label="Title or Description")
    modalities = ModelMultipleChoiceFilter(
        queryset=ImagingModality.objects.all(),
        widget=Select2MultipleWidget,
        label="Modality",
    )
    task_types = ModelMultipleChoiceFilter(
        queryset=TaskType.objects.all(),
        widget=Select2MultipleWidget,
        label="Task Type",
    )
    structures = ModelMultipleChoiceFilter(
        queryset=BodyStructure.objects.select_related("region").all(),
        widget=Select2MultipleWidget,
        label="Anatomical Structure",
    )
    structures__region = ModelMultipleChoiceFilter(
        queryset=BodyRegion.objects.all(),
        widget=Select2MultipleWidget,
        label="Anatomical Region",
    )
    series = ModelMultipleChoiceFilter(
        queryset=ChallengeSeries.objects.all(),
        widget=Select2MultipleWidget,
        label="Challenge Series",
    )

    class Meta:
        model = Challenge
        fields = (
            "search",
            "series",
            "task_types",
            "modalities",
            "structures",
            "structures__region",
            "educational",
        )
        form = ChallengeFilterForm

    def search_filter(self, queryset, name, value):
        search_fields = [
            "title",
            "short_name",
            "description",
            "event_name",
        ]
        return queryset.filter(
            reduce(
                or_,
                [Q(**{f"{f}__icontains": value}) for f in search_fields],
                Q(),
            )
        )
Ejemplo n.º 12
0
class ClosedFindingFilter(DojoFilter):
    title = CharFilter(lookup_expr='icontains')
    mitigated = DateRangeFilter(label="Mitigated Date")
    cwe = MultipleChoiceFilter(choices=[])
    severity = MultipleChoiceFilter(choices=[])
    test__test_type = ModelMultipleChoiceFilter(
        queryset=Test_Type.objects.all())
    test__engagement__product = ModelMultipleChoiceFilter(
        queryset=Product.objects.all(), label="Product")
    test__engagement__product__prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all(), label="Product Type")

    o = OrderingFilter(
        # tuple-mapping retains order
        fields=(
            ('numerical_severity', 'numerical_severity'),
            ('date', 'date'),
            ('mitigated', 'mitigated'),
            ('title', 'title'),
            ('test__engagement__product__name',
             'test__engagement__product__name'),
        ),
        field_labels={
            'numerical_severity': 'Severity',
            'date': 'Date',
            'mitigated': 'Mitigated Date',
            'title': 'Finding Name',
            'test__engagement__product__name': 'Product Name',
        })

    class Meta:
        model = Finding
        exclude = [
            'url', 'description', 'mitigation', 'impact', 'endpoint',
            'references', 'test', 'is_template', 'active', 'verified',
            'out_of_scope', 'false_p', 'duplicate', 'thread_id', 'date',
            'notes', 'numerical_severity', 'reporter', 'endpoints',
            'last_reviewed'
        ]

    def __init__(self, *args, **kwargs):
        super(ClosedFindingFilter, self).__init__(*args, **kwargs)
        cwe = dict()
        cwe = dict([finding.cwe, finding.cwe]
                   for finding in self.queryset.distinct()
                   if finding.cwe > 0 and finding.cwe not in cwe)
        cwe = collections.OrderedDict(sorted(cwe.items()))
        self.form.fields['cwe'].choices = cwe.items()
        sevs = dict()
        sevs = dict([finding.severity, finding.severity]
                    for finding in self.queryset.distinct()
                    if finding.severity not in sevs)
        self.form.fields['severity'].choices = sevs.items()
Ejemplo n.º 13
0
class ProductFilter(FilterSet):
    price = RangeFilter()
    brand = ModelMultipleChoiceFilter(queryset=brands,
                                      widget=forms.CheckboxSelectMultiple)
    category = ModelMultipleChoiceFilter(queryset=categories,
                                         widget=forms.CheckboxSelectMultiple)

    class Meta:
        model = Product
        fields = [
            'brand',
            'price',
        ]
Ejemplo n.º 14
0
class AcceptedFindingFilter(DojoFilter):
    title = CharFilter(lookup_type='icontains')
    test__engagement__risk_acceptance__created = \
        DateRangeFilter(label="Acceptance Date")
    date = DateRangeFilter(label="Finding Date")
    cwe = MultipleChoiceFilter(choices=[])
    severity = MultipleChoiceFilter(choices=[])
    test__test_type = ModelMultipleChoiceFilter(
        queryset=Test_Type.objects.all())
    test__engagement__product = ModelMultipleChoiceFilter(
        queryset=Product.objects.all(), label="Product")
    test__engagement__product__prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all(), label="Product Type")

    class Meta:
        model = Finding
        order_by = (('numerical_severity', 'Severity'), ('-numerical_severity',
                                                         'Severity Desc'),
                    ('date', 'Finding Date Asc'), ('-date',
                                                   'Finding Date Desc'),
                    ('test__engagement__risk_acceptance__created',
                     'Acceptance Date Asc'),
                    ('-test__engagement__risk_acceptance__created',
                     'Acceptance Date Desc'), ('title', 'Finding Name'),
                    ('-title', 'Finding Name Desc'),
                    ('test__engagement__product__name',
                     'Product Name'), ('-test__engagement__product__name',
                                       'Product Name Dec'))
        fields = ['title', 'test__engagement__risk_acceptance__created']
        exclude = [
            'url', 'description', 'mitigation', 'impact', 'endpoint',
            'references', 'test', 'is_template', 'active', 'verified',
            'out_of_scope', 'false_p', 'duplicate', 'thread_id', 'mitigated',
            'notes', 'numerical_severity', 'reporter', 'endpoints',
            'last_reviewed', 'o'
        ]

    def __init__(self, *args, **kwargs):
        super(AcceptedFindingFilter, self).__init__(*args, **kwargs)
        cwe = dict()
        cwe = dict([finding.cwe, finding.cwe]
                   for finding in self.queryset.distinct()
                   if finding.cwe > 0 and finding.cwe not in cwe)
        cwe = collections.OrderedDict(sorted(cwe.items()))
        self.form.fields['cwe'].choices = cwe.items()
        sevs = dict()
        sevs = dict([finding.severity, finding.severity]
                    for finding in self.queryset.distinct()
                    if finding.severity not in sevs)
        self.form.fields['severity'].choices = sevs.items()
Ejemplo n.º 15
0
class ProductFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Product list filter label', 'Name'),
                      lookup_expr='icontains')
    category = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Product list filter label', 'Category'),
                                         name='category',
                                         queryset=Category.objects.all())
    brand_id = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Product list filter label', 'Brand'),
                                         name='brand_id',
                                         queryset=Brand.objects.all()),
    product_type = ModelMultipleChoiceFilter(
        label=pgettext_lazy('Product list filter label', 'Product type'),
        name='product_type',
        queryset=ProductType.objects.all())
    price = RangeFilter(label=pgettext_lazy('Product list filter label',
                                            'Price'),
                        name='price',
                        widget=MoneyRangeWidget)
    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 = ['brand_id', 'location_id']

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard products list',
            'Found %(counter)d matching product',
            'Found %(counter)d matching products',
            number=counter) % {
                'counter': counter
            }
Ejemplo n.º 16
0
class ReportFilter(DojoFilter):
    name = CharFilter(lookup_type='icontains')
    type = MultipleChoiceFilter(choices=[])
    format = MultipleChoiceFilter(choices=[])
    requester = ModelMultipleChoiceFilter(queryset=Dojo_User.objects.all())
    datetime = DateTimeFilter()
    status = MultipleChoiceFilter(choices=[])

    class Meta:
        model = Report
        exclude = ['task_id', 'file']
        order_by = (('-datetime', 'Date Desc'), ('datetime', 'Date Asc'),
                    ('name', 'Name'), ('-name', 'Name Desc'), ('type', 'Type'),
                    ('-type', 'Type Desc'), ('format', 'Format'),
                    ('-format', 'Format Desc'), ('requester', 'Requester'),
                    ('-requester', 'Requester Desc'))

    def __init__(self, *args, **kwargs):
        super(ReportFilter, self).__init__(*args, **kwargs)
        type = dict()
        type = dict([report.type, report.type]
                    for report in self.queryset.distinct()
                    if report.type is not None)
        type = collections.OrderedDict(sorted(type.items()))
        self.form.fields['type'].choices = type.items()

        status = dict()
        status = dict([report.status, report.status]
                      for report in self.queryset.distinct()
                      if report.status is not None)
        status = collections.OrderedDict(sorted(status.items()))
        self.form.fields['status'].choices = status.items()
Ejemplo n.º 17
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']
Ejemplo n.º 18
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
            }
Ejemplo n.º 19
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
            }
Ejemplo n.º 20
0
class EventFilter(FilterSet):
    # https://django-filter.readthedocs.io/en/latest/guide/usage.html#declaring-filters

    start = DateTimeFromToRangeFilter(field_name="occurrences__start")
    category = ModelMultipleChoiceFilter(
        field_name="categories__name",
        to_field_name="name",
        queryset=EventCategory.objects.all(),
    )
    tag = ModelMultipleChoiceFilter(field_name="tags__name",
                                    to_field_name="name",
                                    queryset=Tag.objects.all())

    class Meta:
        model = Event
        fields = ["occurrences__start", "category", "tag"]
Ejemplo n.º 21
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 = []
Ejemplo n.º 22
0
class StaffFilter(SortedFilterSet):
    name_or_email = CharFilter(label=pgettext_lazy('Staff list filter label',
                                                   'Name or email'),
                               method=filter_by_customer)
    location = CharFilter(label=pgettext_lazy('Staff list filter label',
                                              'Location'),
                          method=filter_by_location)
    groups = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Staff list filter label', 'Groups'),
                                       name='groups',
                                       queryset=Group.objects.all())
    is_active = ChoiceFilter(label=pgettext_lazy('Staff list filter label',
                                                 'Is active'),
                             choices=IS_ACTIVE_CHOICES,
                             empty_label=pgettext_lazy(
                                 'Filter empty choice label', 'All'),
                             widget=forms.Select)
    sort_by = OrderingFilter(label=pgettext_lazy('Staff list filter label',
                                                 'Sort by'),
                             fields=SORT_BY_FIELDS,
                             field_labels=SORT_BY_FIELDS_LABELS)

    class Meta:
        model = User
        fields = []
Ejemplo n.º 23
0
class GroupFilter(SortedFilterSet):
    name = CharFilter(label=pgettext_lazy('Group list filter label', 'Name'),
                      lookup_expr='icontains')
    permissions = ModelMultipleChoiceFilter(label=pgettext_lazy(
        'Group list filter label', 'Permissions'),
                                            name='permissions',
                                            queryset=get_permissions())
    sort_by = OrderingFilter(label=pgettext_lazy('Group list filter label',
                                                 'Sort by'),
                             fields=SORT_BY_FIELDS.keys(),
                             field_labels=SORT_BY_FIELDS)

    class Meta:
        model = Group
        fields = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            'Number of matching records in the dashboard groups list',
            'Found %(counter)d matching group',
            'Found %(counter)d matching groups',
            number=counter) % {
                'counter': counter
            }
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 = []
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']
Ejemplo n.º 26
0
class ProductFindingFilter(FilterSet):
    title = CharFilter(lookup_type='icontains')
    date = DateRangeFilter()
    cwe = MultipleChoiceFilter(choices=[])
    severity = MultipleChoiceFilter(choices=[])
    test__test_type = ModelMultipleChoiceFilter(
        queryset=Test_Type.objects.all())

    class Meta:
        model = Finding
        order_by = (
            ('numerical_severity', 'Severity'),
            ('test__engagement__risk_acceptance__created', 'Date'),
        )
        exclude = [
            'url', 'description', 'mitigation', 'impact', 'endpoint',
            'references', 'test', 'is_template', 'active', 'verified',
            'out_of_scope', 'false_p', 'duplicate', 'thread_id', 'mitigated',
            'notes', 'numerical_severity', 'reporter'
        ]

    def __init__(self, *args, **kwargs):
        super(ProductFindingFilter, self).__init__(*args, **kwargs)
        cwe = dict()
        cwe = dict([finding.cwe, finding.cwe]
                   for finding in self.queryset.distinct()
                   if finding.cwe > 0 and finding.cwe not in cwe)
        cwe = collections.OrderedDict(sorted(cwe.items()))
        self.form.fields['cwe'].choices = cwe.items()
        sevs = dict()
        sevs = dict([finding.severity, finding.severity]
                    for finding in self.queryset.distinct()
                    if finding.severity not in sevs)
        self.form.fields['severity'].choices = sevs.items()
Ejemplo n.º 27
0
class MetricsFindingFilter(FilterSet):
    date = MetricsDateRangeFilter()
    test__engagement__product__prod_type = ModelMultipleChoiceFilter(
        queryset=Product_Type.objects.all().order_by('name'),
        label="Product Type")
    severity = MultipleChoiceFilter(choices=[])
    status = FindingStatusFilter(label='Status')

    def __init__(self, *args, **kwargs):
        super(MetricsFindingFilter, self).__init__(*args, **kwargs)
        self.form.fields['severity'].choices = self.queryset.order_by('numerical_severity') \
            .values_list('severity', 'severity').distinct()

    class Meta:
        model = Finding
        exclude = ['url',
                   'description',
                   'mitigation',
                   'unsaved_endpoints',
                   'unsaved_request',
                   'unsaved_response',
                   'unsaved_tags',
                   'references',
                   'review_requested_by',
                   'reviewers',
                   'defect_review_requested_by',
                   'thread_id',
                   'notes',
                   'last_reviewed_by',
                   'images',
                   'endpoints',
                   'is_template']
class TitleDescriptionModalityStructureFilter(FilterSet):
    search = CharFilter(method="search_filter", label="Title or Description")
    modalities = ModelMultipleChoiceFilter(
        queryset=ImagingModality.objects.all(),
        widget=Select2MultipleWidget,
        label="Modality",
    )
    structures = ModelMultipleChoiceFilter(
        queryset=BodyStructure.objects.select_related("region").all(),
        widget=Select2MultipleWidget,
        label="Anatomical Structure",
    )
    structures__region = ModelMultipleChoiceFilter(
        queryset=BodyRegion.objects.all(),
        widget=Select2MultipleWidget,
        label="Anatomical Region",
    )
    organizations = ModelMultipleChoiceFilter(
        queryset=Organization.objects.all(),
        widget=Select2MultipleWidget,
        label="Organization",
        field_name="organizations__slug",
        to_field_name="slug",
    )

    class Meta:
        fields = (
            "search",
            "modalities",
            "structures",
            "structures__region",
            "organizations",
        )
        form = FilterForm
        search_fields = ("title", "description")

    def search_filter(self, queryset, name, value):
        return queryset.filter(
            reduce(
                or_,
                [
                    Q(**{f"{f}__icontains": value})
                    for f in self.Meta.search_fields
                ],
                Q(),
            )
        )
Ejemplo n.º 29
0
class ProductFilter(SortedFilterSet):
    name = CharFilter(
        label=pgettext_lazy("Product list filter label", "Name"),
        lookup_expr="icontains",
    )
    category = ModelMultipleChoiceFilter(
        label=pgettext_lazy("Product list filter label", "Category"),
        field_name="category",
        queryset=Category.objects.all(),
        null_label="---------",
    )
    product_type = ModelMultipleChoiceFilter(
        label=pgettext_lazy("Product list filter label", "Product type"),
        field_name="product_type",
        queryset=ProductType.objects.all(),
    )
    price = RangeFilter(
        label=pgettext_lazy("Product list filter label", "Price"),
        field_name="price_amount",
        widget=MoneyRangeWidget,
    )
    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,
    )
    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 = []

    def get_summary_message(self):
        counter = self.qs.count()
        return npgettext(
            "Number of matching records in the dashboard products list",
            "Found %(counter)d matching product",
            "Found %(counter)d matching products",
            number=counter,
        ) % {
            "counter": counter
        }
Ejemplo n.º 30
0
class BenthicAttributeFilterSet(BaseAPIFilterSet):
    parent = NullableUUIDFilter(field_name='parent')
    life_history = NullableUUIDFilter(field_name='life_history')
    regions = ModelMultipleChoiceFilter(queryset=Region.objects.all())

    class Meta:
        model = BenthicAttribute
        fields = ['parent', 'life_history', 'regions', ]