mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-05 14:56:24 -06:00
Enable plugins to define user preferences
This commit is contained in:
+1
-10
@@ -2,10 +2,10 @@ from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm as DjangoPasswordChangeForm
|
||||
from django.utils.html import mark_safe
|
||||
|
||||
from netbox.preferences import PREFERENCES
|
||||
from utilities.forms import BootstrapMixin, DateTimePicker, StaticSelect
|
||||
from utilities.utils import flatten_dict
|
||||
from .models import Token, UserConfig
|
||||
from .preferences import PREFERENCES
|
||||
|
||||
|
||||
class LoginForm(BootstrapMixin, AuthenticationForm):
|
||||
@@ -44,15 +44,6 @@ class UserConfigForm(BootstrapMixin, forms.ModelForm, metaclass=UserConfigFormMe
|
||||
class Meta:
|
||||
model = UserConfig
|
||||
fields = ()
|
||||
fieldsets = (
|
||||
('User Interface', (
|
||||
'pagination.per_page',
|
||||
'ui.colormode',
|
||||
)),
|
||||
('Miscellaneous', (
|
||||
'data_format',
|
||||
)),
|
||||
)
|
||||
|
||||
def __init__(self, *args, instance=None, **kwargs):
|
||||
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
from utilities.paginator import EnhancedPaginator
|
||||
|
||||
|
||||
def get_page_lengths():
|
||||
return [
|
||||
(v, str(v)) for v in EnhancedPaginator.default_page_lengths
|
||||
]
|
||||
|
||||
|
||||
class UserPreference:
|
||||
|
||||
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x):
|
||||
@@ -15,33 +6,3 @@ class UserPreference:
|
||||
self.default = default if default is not None else choices[0]
|
||||
self.description = description
|
||||
self.coerce = coerce
|
||||
|
||||
|
||||
PREFERENCES = {
|
||||
|
||||
# User interface
|
||||
'ui.colormode': UserPreference(
|
||||
label='Color mode',
|
||||
choices=(
|
||||
('light', 'Light'),
|
||||
('dark', 'Dark'),
|
||||
),
|
||||
default='light',
|
||||
),
|
||||
'pagination.per_page': UserPreference(
|
||||
label='Page length',
|
||||
choices=get_page_lengths(),
|
||||
description='The number of objects to display per page',
|
||||
coerce=lambda x: int(x)
|
||||
),
|
||||
|
||||
# Miscellaneous
|
||||
'data_format': UserPreference(
|
||||
label='Data format',
|
||||
choices=(
|
||||
('json', 'JSON'),
|
||||
('yaml', 'YAML'),
|
||||
),
|
||||
),
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user