Skip to content

filters

log_panel.filters

LevelFilter

Bases: SimpleListFilter

Filter log entries by level without scanning the log table for distinct values.

LoggerNameFilter

Bases: SimpleListFilter

Filter by logger name, reading choices from the small Logger table.

CardListFilter(request)

Applies the card-level filter from the request.

Source code in log_panel/filters.py
def __init__(self, request: HttpRequest) -> None:
    filter: str = request.GET.get(key=self.parameter_name, default="")
    valid_values: set[str] = {f.value for f in CardFilter}

    if filter in valid_values:
        self.value: CardFilter = CardFilter(value=filter)
    else:
        self.value: Literal[CardFilter.ALL] = CardFilter.ALL
        if filter:
            messages.warning(
                request,
                message=f"Unknown filter '{filter}', fall back to 'All'.",
            )

apply(rows)

Return only the rows matching the selected filter.

Source code in log_panel/filters.py
def apply(self, rows: list[dict]) -> list[dict]:
    """Return only the rows matching the selected filter."""
    if self.value is CardFilter.ERRORS:
        return [r for r in rows if r.get("total_errors", 0) > 0]
    if self.value is CardFilter.WARNINGS:
        return [r for r in rows if r.get("total_warnings", 0) > 0]
    return rows