From 9476fda987000eb7b176c459f0b3057bc89ec4c3 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 21 Apr 2021 10:29:25 -0400 Subject: [PATCH] Closes #5994: Drop support for display_field argument on ObjectVar --- docs/additional-features/custom-scripts.md | 6 ------ docs/release-notes/version-2.12.md | 1 + netbox/extras/scripts.py | 11 ----------- netbox/project-static/js/forms.js | 2 +- netbox/utilities/forms/fields.py | 11 +++-------- netbox/virtualization/forms.py | 4 +--- 6 files changed, 6 insertions(+), 29 deletions(-) diff --git a/docs/additional-features/custom-scripts.md b/docs/additional-features/custom-scripts.md index 3ed910791..a27bcab83 100644 --- a/docs/additional-features/custom-scripts.md +++ b/docs/additional-features/custom-scripts.md @@ -170,14 +170,9 @@ Similar to `ChoiceVar`, but allows for the selection of multiple choices. A particular object within NetBox. Each ObjectVar must specify a particular model, and allows the user to select one of the available instances. ObjectVar accepts several arguments, listed below. * `model` - The model class -* `display_field` - The name of the REST API object field to display in the selection list (default: `'display'`) * `query_params` - A dictionary of query parameters to use when retrieving available options (optional) * `null_option` - A label representing a "null" or empty choice (optional) -!!! warning - The `display_field` parameter is now deprecated, and will be removed in NetBox v2.12. All ObjectVar instances will - instead use the new standard `display` field for all serializers (introduced in NetBox v2.11). - To limit the selections available within the list, additional query parameters can be passed as the `query_params` dictionary. For example, to show only devices with an "active" status: ```python @@ -288,7 +283,6 @@ class NewBranchScript(Script): switch_model = ObjectVar( description="Access switch model", model=DeviceType, - display_field='model', query_params={ 'manufacturer_id': '$manufacturer' } diff --git a/docs/release-notes/version-2.12.md b/docs/release-notes/version-2.12.md index dcdbeb74a..548868a3d 100644 --- a/docs/release-notes/version-2.12.md +++ b/docs/release-notes/version-2.12.md @@ -5,3 +5,4 @@ ### Other Changes * [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6 +* [#5994](https://github.com/netbox-community/netbox/issues/5994) - Drop support for `display_field` argument on ObjectVar diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 29ecc3ef3..156b88065 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -180,27 +180,16 @@ class ObjectVar(ScriptVariable): A single object within NetBox. :param model: The NetBox model being referenced - :param display_field: The attribute of the returned object to display in the selection list (DEPRECATED) :param query_params: A dictionary of additional query parameters to attach when making REST API requests (optional) :param null_option: The label to use as a "null" selection option (optional) """ form_field = DynamicModelChoiceField def __init__(self, model, query_params=None, null_option=None, *args, **kwargs): - - # TODO: Remove display_field in v2.12 - if 'display_field' in kwargs: - warnings.warn( - "The 'display_field' parameter has been deprecated, and will be removed in NetBox v2.12. Object " - "variables will now reference the 'display' attribute available on all model serializers by default." - ) - display_field = kwargs.pop('display_field', 'display') - super().__init__(*args, **kwargs) self.field_attrs.update({ 'queryset': model.objects.all(), - 'display_field': display_field, 'query_params': query_params, 'null_option': null_option, }) diff --git a/netbox/project-static/js/forms.js b/netbox/project-static/js/forms.js index b95100acc..08af273a0 100644 --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -201,7 +201,7 @@ $(document).ready(function() { var results = data.results; results = results.reduce((results,record,idx) => { - record.text = record[element.getAttribute('display-field')] || record.name; + record.text = record.display; if (record._depth) { // Annotate hierarchical depth for MPTT objects record.text = '--'.repeat(record._depth) + ' ' + record.text; diff --git a/netbox/utilities/forms/fields.py b/netbox/utilities/forms/fields.py index 9bc0e3df7..88569c694 100644 --- a/netbox/utilities/forms/fields.py +++ b/netbox/utilities/forms/fields.py @@ -328,7 +328,6 @@ class ExpandableIPAddressField(forms.CharField): class DynamicModelChoiceMixin: """ - :param display_field: The name of the attribute of an API response object to display in the selection list :param query_params: A dictionary of additional key/value pairs to attach to the API request :param initial_params: A dictionary of child field references to use for selecting a parent field's initial value :param null_option: The string used to represent a null selection (if any) @@ -338,10 +337,8 @@ class DynamicModelChoiceMixin: filter = django_filters.ModelChoiceFilter widget = widgets.APISelect - # TODO: Remove display_field in v2.12 - def __init__(self, display_field='display', query_params=None, initial_params=None, null_option=None, - disabled_indicator=None, *args, **kwargs): - self.display_field = display_field + def __init__(self, query_params=None, initial_params=None, null_option=None, disabled_indicator=None, *args, + **kwargs): self.query_params = query_params or {} self.initial_params = initial_params or {} self.null_option = null_option @@ -354,9 +351,7 @@ class DynamicModelChoiceMixin: super().__init__(*args, **kwargs) def widget_attrs(self, widget): - attrs = { - 'display-field': self.display_field, - } + attrs = {} # Set value-field attribute if the field specifies to_field_name if self.to_field_name: diff --git a/netbox/virtualization/forms.py b/netbox/virtualization/forms.py index 3da5c98d2..5fb56e280 100644 --- a/netbox/virtualization/forms.py +++ b/netbox/virtualization/forms.py @@ -667,7 +667,6 @@ class VMInterfaceCreateForm(BootstrapMixin, InterfaceCommonForm): parent = DynamicModelChoiceField( queryset=VMInterface.objects.all(), required=False, - display_field='display_name', query_params={ 'virtualmachine_id': 'virtual_machine', } @@ -756,8 +755,7 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm): ) parent = DynamicModelChoiceField( queryset=VMInterface.objects.all(), - required=False, - display_field='display_name' + required=False ) enabled = forms.NullBooleanField( required=False,