From b24f8fb340ecb6974157e46dd039c1666fc669c0 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Mon, 8 Sep 2025 18:44:00 +0200 Subject: [PATCH] feat(core): Update plugin title rendering with default icon Replaces inline plugin title HTML with a reusable template in `template_code.py`. Adds a default icon for plugins without custom icons and updates the table logic to use this template. Removes redundant logic from the `render_title_long` method to improve maintainability. Changes the `order_by` field in `plugins.py` from `name` to `title_long`. Fixes #20264 --- netbox/core/tables/plugins.py | 18 ++---------------- netbox/core/tables/template_code.py | 10 ++++++++++ netbox/project-static/img/plugin-default.svg | 1 + 3 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 netbox/project-static/img/plugin-default.svg diff --git a/netbox/core/tables/plugins.py b/netbox/core/tables/plugins.py index e1b80af42..8903227fe 100644 --- a/netbox/core/tables/plugins.py +++ b/netbox/core/tables/plugins.py @@ -1,10 +1,8 @@ import django_tables2 as tables -from django.urls import reverse -from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ from netbox.tables import BaseTable, columns -from .template_code import PLUGIN_IS_INSTALLED +from .template_code import PLUGIN_IS_INSTALLED, PLUGIN_NAME_TEMPLATE __all__ = ( 'CatalogPluginTable', @@ -12,12 +10,6 @@ __all__ = ( ) -PLUGIN_NAME_TEMPLATE = """ - -{{ record.title_long }} -""" - - class PluginVersionTable(BaseTable): version = tables.Column( verbose_name=_('Version') @@ -93,10 +85,4 @@ class CatalogPluginTable(BaseTable): ) # List installed plugins first, then certified plugins, then # everything else (with each tranche ordered alphabetically) - order_by = ('-is_installed', '-is_certified', 'name') - - def render_title_long(self, value, record): - if record.static: - return value - url = reverse('core:plugin', args=[record.config_name]) - return mark_safe(f"{value}") + order_by = ('-is_installed', '-is_certified', 'title_long') diff --git a/netbox/core/tables/template_code.py b/netbox/core/tables/template_code.py index f49231a39..dc604876f 100644 --- a/netbox/core/tables/template_code.py +++ b/netbox/core/tables/template_code.py @@ -27,6 +27,16 @@ PLUGIN_IS_INSTALLED = """ {% endif %} """ +PLUGIN_NAME_TEMPLATE = """ +{% load static %} +{% if record.icon_url %} + +{% else %} + +{% endif %} +{{ record.title_long }} +""" + DATA_SOURCE_SYNC_BUTTON = """ {% load helpers %} {% load i18n %} diff --git a/netbox/project-static/img/plugin-default.svg b/netbox/project-static/img/plugin-default.svg new file mode 100644 index 000000000..1493e72d4 --- /dev/null +++ b/netbox/project-static/img/plugin-default.svg @@ -0,0 +1 @@ + \ No newline at end of file