mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
moved context to render method of ConfigTemplate
This commit is contained in:
parent
55c7c14fba
commit
69ffdbf8dd
@ -1,4 +1,3 @@
|
||||
from django.apps import apps
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
@ -24,7 +23,6 @@ from netbox.api.renderers import TextRenderer
|
||||
from netbox.api.viewsets import NetBoxModelViewSet
|
||||
from netbox.api.viewsets.mixins import SequentialBulkCreatesMixin
|
||||
from netbox.constants import NESTED_SERIALIZER_PREFIX
|
||||
from netbox.registry import registry
|
||||
from utilities.api import get_serializer_for_model
|
||||
from utilities.utils import count_related
|
||||
from virtualization.models import VirtualMachine
|
||||
@ -436,13 +434,6 @@ class DeviceViewSet(
|
||||
context_data.update(request.data)
|
||||
context_data.update({'device': device})
|
||||
|
||||
app_ns = registry['model_features']['custom_fields'].keys()
|
||||
for app in app_ns:
|
||||
context_data.setdefault(app, {})
|
||||
models = apps.get_app_config(app).get_models()
|
||||
for model in models:
|
||||
context_data[app][model.__name__] = model
|
||||
|
||||
return self.render_configtemplate(request, configtemplate, context_data)
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import traceback
|
||||
|
||||
from django.apps import apps
|
||||
from django.contrib import messages
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.paginator import EmptyPage, PageNotAnInteger
|
||||
@ -20,7 +19,6 @@ from circuits.models import Circuit, CircuitTermination
|
||||
from extras.views import ObjectConfigContextView
|
||||
from ipam.models import ASN, IPAddress, Prefix, VLAN, VLANGroup
|
||||
from ipam.tables import InterfaceVLANTable
|
||||
from netbox.registry import registry
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.forms import ConfirmationForm
|
||||
@ -2082,13 +2080,6 @@ class DeviceRenderConfigView(generic.ObjectView):
|
||||
context_data = instance.get_config_context()
|
||||
context_data.update({'device': instance})
|
||||
|
||||
app_ns = registry['model_features']['custom_fields'].keys()
|
||||
for app in app_ns:
|
||||
context_data.setdefault(app, {})
|
||||
models = apps.get_app_config(app).get_models()
|
||||
for model in models:
|
||||
context_data[app][model.__name__] = model
|
||||
|
||||
# Render the config template
|
||||
rendered_config = None
|
||||
if config_template := instance.get_config_template():
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.core.validators import ValidationError
|
||||
from django.db import models
|
||||
@ -8,6 +9,7 @@ from jinja2.sandbox import SandboxedEnvironment
|
||||
|
||||
from extras.querysets import ConfigContextQuerySet
|
||||
from netbox.config import get_config
|
||||
from netbox.registry import registry
|
||||
from netbox.models import ChangeLoggedModel
|
||||
from netbox.models.features import CloningMixin, ExportTemplatesMixin, SyncedDataMixin, TagsMixin
|
||||
from utilities.jinja2 import ConfigTemplateLoader
|
||||
@ -257,6 +259,15 @@ class ConfigTemplate(SyncedDataMixin, ExportTemplatesMixin, TagsMixin, ChangeLog
|
||||
"""
|
||||
context = context or {}
|
||||
|
||||
app_ns = registry['model_features']['custom_fields'].keys()
|
||||
for app in app_ns:
|
||||
context.setdefault(app, {})
|
||||
models = apps.get_app_config(app).get_models()
|
||||
for model in models:
|
||||
context[app][model.__name__] = model
|
||||
|
||||
print(context)
|
||||
|
||||
# Initialize the Jinja2 environment and instantiate the Template
|
||||
environment = self._get_environment()
|
||||
if self.data_file:
|
||||
|
Loading…
Reference in New Issue
Block a user