Skip to content

Commit b24f8fb

Browse files
committed
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
1 parent a611ade commit b24f8fb

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

netbox/core/tables/plugins.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
import django_tables2 as tables
2-
from django.urls import reverse
3-
from django.utils.safestring import mark_safe
42
from django.utils.translation import gettext_lazy as _
53

64
from netbox.tables import BaseTable, columns
7-
from .template_code import PLUGIN_IS_INSTALLED
5+
from .template_code import PLUGIN_IS_INSTALLED, PLUGIN_NAME_TEMPLATE
86

97
__all__ = (
108
'CatalogPluginTable',
119
'PluginVersionTable',
1210
)
1311

1412

15-
PLUGIN_NAME_TEMPLATE = """
16-
<img class="plugin-icon" src="{{ record.icon_url }}">
17-
<a href="{% url 'core:plugin' record.config_name %}">{{ record.title_long }}</a>
18-
"""
19-
20-
2113
class PluginVersionTable(BaseTable):
2214
version = tables.Column(
2315
verbose_name=_('Version')
@@ -93,10 +85,4 @@ class Meta(BaseTable.Meta):
9385
)
9486
# List installed plugins first, then certified plugins, then
9587
# everything else (with each tranche ordered alphabetically)
96-
order_by = ('-is_installed', '-is_certified', 'name')
97-
98-
def render_title_long(self, value, record):
99-
if record.static:
100-
return value
101-
url = reverse('core:plugin', args=[record.config_name])
102-
return mark_safe(f"<a href='{url}'>{value}</a>")
88+
order_by = ('-is_installed', '-is_certified', 'title_long')

netbox/core/tables/template_code.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
{% endif %}
2828
"""
2929

30+
PLUGIN_NAME_TEMPLATE = """
31+
{% load static %}
32+
{% if record.icon_url %}
33+
<img class="plugin-icon" src="{{ record.icon_url }}">
34+
{% else %}
35+
<img class="plugin-icon" src="{% static 'plugin-default.svg' %}">
36+
{% endif %}
37+
<a href="{% url 'core:plugin' record.config_name %}">{{ record.title_long }}</a>
38+
"""
39+
3040
DATA_SOURCE_SYNC_BUTTON = """
3141
{% load helpers %}
3242
{% load i18n %}
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)