From c09473f41ebeabeb741d05c8ed1fc350fe56d2cc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 4 Apr 2017 14:19:48 -0400 Subject: [PATCH] #1033: Convert SelectWithDisabled to a templatized widget --- netbox/utilities/forms.py | 27 +------------------ .../templates/selectwithdisabled_option.html | 1 + 2 files changed, 2 insertions(+), 26 deletions(-) create mode 100644 netbox/utilities/templates/selectwithdisabled_option.html diff --git a/netbox/utilities/forms.py b/netbox/utilities/forms.py index 35be15926f4..69ee34a6009 100644 --- a/netbox/utilities/forms.py +++ b/netbox/utilities/forms.py @@ -133,32 +133,7 @@ class SelectWithDisabled(forms.Select): Modified the stock Select widget to accept choices using a dict() for a label. The dict for each option must include 'label' (string) and 'disabled' (boolean). """ - - def render_option(self, selected_choices, option_value, option_label): - - # Determine if option has been selected - option_value = force_text(option_value) - if option_value in selected_choices: - selected_html = mark_safe(' selected="selected"') - if not self.allow_multiple_selected: - # Only allow for a single selection. - selected_choices.remove(option_value) - else: - selected_html = '' - - # Determine if option has been disabled - option_disabled = False - exempt_value = force_text(self.attrs.get('exempt', None)) - if isinstance(option_label, dict): - option_disabled = option_label['disabled'] if option_value != exempt_value else False - option_label = option_label['label'] - disabled_html = ' disabled="disabled"' if option_disabled else '' - - return format_html(u'', - option_value, - selected_html, - disabled_html, - force_text(option_label)) + option_template_name = 'selectwithdisabled_option.html' class ArrayFieldSelectMultiple(SelectWithDisabled, forms.SelectMultiple): diff --git a/netbox/utilities/templates/selectwithdisabled_option.html b/netbox/utilities/templates/selectwithdisabled_option.html new file mode 100644 index 00000000000..df8f1f526f5 --- /dev/null +++ b/netbox/utilities/templates/selectwithdisabled_option.html @@ -0,0 +1 @@ +