mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
Fix system config export
This commit is contained in:
parent
3c2af97823
commit
ffbc8b4b41
@ -574,13 +574,14 @@ class SystemView(UserPassesTestMixin, View):
|
|||||||
k: getattr(config, k) for k in sorted(params)
|
k: getattr(config, k) for k in sorted(params)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
response = HttpResponse(json.dumps(data, indent=4), content_type='text/json')
|
response = HttpResponse(json.dumps(data, cls=ConfigJSONEncoder, indent=4), content_type='text/json')
|
||||||
response['Content-Disposition'] = 'attachment; filename="netbox.json"'
|
response['Content-Disposition'] = 'attachment; filename="netbox.json"'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
plugins_table = tables.PluginTable(plugins, orderable=False)
|
plugins_table = tables.PluginTable(plugins, orderable=False)
|
||||||
plugins_table.configure(request)
|
plugins_table.configure(request)
|
||||||
|
|
||||||
|
# Serialize any CustomValidator classes
|
||||||
if hasattr(config, 'CUSTOM_VALIDATORS') and config.CUSTOM_VALIDATORS:
|
if hasattr(config, 'CUSTOM_VALIDATORS') and config.CUSTOM_VALIDATORS:
|
||||||
config.CUSTOM_VALIDATORS = json.dumps(config.CUSTOM_VALIDATORS, cls=ConfigJSONEncoder, indent=4)
|
config.CUSTOM_VALIDATORS = json.dumps(config.CUSTOM_VALIDATORS, cls=ConfigJSONEncoder, indent=4)
|
||||||
|
|
||||||
|
@ -20,11 +20,12 @@ class CustomFieldJSONEncoder(DjangoJSONEncoder):
|
|||||||
|
|
||||||
class ConfigJSONEncoder(DjangoJSONEncoder):
|
class ConfigJSONEncoder(DjangoJSONEncoder):
|
||||||
"""
|
"""
|
||||||
Override Django's built-in JSON encoder to save python functions as function names.
|
Override Django's built-in JSON encoder to serialize CustomValidator classes as strings.
|
||||||
"""
|
"""
|
||||||
def default(self, o):
|
def default(self, o):
|
||||||
from extras.validators import CustomValidator
|
from extras.validators import CustomValidator
|
||||||
|
|
||||||
if issubclass(type(o), CustomValidator):
|
if issubclass(type(o), CustomValidator):
|
||||||
return type(o).__name__
|
return type(o).__name__
|
||||||
|
|
||||||
return super().default(o)
|
return super().default(o)
|
||||||
|
Loading…
Reference in New Issue
Block a user