mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
17219 fix custom validator display if function
This commit is contained in:
parent
92e1f14d81
commit
67e4b8c8c6
@ -25,6 +25,7 @@ from rq.registry import (
|
|||||||
from rq.worker import Worker
|
from rq.worker import Worker
|
||||||
from rq.worker_registration import clean_worker_registry
|
from rq.worker_registration import clean_worker_registry
|
||||||
|
|
||||||
|
from extras.validators import CustomValidator
|
||||||
from netbox.config import get_config, PARAMS
|
from netbox.config import get_config, PARAMS
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from netbox.views.generic.base import BaseObjectView
|
from netbox.views.generic.base import BaseObjectView
|
||||||
@ -522,6 +523,23 @@ class SystemView(UserPassesTestMixin, View):
|
|||||||
def test_func(self):
|
def test_func(self):
|
||||||
return self.request.user.is_staff
|
return self.request.user.is_staff
|
||||||
|
|
||||||
|
def map_validators(self, validator):
|
||||||
|
if isinstance(validator, dict):
|
||||||
|
for k, v in validator.items():
|
||||||
|
if isinstance(v, tuple):
|
||||||
|
validator[k] = type(v[0]).__name__
|
||||||
|
else:
|
||||||
|
validator[k] = self.map_validators(v)
|
||||||
|
|
||||||
|
elif isinstance(validator, list):
|
||||||
|
for index, v in enumerate(validator):
|
||||||
|
validator[index] = self.map_validators(v)
|
||||||
|
|
||||||
|
elif issubclass(type(validator), CustomValidator):
|
||||||
|
return type(validator).__name__
|
||||||
|
|
||||||
|
return validator
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
# System stats
|
# System stats
|
||||||
@ -562,9 +580,7 @@ class SystemView(UserPassesTestMixin, View):
|
|||||||
|
|
||||||
# If Custom Validators is function (in configuration.py) get function name
|
# If Custom Validators is function (in configuration.py) get function name
|
||||||
if hasattr(config, 'CUSTOM_VALIDATORS') and config.CUSTOM_VALIDATORS:
|
if hasattr(config, 'CUSTOM_VALIDATORS') and config.CUSTOM_VALIDATORS:
|
||||||
for k, v in config.CUSTOM_VALIDATORS.items():
|
config.CUSTOM_VALIDATORS = self.map_validators(config.CUSTOM_VALIDATORS)
|
||||||
if isinstance(v, tuple):
|
|
||||||
config.CUSTOM_VALIDATORS[k] = type(v[0]).__name__
|
|
||||||
|
|
||||||
# Raw data export
|
# Raw data export
|
||||||
if 'export' in request.GET:
|
if 'export' in request.GET:
|
||||||
|
Loading…
Reference in New Issue
Block a user