-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixes: #16905 - Allow filtering on Device Status in InventoryItemTable #17260
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
Conversation
…nventoryItemTable
| def get_absolute_url(self): | ||
| return reverse('dcim:inventoryitem', kwargs={'pk': self.pk}) | ||
|
|
||
| def get_device_status_color(self): |
There was a problem hiding this comment.
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()
)
There was a problem hiding this comment.
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
jeremystretch
left a comment
There was a problem hiding this 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.
Fixes: #16905 Allow filtering on Device Status in InventoryItemTable
Adds
device_statusas a filter field in Inventory Item list view, and associated filter inInventoryItemFilterSet.