Allow reports to be sorted by object information or status. #2195

Closed
opened 2025-12-29 17:23:23 +01:00 by adam · 2 comments
Owner

Originally created by @chaomodus on GitHub (Dec 11, 2018).

Description

Allow from the reports UI, or from the reports API, the consumer to specify sort column(s) and sort order, such as by object creation date, or by status (error, warning, success).

Use Case

Our use case is that we use reports to for example determine if hardware is old and should be considered for replacement. It would be preferable to be able to get this report with log_success sorted to the bottom to focus attention on the log_error lines which indicate old hardware. This feature is generic however and would likely have numerous uses.

Originally created by @chaomodus on GitHub (Dec 11, 2018). ### Description Allow from the reports UI, or from the reports API, the consumer to specify sort column(s) and sort order, such as by object creation date, or by status (error, warning, success). ### Use Case Our use case is that we use reports to for example determine if hardware is old and should be considered for replacement. It would be preferable to be able to get this report with log_success sorted to the bottom to focus attention on the log_error lines which indicate old hardware. This feature is generic however and would likely have numerous uses.
adam closed this issue 2025-12-29 17:23:23 +01:00
Author
Owner

@paravoid commented on GitHub (Dec 14, 2018):

It would be neat perhaps to have an option to hide successes entirely (perhaps even the default?). Otherwise one would have go go over a few thousand successes only (or sort them) just to identify a handful of failures.

@paravoid commented on GitHub (Dec 14, 2018): It would be neat perhaps to have an option to hide successes entirely (perhaps even the default?). Otherwise one would have go go over a few thousand successes only (or sort them) just to identify a handful of failures.
Author
Owner

@jeremystretch commented on GitHub (Dec 19, 2018):

Individual successes and failures logged within a report are not orderable at the database level: These are all stored as a single JSON object and listed in the order they were generated. You can achieve a particular ordering of results by calling log_success(), log_failure(), etc. in the desired order within the report. For example:

infos = []
for device in Device.objects.all():
    if not device.serial:
        self.log_failure(device, "Mising serial number!")
    else:
        infos.append(device)
for info in infos:
    self.log_info(device, "{} has a serial number: {}".format(device.name, device.serial))
@jeremystretch commented on GitHub (Dec 19, 2018): Individual successes and failures logged within a report are not orderable at the database level: These are all stored as a single JSON object and listed in the order they were generated. You can achieve a particular ordering of results by calling `log_success()`, `log_failure()`, etc. in the desired order within the report. For example: ``` infos = [] for device in Device.objects.all(): if not device.serial: self.log_failure(device, "Mising serial number!") else: infos.append(device) for info in infos: self.log_info(device, "{} has a serial number: {}".format(device.name, device.serial)) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2195