mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-07 16:18: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)
|
||||
},
|
||||
}
|
||||
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"'
|
||||
return response
|
||||
|
||||
plugins_table = tables.PluginTable(plugins, orderable=False)
|
||||
plugins_table.configure(request)
|
||||
|
||||
# Serialize any CustomValidator classes
|
||||
if hasattr(config, 'CUSTOM_VALIDATORS') and config.CUSTOM_VALIDATORS:
|
||||
config.CUSTOM_VALIDATORS = json.dumps(config.CUSTOM_VALIDATORS, cls=ConfigJSONEncoder, indent=4)
|
||||
|
||||
|
@ -20,11 +20,12 @@ class CustomFieldJSONEncoder(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):
|
||||
from extras.validators import CustomValidator
|
||||
|
||||
if issubclass(type(o), CustomValidator):
|
||||
return type(o).__name__
|
||||
|
||||
return super().default(o)
|
||||
|
Loading…
Reference in New Issue
Block a user