Skip to content

Only show valid platforms when editing a device #3809

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

Closed
hoalex opened this issue Dec 30, 2019 · 3 comments
Closed

Only show valid platforms when editing a device #3809

hoalex opened this issue Dec 30, 2019 · 3 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@hoalex
Copy link

hoalex commented Dec 30, 2019

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.9

Proposed Functionality

When editing a device, only show valid values for the "Platform" field, i.e. such platforms that either have a) no manufacturer or b) the manufacturer of the device assigned.

Use Case

Currently, the user is presented with a list of all platforms defined in Netbox. When selecting a platform that has a manufacturer different to that of the device, the following message appears after clicking on "Update":
netbox_platform

Limiting the drop down menu to valid values only makes it easier to find the correct entry when dealing with a large number of platforms and avoids the above error message in the first place.

Database Changes

none

External Dependencies

none

@hSaria
Copy link
Contributor

hSaria commented Dec 30, 2019

I can do the "manufacturer of the device" bit (below), but I'm not sure how additionally list the platforms with no manufacturers.

--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -1339,7 +1339,8 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
         widget=APISelect(
             api_url="/api/dcim/manufacturers/",
             filter_for={
-                'device_type': 'manufacturer_id'
+                'device_type': 'manufacturer_id',
+                'platform': 'manufacturer_id'
             }
         )
     )

A platform with no manufacturer is currently assignable to a device with a specific platform, so the above will stop that as it will filter out any platforms with no manufacturers, unless the user picks the device's platform (no manufacturer) first, then the device's manufacturer (a bit janky).

@jeremystretch
Copy link
Member

Looks like we've worked ourselves into a corner here. The current implementation only allows for filter a) a specific value, or b) null, if the filtering field is nullable. However, manufacturer is required and thus not nullable. (But even if it was, we still want to match on $value OR null.)

The least disruptive solution might be to allow appending +null to the filter_for value and treating it as a special condition. For example:

filter_for={
    'device_type': 'manufacturer_id',
    'platform': 'manufacturer_id+null'
}

Modifying the applicable Javascript would result in the API call GET /api/dcim/platforms/?manufacturer_id=123&manufacturer_id=null (where 123 is the value of the manufacturer field).

I'll take a shot at this and see if it works.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Dec 31, 2019
@jeremystretch jeremystretch self-assigned this Dec 31, 2019
@jeremystretch
Copy link
Member

Looking into this further, we should be able to use additional_query_params. Just need to modify the Javscript to allow for redundant query values.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants