Skip to content

Commit e9b1543

Browse files
committed
Add EmbeddedTablePanel
1 parent 4d5f8e9 commit e9b1543

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

netbox/dcim/views.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from django.contrib import messages
23
from django.contrib.contenttypes.models import ContentType
34
from django.core.paginator import EmptyPage, PageNotAnInteger
@@ -19,7 +20,8 @@
1920
from netbox.object_actions import *
2021
from netbox.ui import layout
2122
from netbox.ui.panels import (
22-
CommentsPanel, CustomFieldsPanel, ImageAttachmentsPanel, PluginContentPanel, RelatedObjectsPanel, TagsPanel,
23+
CommentsPanel, CustomFieldsPanel, EmbeddedTablePanel, ImageAttachmentsPanel, PluginContentPanel,
24+
RelatedObjectsPanel, TagsPanel,
2325
)
2426
from netbox.views import generic
2527
from utilities.forms import ConfirmationForm
@@ -485,6 +487,20 @@ class SiteView(GetRelatedModelsMixin, generic.ObjectView):
485487
),
486488
layout.Row(
487489
layout.Column(
490+
EmbeddedTablePanel(
491+
'dcim:location_list',
492+
url_params={'site_id': lambda x: x.pk},
493+
title=_('Locations')
494+
),
495+
EmbeddedTablePanel(
496+
'dcim:device_list',
497+
url_params={
498+
'site_id': lambda x: x.pk,
499+
'rack_id': settings.FILTERS_NULL_CHOICE_VALUE,
500+
'parent_bay_id': settings.FILTERS_NULL_CHOICE_VALUE,
501+
},
502+
title=_('Non-Racked Devices')
503+
),
488504
PluginContentPanel('full_width_page'),
489505
),
490506
),

netbox/netbox/ui/panels.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
from netbox.ui import attrs
77
from netbox.ui.attrs import Attr
8+
from utilities.querydict import dict_to_querydict
89
from utilities.string import title
910
from utilities.templatetags.plugins import _get_registered_content
1011

1112
__all__ = (
1213
'CommentsPanel',
1314
'CustomFieldsPanel',
15+
'EmbeddedTablePanel',
1416
'ImageAttachmentsPanel',
1517
'NestedGroupObjectPanel',
1618
'ObjectPanel',
@@ -146,6 +148,28 @@ def render(self, context):
146148
})
147149

148150

151+
class EmbeddedTablePanel(Panel):
152+
template_name = 'ui/panels/embedded_table.html'
153+
title = None
154+
155+
def __init__(self, viewname, url_params=None, **kwargs):
156+
super().__init__(**kwargs)
157+
self.viewname = viewname
158+
self.url_params = url_params or {}
159+
160+
def render(self, context):
161+
obj = context.get('object')
162+
url_params = {
163+
k: v(obj) if callable(v) else v for k, v in self.url_params.items()
164+
}
165+
# url_params['return_url'] = return_url or context['request'].path
166+
return render_to_string(self.template_name, {
167+
'title': self.title,
168+
'viewname': self.viewname,
169+
'url_params': dict_to_querydict(url_params),
170+
})
171+
172+
149173
class PluginContentPanel(Panel):
150174

151175
def __init__(self, method, **kwargs):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "ui/panels/_base.html" %}
2+
3+
{% block panel_content %}
4+
{% include 'builtins/htmx_table.html' %}
5+
{% endblock panel_content %}

0 commit comments

Comments
 (0)