mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-14 05:00:13 +02:00
Move TextCodePanel to netbox.ui.panels and remove SyncCodePanel
This commit is contained in:
@@ -36,7 +36,6 @@ __all__ = (
|
|||||||
'ObjectTypesPanel',
|
'ObjectTypesPanel',
|
||||||
'SavedFilterObjectTypesPanel',
|
'SavedFilterObjectTypesPanel',
|
||||||
'SavedFilterPanel',
|
'SavedFilterPanel',
|
||||||
'SyncCodePanel',
|
|
||||||
'TableConfigColumnsPanel',
|
'TableConfigColumnsPanel',
|
||||||
'TableConfigOrderingPanel',
|
'TableConfigOrderingPanel',
|
||||||
'TableConfigPanel',
|
'TableConfigPanel',
|
||||||
@@ -44,7 +43,6 @@ __all__ = (
|
|||||||
'TagObjectTypesPanel',
|
'TagObjectTypesPanel',
|
||||||
'TagPanel',
|
'TagPanel',
|
||||||
'TagsPanel',
|
'TagsPanel',
|
||||||
'TextCodePanel',
|
|
||||||
'WebhookHTTPPanel',
|
'WebhookHTTPPanel',
|
||||||
'WebhookPanel',
|
'WebhookPanel',
|
||||||
'WebhookSSLPanel',
|
'WebhookSSLPanel',
|
||||||
@@ -126,40 +124,6 @@ class ObjectTypesPanel(panels.ObjectPanel):
|
|||||||
title = _('Object Types')
|
title = _('Object Types')
|
||||||
|
|
||||||
|
|
||||||
class TextCodePanel(panels.ObjectPanel):
|
|
||||||
"""
|
|
||||||
A panel displaying a text field as a pre-formatted code block.
|
|
||||||
"""
|
|
||||||
template_name = 'extras/panels/text_code.html'
|
|
||||||
|
|
||||||
def __init__(self, field_name, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
self.field_name = field_name
|
|
||||||
|
|
||||||
def get_context(self, context):
|
|
||||||
return {
|
|
||||||
**super().get_context(context),
|
|
||||||
'value': getattr(context.get('object'), self.field_name, None),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class SyncCodePanel(panels.ObjectPanel):
|
|
||||||
"""
|
|
||||||
A panel displaying a text field with a sync warning included.
|
|
||||||
"""
|
|
||||||
template_name = 'extras/panels/sync_code.html'
|
|
||||||
|
|
||||||
def __init__(self, field_name, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
self.field_name = field_name
|
|
||||||
|
|
||||||
def get_context(self, context):
|
|
||||||
return {
|
|
||||||
**super().get_context(context),
|
|
||||||
'value': getattr(context.get('object'), self.field_name, None),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# CustomField panels
|
# CustomField panels
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import gettext_lazy as _l
|
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
from jinja2.exceptions import TemplateError
|
from jinja2.exceptions import TemplateError
|
||||||
|
|
||||||
@@ -25,7 +24,13 @@ from extras.dashboard.utils import get_widget_class
|
|||||||
from extras.utils import SharedObjectViewMixin
|
from extras.utils import SharedObjectViewMixin
|
||||||
from netbox.object_actions import *
|
from netbox.object_actions import *
|
||||||
from netbox.ui import layout
|
from netbox.ui import layout
|
||||||
from netbox.ui.panels import CommentsPanel, ContextTablePanel, JSONPanel, TemplatePanel
|
from netbox.ui.panels import (
|
||||||
|
CommentsPanel,
|
||||||
|
ContextTablePanel,
|
||||||
|
JSONPanel,
|
||||||
|
TemplatePanel,
|
||||||
|
TextCodePanel,
|
||||||
|
)
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from netbox.views.generic.mixins import TableMixin
|
from netbox.views.generic.mixins import TableMixin
|
||||||
from utilities.forms import ConfirmationForm, get_field_value
|
from utilities.forms import ConfirmationForm, get_field_value
|
||||||
@@ -43,7 +48,7 @@ from . import filtersets, forms, tables
|
|||||||
from .constants import LOG_LEVEL_RANK
|
from .constants import LOG_LEVEL_RANK
|
||||||
from .models import *
|
from .models import *
|
||||||
from .tables import ReportResultsTable, ScriptJobTable, ScriptResultsTable
|
from .tables import ReportResultsTable, ScriptJobTable, ScriptResultsTable
|
||||||
from .ui import panels as ui_panels
|
from .ui import panels
|
||||||
|
|
||||||
#
|
#
|
||||||
# Custom fields
|
# Custom fields
|
||||||
@@ -63,14 +68,14 @@ class CustomFieldView(generic.ObjectView):
|
|||||||
queryset = CustomField.objects.select_related('choice_set')
|
queryset = CustomField.objects.select_related('choice_set')
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.CustomFieldPanel(),
|
panels.CustomFieldPanel(),
|
||||||
ui_panels.CustomFieldBehaviorPanel(),
|
panels.CustomFieldBehaviorPanel(),
|
||||||
CommentsPanel(),
|
CommentsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.CustomFieldObjectTypesPanel(),
|
panels.CustomFieldObjectTypesPanel(),
|
||||||
ui_panels.CustomFieldValidationPanel(),
|
panels.CustomFieldValidationPanel(),
|
||||||
ui_panels.CustomFieldRelatedObjectsPanel(),
|
panels.CustomFieldRelatedObjectsPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -146,10 +151,10 @@ class CustomFieldChoiceSetView(generic.ObjectView):
|
|||||||
queryset = CustomFieldChoiceSet.objects.all()
|
queryset = CustomFieldChoiceSet.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.CustomFieldChoiceSetPanel(),
|
panels.CustomFieldChoiceSetPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.CustomFieldChoiceSetChoicesPanel(),
|
panels.CustomFieldChoiceSetChoicesPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -229,12 +234,12 @@ class CustomLinkView(generic.ObjectView):
|
|||||||
queryset = CustomLink.objects.all()
|
queryset = CustomLink.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.CustomLinkPanel(),
|
panels.CustomLinkPanel(),
|
||||||
ui_panels.ObjectTypesPanel(title=_l('Assigned Models')),
|
panels.ObjectTypesPanel(title=_('Assigned Models')),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.TextCodePanel('link_text', title=_l('Link Text')),
|
TextCodePanel('link_text', title=_('Link Text')),
|
||||||
ui_panels.TextCodePanel('link_url', title=_l('Link URL')),
|
TextCodePanel('link_url', title=_('Link URL')),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -296,15 +301,15 @@ class ExportTemplateView(generic.ObjectView):
|
|||||||
queryset = ExportTemplate.objects.all()
|
queryset = ExportTemplate.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.ExportTemplatePanel(),
|
panels.ExportTemplatePanel(),
|
||||||
TemplatePanel('core/inc/datafile_panel.html'),
|
TemplatePanel('core/inc/datafile_panel.html'),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.ObjectTypesPanel(title=_l('Assigned Models')),
|
panels.ObjectTypesPanel(title=_('Assigned Models')),
|
||||||
JSONPanel('environment_params', title=_l('Environment Parameters')),
|
JSONPanel('environment_params', title=_('Environment Parameters')),
|
||||||
],
|
],
|
||||||
bottom_panels=[
|
bottom_panels=[
|
||||||
ui_panels.SyncCodePanel('template_code', title=_l('Template')),
|
TextCodePanel('template_code', title=_('Template')),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -370,11 +375,11 @@ class SavedFilterView(SharedObjectViewMixin, generic.ObjectView):
|
|||||||
queryset = SavedFilter.objects.all()
|
queryset = SavedFilter.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.SavedFilterPanel(),
|
panels.SavedFilterPanel(),
|
||||||
ui_panels.SavedFilterObjectTypesPanel(),
|
panels.SavedFilterObjectTypesPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
JSONPanel('parameters', title=_l('Parameters')),
|
JSONPanel('parameters', title=_('Parameters')),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -441,11 +446,11 @@ class TableConfigView(SharedObjectViewMixin, generic.ObjectView):
|
|||||||
queryset = TableConfig.objects.all()
|
queryset = TableConfig.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.TableConfigPanel(),
|
panels.TableConfigPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.TableConfigColumnsPanel(),
|
panels.TableConfigColumnsPanel(),
|
||||||
ui_panels.TableConfigOrderingPanel(),
|
panels.TableConfigOrderingPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -543,11 +548,11 @@ class NotificationGroupView(generic.ObjectView):
|
|||||||
queryset = NotificationGroup.objects.all()
|
queryset = NotificationGroup.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.NotificationGroupPanel(),
|
panels.NotificationGroupPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.NotificationGroupGroupsPanel(),
|
panels.NotificationGroupGroupsPanel(),
|
||||||
ui_panels.NotificationGroupUsersPanel(),
|
panels.NotificationGroupUsersPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -736,15 +741,15 @@ class WebhookView(generic.ObjectView):
|
|||||||
queryset = Webhook.objects.all()
|
queryset = Webhook.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.WebhookPanel(),
|
panels.WebhookPanel(),
|
||||||
ui_panels.WebhookHTTPPanel(),
|
panels.WebhookHTTPPanel(),
|
||||||
ui_panels.WebhookSSLPanel(),
|
panels.WebhookSSLPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.TextCodePanel('additional_headers', title=_l('Additional Headers')),
|
TextCodePanel('additional_headers', title=_('Additional Headers')),
|
||||||
ui_panels.TextCodePanel('body_template', title=_l('Body Template')),
|
TextCodePanel('body_template', title=_('Body Template')),
|
||||||
ui_panels.CustomFieldsPanel(),
|
panels.CustomFieldsPanel(),
|
||||||
ui_panels.TagsPanel(),
|
panels.TagsPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -805,15 +810,15 @@ class EventRuleView(generic.ObjectView):
|
|||||||
queryset = EventRule.objects.all()
|
queryset = EventRule.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.EventRulePanel(),
|
panels.EventRulePanel(),
|
||||||
ui_panels.ObjectTypesPanel(),
|
panels.ObjectTypesPanel(),
|
||||||
ui_panels.EventRuleEventTypesPanel(),
|
panels.EventRuleEventTypesPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
JSONPanel('conditions', title=_l('Conditions')),
|
JSONPanel('conditions', title=_('Conditions')),
|
||||||
ui_panels.EventRuleActionPanel(),
|
panels.EventRuleActionPanel(),
|
||||||
ui_panels.CustomFieldsPanel(),
|
panels.CustomFieldsPanel(),
|
||||||
ui_panels.TagsPanel(),
|
panels.TagsPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -876,14 +881,14 @@ class TagView(generic.ObjectView):
|
|||||||
queryset = Tag.objects.all()
|
queryset = Tag.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.TagPanel(),
|
panels.TagPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.TagObjectTypesPanel(),
|
panels.TagObjectTypesPanel(),
|
||||||
ui_panels.TagItemTypesPanel(),
|
panels.TagItemTypesPanel(),
|
||||||
],
|
],
|
||||||
bottom_panels=[
|
bottom_panels=[
|
||||||
ContextTablePanel('taggeditem_table', title=_l('Tagged Objects')),
|
ContextTablePanel('taggeditem_table', title=_('Tagged Objects')),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -967,14 +972,14 @@ class ConfigContextProfileView(generic.ObjectView):
|
|||||||
queryset = ConfigContextProfile.objects.all()
|
queryset = ConfigContextProfile.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.ConfigContextProfilePanel(),
|
panels.ConfigContextProfilePanel(),
|
||||||
TemplatePanel('core/inc/datafile_panel.html'),
|
TemplatePanel('core/inc/datafile_panel.html'),
|
||||||
ui_panels.CustomFieldsPanel(),
|
panels.CustomFieldsPanel(),
|
||||||
ui_panels.TagsPanel(),
|
panels.TagsPanel(),
|
||||||
CommentsPanel(),
|
CommentsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.ConfigContextProfileSchemaPanel(),
|
panels.ConfigContextProfileSchemaPanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1041,9 +1046,9 @@ class ConfigContextView(generic.ObjectView):
|
|||||||
queryset = ConfigContext.objects.all()
|
queryset = ConfigContext.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.ConfigContextPanel(),
|
panels.ConfigContextPanel(),
|
||||||
TemplatePanel('core/inc/datafile_panel.html'),
|
TemplatePanel('core/inc/datafile_panel.html'),
|
||||||
ui_panels.ConfigContextAssignmentPanel(),
|
panels.ConfigContextAssignmentPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
TemplatePanel('extras/panels/configcontext_data.html'),
|
TemplatePanel('extras/panels/configcontext_data.html'),
|
||||||
@@ -1170,14 +1175,14 @@ class ConfigTemplateView(generic.ObjectView):
|
|||||||
queryset = ConfigTemplate.objects.all()
|
queryset = ConfigTemplate.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.ConfigTemplatePanel(),
|
panels.ConfigTemplatePanel(),
|
||||||
ui_panels.TagsPanel(),
|
panels.TagsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
JSONPanel('environment_params', title=_l('Environment Parameters')),
|
JSONPanel('environment_params', title=_('Environment Parameters')),
|
||||||
],
|
],
|
||||||
bottom_panels=[
|
bottom_panels=[
|
||||||
ui_panels.SyncCodePanel('template_code', title=_l('Template')),
|
TextCodePanel('template_code', title=_('Template')),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1299,13 +1304,13 @@ class ImageAttachmentView(generic.ObjectView):
|
|||||||
queryset = ImageAttachment.objects.all()
|
queryset = ImageAttachment.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.ImageAttachmentPanel(),
|
panels.ImageAttachmentPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
ui_panels.ImageAttachmentFilePanel(),
|
panels.ImageAttachmentFilePanel(),
|
||||||
],
|
],
|
||||||
bottom_panels=[
|
bottom_panels=[
|
||||||
ui_panels.ImageAttachmentImagePanel(),
|
panels.ImageAttachmentImagePanel(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1374,9 +1379,9 @@ class JournalEntryView(generic.ObjectView):
|
|||||||
queryset = JournalEntry.objects.all()
|
queryset = JournalEntry.objects.all()
|
||||||
layout = layout.SimpleLayout(
|
layout = layout.SimpleLayout(
|
||||||
left_panels=[
|
left_panels=[
|
||||||
ui_panels.JournalEntryPanel(),
|
panels.JournalEntryPanel(),
|
||||||
ui_panels.CustomFieldsPanel(),
|
panels.CustomFieldsPanel(),
|
||||||
ui_panels.TagsPanel(),
|
panels.TagsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
CommentsPanel(),
|
CommentsPanel(),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ __all__ = (
|
|||||||
'PluginContentPanel',
|
'PluginContentPanel',
|
||||||
'RelatedObjectsPanel',
|
'RelatedObjectsPanel',
|
||||||
'TemplatePanel',
|
'TemplatePanel',
|
||||||
|
'TextCodePanel',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -329,6 +330,23 @@ class TemplatePanel(Panel):
|
|||||||
return render_to_string(self.template_name, context.flatten())
|
return render_to_string(self.template_name, context.flatten())
|
||||||
|
|
||||||
|
|
||||||
|
class TextCodePanel(ObjectPanel):
|
||||||
|
"""
|
||||||
|
A panel displaying a text field as a pre-formatted code block.
|
||||||
|
"""
|
||||||
|
template_name = 'ui/panels/text_code.html'
|
||||||
|
|
||||||
|
def __init__(self, field_name, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.field_name = field_name
|
||||||
|
|
||||||
|
def get_context(self, context):
|
||||||
|
return {
|
||||||
|
**super().get_context(context),
|
||||||
|
'value': getattr(context.get('object'), self.field_name, None),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PluginContentPanel(Panel):
|
class PluginContentPanel(Panel):
|
||||||
"""
|
"""
|
||||||
A panel which displays embedded plugin content.
|
A panel which displays embedded plugin content.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends "ui/panels/_base.html" %}
|
{% extends "ui/panels/_base.html" %}
|
||||||
|
{% load helpers %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block panel_content %}
|
{% block panel_content %}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends "ui/panels/_base.html" %}
|
{% extends "ui/panels/_base.html" %}
|
||||||
|
{% load helpers %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block panel_content %}
|
{% block panel_content %}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
{% if value %}
|
{% if value %}
|
||||||
<pre>{{ value }}</pre>
|
<pre>{{ value }}</pre>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
{% include 'inc/sync_warning.html' %}
|
||||||
<span class="text-muted">{% trans "None" %}</span>
|
<span class="text-muted">{% trans "None" %}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user