Skip to content

Commit bb38502

Browse files
committed
refactor(core): Simplify plugin table rendering logic
Extracts `PLUGIN_NAME_TEMPLATE` into `template_code.py` for better reusability across the codebase. 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 47e4947 commit bb38502

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@
2626
<span class="text-muted">&mdash;</span>
2727
{% endif %}
2828
"""
29+
30+
PLUGIN_NAME_TEMPLATE = """
31+
<img class="plugin-icon" src="{{ record.icon_url }}">
32+
<a href="{% url 'core:plugin' record.config_name %}">{{ record.title_long }}</a>
33+
"""

0 commit comments

Comments
 (0)