From 3b4894cfae4b7128f940ca51c6ee7e3ec18fc3f3 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Fri, 5 Sep 2025 15:12:38 +0200 Subject: [PATCH] feat(core): Add Sync button for DataSource actions Introduces a sync button in the DataSource table for improved user interaction. Enables users to trigger sync actions directly from the table, with context-sensitive availability based on permissions and record status. Closes #19547 --- netbox/core/tables/data.py | 4 ++++ netbox/core/tables/template_code.py | 18 ++++++++++++++++++ netbox/core/views.py | 2 ++ 3 files changed, 24 insertions(+) diff --git a/netbox/core/tables/data.py b/netbox/core/tables/data.py index 5c6ccebcf..50b7821fe 100644 --- a/netbox/core/tables/data.py +++ b/netbox/core/tables/data.py @@ -4,6 +4,7 @@ import django_tables2 as tables from core.models import * from netbox.tables import NetBoxTable, columns from .columns import BackendTypeColumn +from .template_code import DATA_SOURCE_SYNC_BUTTONS __all__ = ( 'DataFileTable', @@ -37,6 +38,9 @@ class DataSourceTable(NetBoxTable): tags = columns.TagColumn( url_name='core:datasource_list', ) + actions = columns.ActionsColumn( + extra_buttons=DATA_SOURCE_SYNC_BUTTONS, + ) class Meta(NetBoxTable.Meta): model = DataSource diff --git a/netbox/core/tables/template_code.py b/netbox/core/tables/template_code.py index 9fc652c4c..e9c2aabd1 100644 --- a/netbox/core/tables/template_code.py +++ b/netbox/core/tables/template_code.py @@ -26,3 +26,21 @@ PLUGIN_IS_INSTALLED = """ {% endif %} """ + +DATA_SOURCE_SYNC_BUTTONS = """ +{% load helpers %} +{% load i18n %} + {% if perms.core.sync_datasource %} + {% if record.ready_for_sync %} + + {% else %} + + + + {% endif %} + {% endif %} +""" diff --git a/netbox/core/views.py b/netbox/core/views.py index b18937308..947e03681 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -85,6 +85,8 @@ class DataSourceSyncView(BaseObjectView): request, _("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource) ) + if return_url := request.POST.get('return_url'): + return redirect(return_url) return redirect(datasource.get_absolute_url())