Skip to content

Filters

hypha.apply.projects.filters

User module-attribute

User = get_user_model()

InvoiceListFilter

Bases: FilterSet

fund class-attribute instance-attribute

fund = Select2ModelMultipleChoiceFilter(label=gettext_lazy('Funds'), queryset=get_used_funds, field_name='project__submission__page')

status class-attribute instance-attribute

status = Select2MultipleChoiceFilter(label=gettext_lazy('Status'), choices=INVOICE_STATUS_CHOICES)

lead class-attribute instance-attribute

lead = Select2ModelMultipleChoiceFilter(label=gettext_lazy('Lead'), queryset=get_project_leads, field_name='project__lead')

Meta

fields class-attribute instance-attribute
fields = ['lead', 'fund', 'status']
model class-attribute instance-attribute
model = Invoice

ProjectListFilter

Bases: FilterSet

REPORTING_CHOICES class-attribute instance-attribute

REPORTING_CHOICES = ((0, 'Up to date'), (1, 'Behind schedule'))

project_fund class-attribute instance-attribute

project_fund = Select2ModelMultipleChoiceFilter(field_name='submission__page', label=gettext_lazy('Funds'), queryset=get_used_funds)

project_lead class-attribute instance-attribute

project_lead = Select2ModelMultipleChoiceFilter(field_name='lead', label=gettext_lazy('Lead'), queryset=get_project_leads)

project_status class-attribute instance-attribute

project_status = Select2MultipleChoiceFilter(field_name='status', label=gettext_lazy('Status'), choices=PROJECT_STATUS_CHOICES)

query class-attribute instance-attribute

query = CharFilter(field_name='title', lookup_expr='icontains', widget=HiddenInput)

reporting class-attribute instance-attribute

reporting = ChoiceFilter(choices=REPORTING_CHOICES, method='filter_reporting', widget=Select2Widget(attrs={'data-placeholder': 'Reporting', 'data-minimum-results-for-search': -1}))

Meta

fields class-attribute instance-attribute
fields = ['project_status', 'project_lead', 'project_fund']
model class-attribute instance-attribute
model = Project

filter_reporting

filter_reporting(queryset, name, value)
Source code in hypha/apply/projects/filters.py
def filter_reporting(self, queryset, name, value):
    if value == "1":
        return queryset.filter(outstanding_reports__gt=0)
    return queryset.filter(
        Q(outstanding_reports__lt=1) | Q(outstanding_reports__isnull=True),
        status__in=(INVOICING_AND_REPORTING, CLOSING),
    )

DateRangeInputWidget

DateRangeInputWidget(attrs=None)

Bases: SuffixedMultiWidget

Source code in hypha/apply/projects/filters.py
def __init__(self, attrs=None):
    widgets = (forms.DateInput, forms.DateInput)
    super().__init__(widgets, attrs)

template_name class-attribute instance-attribute

template_name = 'application_projects/filters/widgets/date_range_input_widget.html'

suffixes class-attribute instance-attribute

suffixes = ['after', 'before']

decompress

decompress(value)
Source code in hypha/apply/projects/filters.py
def decompress(self, value):
    if value:
        return [value.start, value.stop]
    return [None, None]

ReportListFilter

Bases: FilterSet

reporting_period class-attribute instance-attribute

reporting_period = DateFromToRangeFilter(label=gettext_lazy('Reporting Period'), method='filter_reporting_period', widget=DateRangeInputWidget)

submitted class-attribute instance-attribute

submitted = DateFromToRangeFilter(widget=DateRangeInputWidget)

Meta

model class-attribute instance-attribute
model = Report
fields class-attribute instance-attribute
fields = ['submitted']

filter_reporting_period

filter_reporting_period(queryset, name, value)
Source code in hypha/apply/projects/filters.py
def filter_reporting_period(self, queryset, name, value):
    after, before = value.start, value.stop
    q = {}
    if after:
        q["start__gte"] = after
    if before:
        q["end_date__lte"] = before

    return queryset.filter(**q)

get_project_leads

get_project_leads(request)
Source code in hypha/apply/projects/filters.py
def get_project_leads(request):
    return User.objects.filter(lead_projects__isnull=False).distinct()