diff --git a/netbox/templates/users/preferences.html b/netbox/templates/users/preferences.html index b9b0be665..6ce60a458 100644 --- a/netbox/templates/users/preferences.html +++ b/netbox/templates/users/preferences.html @@ -8,6 +8,7 @@
{% csrf_token %} + {# Built-in preferences #} {% for group, fields in form.fieldsets %}
@@ -19,6 +20,7 @@
{% endfor %} + {# Plugin preferences #} {% with plugin_fields=form.plugin_fields %} {% if plugin_fields %}
@@ -32,6 +34,50 @@ {% endif %} {% endwith %} + {# Table configurations #} +
+
+
Table Configurations
+
+
+ {% if request.user.config.data.tables %} + +
+ + + + + + + + + + + {% for table, prefs in request.user.config.data.tables.items %} + + + + + + + {% endfor %} + +
+ + TableOrderingColumns
+ + {{ table }}{{ prefs.ordering|join:", "|placeholder }}{{ prefs.columns|join:", "|placeholder }}
+
+ {% else %} +
+

None found

+
+ {% endif %} +
+
+
Cancel diff --git a/netbox/users/forms.py b/netbox/users/forms.py index 49c080853..d5e6218e5 100644 --- a/netbox/users/forms.py +++ b/netbox/users/forms.py @@ -50,6 +50,11 @@ class UserConfigForm(BootstrapMixin, forms.ModelForm, metaclass=UserConfigFormMe 'data_format', )), ) + # List of clearable preferences + pk = forms.MultipleChoiceField( + choices=[], + required=False + ) class Meta: model = UserConfig @@ -63,12 +68,23 @@ class UserConfigForm(BootstrapMixin, forms.ModelForm, metaclass=UserConfigFormMe super().__init__(*args, instance=instance, **kwargs) + # Compile clearable preference choices + self.fields['pk'].choices = ( + (f'tables.{table_name}', '') for table_name in instance.data.get('tables', []) + ) + def save(self, *args, **kwargs): # Set UserConfig data for pref_name, value in self.cleaned_data.items(): + if pref_name == 'pk': + continue self.instance.set(pref_name, value, commit=False) + # Clear selected preferences + for preference in self.cleaned_data['pk']: + self.instance.clear(preference) + return super().save(*args, **kwargs) @property