mirror of
				https://github.com/netbox-community/netbox.git
				synced 2024-05-10 07:54:54 +00:00 
			
		
		
		
	Update config context display to reference data_format preference
This commit is contained in:
		@@ -4,8 +4,9 @@ The `users.UserConfig` model holds individual preferences for each user in the f
 | 
			
		||||
 | 
			
		||||
## Available Preferences
 | 
			
		||||
 | 
			
		||||
| Name | Description |
 | 
			
		||||
| ---- | ----------- |
 | 
			
		||||
| extras.configcontext.format | Preferred format when rendering config context data (JSON or YAML) |
 | 
			
		||||
| pagination.per_page | The number of items to display per page of a paginated table |
 | 
			
		||||
| tables.TABLE_NAME.columns | The ordered list of columns to display when viewing the table |
 | 
			
		||||
| Name                    | Description |
 | 
			
		||||
|-------------------------|-------------|
 | 
			
		||||
| data_format             | Preferred format when rendering raw data (JSON or YAML) |
 | 
			
		||||
| pagination.per_page     | The number of items to display per page of a paginated table |
 | 
			
		||||
| tables.${table}.columns | The ordered list of columns to display when viewing the table |
 | 
			
		||||
| ui.colormode            | Light or dark mode in the user interface |
 | 
			
		||||
 
 | 
			
		||||
@@ -296,9 +296,9 @@ class ConfigContextView(generic.ObjectView):
 | 
			
		||||
        if request.GET.get('format') in ['json', 'yaml']:
 | 
			
		||||
            format = request.GET.get('format')
 | 
			
		||||
            if request.user.is_authenticated:
 | 
			
		||||
                request.user.config.set('extras.configcontext.format', format, commit=True)
 | 
			
		||||
                request.user.config.set('data_format', format, commit=True)
 | 
			
		||||
        elif request.user.is_authenticated:
 | 
			
		||||
            format = request.user.config.get('extras.configcontext.format', 'json')
 | 
			
		||||
            format = request.user.config.get('data_format', 'json')
 | 
			
		||||
        else:
 | 
			
		||||
            format = 'json'
 | 
			
		||||
 | 
			
		||||
@@ -341,9 +341,9 @@ class ObjectConfigContextView(generic.ObjectView):
 | 
			
		||||
        if request.GET.get('format') in ['json', 'yaml']:
 | 
			
		||||
            format = request.GET.get('format')
 | 
			
		||||
            if request.user.is_authenticated:
 | 
			
		||||
                request.user.config.set('extras.configcontext.format', format, commit=True)
 | 
			
		||||
                request.user.config.set('data_format', format, commit=True)
 | 
			
		||||
        elif request.user.is_authenticated:
 | 
			
		||||
            format = request.user.config.get('extras.configcontext.format', 'json')
 | 
			
		||||
            format = request.user.config.get('data_format', 'json')
 | 
			
		||||
        else:
 | 
			
		||||
            format = 'json'
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
from django import forms
 | 
			
		||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm as DjangoPasswordChangeForm
 | 
			
		||||
 | 
			
		||||
from utilities.forms import BootstrapMixin, DateTimePicker
 | 
			
		||||
from utilities.forms import BootstrapMixin, DateTimePicker, StaticSelect
 | 
			
		||||
from utilities.utils import flatten_dict
 | 
			
		||||
from .models import Token, UserConfig
 | 
			
		||||
from .preferences import PREFERENCES
 | 
			
		||||
@@ -28,6 +28,7 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
 | 
			
		||||
                'help_text': preference.description,
 | 
			
		||||
                'coerce': preference.coerce,
 | 
			
		||||
                'required': False,
 | 
			
		||||
                'widget': StaticSelect,
 | 
			
		||||
            }
 | 
			
		||||
            preference_fields[field_name] = forms.TypedChoiceField(**field_kwargs)
 | 
			
		||||
        attrs.update(preference_fields)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user