Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion netbox_custom_objects/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CustomObjectTypeTable(NetBoxTable):
verbose_name=_('Comments'),
)
tags = columns.TagColumn(
url_name='circuits:provider_list'
url_name='plugins:netbox_custom_objects:customobjecttype_list'
)
name = tables.Column(
verbose_name=_('Name'),
Expand Down Expand Up @@ -87,6 +87,36 @@ class Meta(NetBoxTable.Meta):
)


class CustomObjectTagColumn(columns.TagColumn):
"""
Custom TagColumn that generates tag filter URLs with the custom_object_type slug.
"""
template_code = """
{% load helpers %}
{% for tag in value.all %}
<a href="{% url 'plugins:netbox_custom_objects:customobject_list'
custom_object_type=record.custom_object_type.slug %}?tag={{ tag.slug }}">
<span {% if tag.description %}title="{{ tag.description }}"{% endif %}
class="badge"
style="color: {{ tag.color|fgcolor }}; background-color: #{{ tag.color }}">
{{ tag }}
</span>
</a>
{% empty %}
<span class="text-muted">&mdash;</span>
{% endfor %}
"""

def __init__(self):
# Override parent __init__ to use our custom template
tables.TemplateColumn.__init__(
self,
orderable=False,
template_code=self.template_code,
verbose_name=_('Tags'),
)


class CustomObjectActionsColumn(columns.ActionsColumn):

def render(self, record, table, **kwargs):
Expand Down Expand Up @@ -178,6 +208,7 @@ class CustomObjectTable(NetBoxTable):
actions = CustomObjectActionsColumn(
actions=('edit', 'delete'),
)
tags = CustomObjectTagColumn()

class Meta(NetBoxTable.Meta):
model = CustomObject
Expand All @@ -188,6 +219,7 @@ class Meta(NetBoxTable.Meta):
"custom_object_type",
"created",
"last_updated",
"tags",
)
default_columns = (
"pk",
Expand Down
2 changes: 2 additions & 0 deletions netbox_custom_objects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from netbox.views import generic
from netbox.views.generic.mixins import TableMixin
from utilities.forms import ConfirmationForm
from utilities.forms.fields import TagFilterField
from utilities.htmx import htmx_partial
from utilities.views import ConditionalLoginRequiredMixin, ViewTab, get_viewname, register_model_view

Expand Down Expand Up @@ -345,6 +346,7 @@ def get_filterset_form(self):
attrs = {
"model": model,
"__module__": "database.filterset_forms",
"tag": TagFilterField(model),
}

for field in self.custom_object_type.fields.all():
Expand Down