mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Misc cleanup for config contexts
This commit is contained in:
parent
43ed38a6e9
commit
484a74defd
@ -11,7 +11,7 @@ from taggit.forms import TagField
|
|||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
|
||||||
from dcim.models import Region
|
from dcim.models import Region
|
||||||
from utilities.forms import add_blank_choice, BootstrapMixin, BulkEditForm, LaxURLField, SlugField
|
from utilities.forms import add_blank_choice, BootstrapMixin, BulkEditForm, LaxURLField, JSONField, SlugField
|
||||||
from .constants import (
|
from .constants import (
|
||||||
CF_FILTER_DISABLED, CF_TYPE_BOOLEAN, CF_TYPE_DATE, CF_TYPE_INTEGER, CF_TYPE_SELECT, CF_TYPE_URL,
|
CF_FILTER_DISABLED, CF_TYPE_BOOLEAN, CF_TYPE_DATE, CF_TYPE_INTEGER, CF_TYPE_SELECT, CF_TYPE_URL,
|
||||||
OBJECTCHANGE_ACTION_CHOICES,
|
OBJECTCHANGE_ACTION_CHOICES,
|
||||||
@ -213,6 +213,7 @@ class ConfigContextForm(BootstrapMixin, forms.ModelForm):
|
|||||||
queryset=Region.objects.all(),
|
queryset=Region.objects.all(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
data = JSONField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ConfigContext
|
model = ConfigContext
|
||||||
|
@ -31,6 +31,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<pre>{{ context.data|render_json }}</pre>
|
<pre>{{ context.data|render_json }}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
{% empty %}
|
||||||
|
<div class="panel-body">
|
||||||
|
<span class="text-muted">None found</span>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,6 +6,7 @@ import re
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib.postgres.forms import JSONField as _JSONField
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from mptt.forms import TreeNodeMultipleChoiceField
|
from mptt.forms import TreeNodeMultipleChoiceField
|
||||||
@ -536,6 +537,22 @@ class LaxURLField(forms.URLField):
|
|||||||
default_validators = [EnhancedURLValidator()]
|
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
|
# Forms
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user