2021-12-21 17:05:06 -05:00
|
|
|
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):
|
|
|
|
self.label = label
|
|
|
|
self.choices = choices
|
|
|
|
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(),
|
2021-12-21 20:30:59 -05:00
|
|
|
description='The number of objects to display per page',
|
2021-12-21 17:05:06 -05:00
|
|
|
coerce=lambda x: int(x)
|
|
|
|
),
|
|
|
|
|
|
|
|
# Miscellaneous
|
|
|
|
'data_format': UserPreference(
|
|
|
|
label='Data format',
|
|
|
|
choices=(
|
|
|
|
('json', 'JSON'),
|
|
|
|
('yaml', 'YAML'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
}
|