Overview Filter

Filter form allows user to select observation and issue filtering option and implements filtering logic. It is mainly used in dashboards to filter data displayed in graphs and tables.

class megforms.filter_form.JQueryQueryBuilderFilterMixin(data=None, *args, **kwargs)

A Mixin for FilterForms. Has functions to handle a jQuery QueryBuilder’s JSON query and build Q() objects from the data. Assumes the use of the querybuilder_options() templatetag to set the QueryBuilder’s config.

property builderjson: dict

The jQuery QueryBuilder JSON query, if one was received.

static handle_rule(rule_json: dict) Q

Interpret a single ‘rule’ dictionary into a Q() object. These are the leaf nodes of the QueryBuilder query..

handle_group(group_json: dict) Q

Interpret a single ‘group’ dictionary into a Q() object. These are the branch nodes of a QueryBuilder query. They can contain a combination of rules, and other groups. Process the children into Q()s, and combine them using the group’s chosen operator (AND, or OR).

property builderjson_q: Q

A Q() object built from a jQuery Querybuilder’s JSON query.

class megforms.filter_form.DeferredValidationModelMultipleChoiceField(queryset, **kwargs)

A multi-choice model choice field that avoids validation errors for choices not in the queryset.

class megforms.filter_form.OverviewFilterForm(form: ~megforms.models.AuditForm | ~megforms.models.AuditFormQueryset, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, hide_fields=('qip_status', 'handlers', 'qip_search', 'risk_levels'), current_auditor: ~megforms.models.Auditor | None = None, only_fields: set[str] | None = None, qip: bool = False, timeframe: ~datetime.timedelta | None = None, bookmarked_filter: ~dashboard_widgets.models.BookmarkedFilter | None = None)

Provides observation and QIP issue filtering form and logic

is_lfpse

Whether the audit form is linked with LFPSE

Returns:

True if working with only one form, and that form is an LFPSE form

property custom_filters: Iterator[Tuple[str, CustomField | CustomIssueField]]

Generates filters based off custom fields Yields: tuple of (filter_name, Custom field)

form_institutions

All institutions from all selected forms

property selected_institutions: InstitutionQuerySet

Gets institutions selected by user, falls back to showing all institutions relevant to selected forms if institutions dropdown is not present.

selected_forms

Queryset of all audit forms selected in filters. If form dropdown is not present, returns all forms passed to the filter form.

all_institutions

All institutions available for this dashboard. This includes all institutions from current group, or only current institution if it’s not group level

data_or_initial

Returns cleaned data, or, if data was not submitted, initial (default) values. Any missing values are replaced by initial

time_range

Tuple of start/end date for selected time period

filter_params(time_range: DateTimeRange | None = None, exclude_filters: Collection[str] = ()) dict[str, Any]

Creates kwargs for queryset filter() method to apply this filter

Parameters:
  • time_range – override time range value

  • exclude_filters – filter field names to be excluded from this filter

filter_issues(issues: IssueQueryset, custom_observations: ObservationQueryset = None, including_children: bool = False) IssueQueryset

Filters issues queryset based on status

selected_subforms

Subforms selected by user, or all subforms if none selected or no subform dropdown

get_subforms_q() Q

Builds filter condition for observations based on selected forms. Resulting observations have at least one sub-observation from one of the subforms selected by the user If no subforms are selected, no adjustments to the filtering logic would be made.

advanced_filters

Creates more advanced filters (using OR etc) :return: object used to filter observation queryset. This Q object does not include regular filters

get_q(time_range: DateTimeRange | None = None, **kwargs) Q

Q object representing filter

filter(qs: QuerySet, time_range: DateTimeRange | None = None, **kwargs) ObservationQueryset

Filter Observations

Parameters:
  • qs – base queryset

  • time_range – override time range selected by user. For example, use this argument to select preceding time range

filter_for_form(form: AuditForm) ObservationQueryset

Filter Observations for specific Audit form

Parameters:

form – base Audit Form

property media

Return all media required to render the widgets on this form.

property model_custom_field_names: list[str]

Return list of model field names for limit choices functionality

property conditions: list[tuple[str, list[audit_builder.types.Condition]]]

Return list of conditions for limit choices functionality