mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Include child regions, site groups
This commit is contained in:
parent
e543b305c3
commit
838200219f
@ -2,7 +2,9 @@ import django_tables2 as tables
|
||||
|
||||
from dcim.models import Region, Site, SiteGroup
|
||||
from tenancy.tables import TenantColumn
|
||||
from utilities.tables import BaseTable, ButtonsColumn, ChoiceFieldColumn, MPTTColumn, TagColumn, ToggleColumn
|
||||
from utilities.tables import (
|
||||
BaseTable, ButtonsColumn, ChoiceFieldColumn, LinkedCountColumn, MPTTColumn, TagColumn, ToggleColumn,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
'RegionTable',
|
||||
@ -20,7 +22,9 @@ class RegionTable(BaseTable):
|
||||
name = MPTTColumn(
|
||||
linkify=True
|
||||
)
|
||||
site_count = tables.Column(
|
||||
site_count = LinkedCountColumn(
|
||||
viewname='dcim:site_list',
|
||||
url_params={'region_id': 'pk'},
|
||||
verbose_name='Sites'
|
||||
)
|
||||
actions = ButtonsColumn(Region)
|
||||
@ -40,7 +44,9 @@ class SiteGroupTable(BaseTable):
|
||||
name = MPTTColumn(
|
||||
linkify=True
|
||||
)
|
||||
site_count = tables.Column(
|
||||
site_count = LinkedCountColumn(
|
||||
viewname='dcim:site_list',
|
||||
url_params={'group_id': 'pk'},
|
||||
verbose_name='Sites'
|
||||
)
|
||||
actions = ButtonsColumn(SiteGroup)
|
||||
|
@ -116,15 +116,26 @@ class RegionView(generic.ObjectView):
|
||||
queryset = Region.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
child_regions = Region.objects.add_related_count(
|
||||
Region.objects.all(),
|
||||
Site,
|
||||
'region',
|
||||
'site_count',
|
||||
cumulative=True
|
||||
).restrict(request.user, 'view').filter(
|
||||
parent__in=instance.get_descendants(include_self=True)
|
||||
)
|
||||
child_regions_table = tables.RegionTable(child_regions)
|
||||
|
||||
sites = Site.objects.restrict(request.user, 'view').filter(
|
||||
region=instance
|
||||
)
|
||||
|
||||
sites_table = tables.SiteTable(sites)
|
||||
sites_table.columns.hide('region')
|
||||
paginate_table(sites_table, request)
|
||||
|
||||
return {
|
||||
'child_regions_table': child_regions_table,
|
||||
'sites_table': sites_table,
|
||||
}
|
||||
|
||||
@ -190,15 +201,26 @@ class SiteGroupView(generic.ObjectView):
|
||||
queryset = SiteGroup.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
child_groups = SiteGroup.objects.add_related_count(
|
||||
SiteGroup.objects.all(),
|
||||
Site,
|
||||
'group',
|
||||
'site_count',
|
||||
cumulative=True
|
||||
).restrict(request.user, 'view').filter(
|
||||
parent__in=instance.get_descendants(include_self=True)
|
||||
)
|
||||
child_groups_table = tables.SiteGroupTable(child_groups)
|
||||
|
||||
sites = Site.objects.restrict(request.user, 'view').filter(
|
||||
group=instance
|
||||
)
|
||||
|
||||
sites_table = tables.SiteTable(sites)
|
||||
sites_table.columns.hide('group')
|
||||
paginate_table(sites_table, request)
|
||||
|
||||
return {
|
||||
'child_groups_table': child_groups_table,
|
||||
'sites_table': sites_table,
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,23 @@
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{% include 'inc/custom_fields_panel.html' %}
|
||||
{% plugin_left_page object %}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{% include 'inc/custom_fields_panel.html' %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<strong>Child Regions</strong>
|
||||
</div>
|
||||
{% include 'inc/table.html' with table=child_regions_table %}
|
||||
{% if perms.dcim.add_region %}
|
||||
<div class="panel-footer text-right noprint">
|
||||
<a href="{% url 'dcim:region_add' %}?parent={{ object.pk }}" class="btn btn-xs btn-primary">
|
||||
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add region
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% plugin_right_page object %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -44,10 +44,23 @@
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{% include 'inc/custom_fields_panel.html' %}
|
||||
{% plugin_left_page object %}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{% include 'inc/custom_fields_panel.html' %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<strong>Child Groups</strong>
|
||||
</div>
|
||||
{% include 'inc/table.html' with table=child_groups_table %}
|
||||
{% if perms.dcim.add_sitegroup %}
|
||||
<div class="panel-footer text-right noprint">
|
||||
<a href="{% url 'dcim:sitegroup_add' %}?parent={{ object.pk }}" class="btn btn-xs btn-primary">
|
||||
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add site group
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% plugin_right_page object %}
|
||||
</div>
|
||||
</div>
|
||||
@ -65,9 +78,9 @@
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% include 'inc/paginator.html' with paginator=sites_table.paginator page=sites_table.page %}
|
||||
{% plugin_full_width_page object %}
|
||||
</div>
|
||||
{% include 'inc/paginator.html' with paginator=sites_table.paginator page=sites_table.page %}
|
||||
{% plugin_full_width_page object %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user