1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Misc cleanup for config contexts

This commit is contained in:
Jeremy Stretch
2018-07-10 16:16:23 -04:00
parent 43ed38a6e9
commit 484a74defd
3 changed files with 23 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import re
from django import forms
from django.conf import settings
from django.contrib.postgres.forms import JSONField as _JSONField
from django.db.models import Count
from django.urls import reverse_lazy
from mptt.forms import TreeNodeMultipleChoiceField
@ -536,6 +537,22 @@ class LaxURLField(forms.URLField):
default_validators = [EnhancedURLValidator()]
class JSONField(_JSONField):
"""
Custom wrapper around Django's built-in JSONField to avoid presenting "null" as the default text.
"""
def __init__(self, *args, **kwargs):
super(JSONField, self).__init__(*args, **kwargs)
if not self.help_text:
self.help_text = 'Enter context data in <a href="https://json.org/">JSON</a> format.'
self.widget.attrs['placeholder'] = ''
def prepare_value(self, value):
if value is None:
return ''
return super(JSONField, self).prepare_value(value)
#
# Forms
#