Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #16905 - Allow filtering on Device Status in InventoryItemTable #17260

Merged

Conversation

bctiemann
Copy link
Contributor

@bctiemann bctiemann commented Aug 23, 2024

Fixes: #16905 Allow filtering on Device Status in InventoryItemTable

Adds device_status as a filter field in Inventory Item list view, and associated filter in InventoryItemFilterSet.

Screenshot 2024-08-23 at 5 27 48 PM

@bctiemann bctiemann changed the title #16905 - Allow filtering on Device Status in InventoryItemTable Fixes: #16905 - Allow filtering on Device Status in InventoryItemTable Aug 23, 2024
@bctiemann bctiemann self-assigned this Aug 23, 2024
netbox/dcim/filtersets.py Outdated Show resolved Hide resolved
netbox/dcim/forms/filtersets.py Outdated Show resolved Hide resolved
@@ -1265,6 +1265,9 @@ class Meta:
def get_absolute_url(self):
return reverse('dcim:inventoryitem', kwargs={'pk': self.pk})

def get_device_status_color(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to avoid introducing "proxy" methods that only exist to return the value of an attribute of some related object. Instead, maybe we can refactor ChoiceFieldColumn to accept a custom function for determining the appropriate color. Then we could do something like this:

device_status = columns.ChoiceFieldColumn(
    accessor=tables.A('device__status'),
    verbose_name=_('Device Status'),
    color=lambda x: x.device.get_status_color()
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like where this is going. Let me know if you think the preference order I've got here looks right to you -- it takes the color callable first if provided, then falls back to the try-except of get_FOO_color as before.

…efactor ChoiceFieldColumn to support a "color" callable allowing get_FOO_color behavior to be overridden
netbox/dcim/filtersets.py Outdated Show resolved Hide resolved
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include tests for the device_status filters for all relevant models in dcim/tests/test_filtersets.py.

@jeremystretch jeremystretch merged commit a150e5d into develop Aug 29, 2024
6 checks passed
@jeremystretch jeremystretch deleted the 16905-inventoryitemlist-filter-by-device-status branch August 29, 2024 12:10
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow filtering of Inventory Items by Device Status
2 participants