From 29ba9cb0cee6fd80bfdcae08cb96b532623ef044 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Sat, 6 Sep 2025 10:53:47 +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 | 16 ++++++++++++++++ netbox/core/views.py | 12 +++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/netbox/core/tables/data.py b/netbox/core/tables/data.py index 5c6ccebcf..226a48081 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_BUTTON __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_BUTTON, + ) class Meta(NetBoxTable.Meta): model = DataSource diff --git a/netbox/core/tables/template_code.py b/netbox/core/tables/template_code.py index 9fc652c4c..f49231a39 100644 --- a/netbox/core/tables/template_code.py +++ b/netbox/core/tables/template_code.py @@ -26,3 +26,19 @@ PLUGIN_IS_INSTALLED = """ {% endif %} """ + +DATA_SOURCE_SYNC_BUTTON = """ +{% 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..0959e1c12 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -33,7 +33,13 @@ from utilities.forms import ConfirmationForm from utilities.htmx import htmx_partial from utilities.json import ConfigJSONEncoder from utilities.query import count_related -from utilities.views import ContentTypePermissionRequiredMixin, GetRelatedModelsMixin, ViewTab, register_model_view +from utilities.views import ( + ContentTypePermissionRequiredMixin, + GetRelatedModelsMixin, + GetReturnURLMixin, + ViewTab, + register_model_view, +) from . import filtersets, forms, tables from .jobs import SyncDataSourceJob from .models import * @@ -66,7 +72,7 @@ class DataSourceView(GetRelatedModelsMixin, generic.ObjectView): @register_model_view(DataSource, 'sync') -class DataSourceSyncView(BaseObjectView): +class DataSourceSyncView(GetReturnURLMixin, BaseObjectView): queryset = DataSource.objects.all() def get_required_permission(self): @@ -85,7 +91,7 @@ class DataSourceSyncView(BaseObjectView): request, _("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource) ) - return redirect(datasource.get_absolute_url()) + return redirect(self.get_return_url(request, datasource)) @register_model_view(DataSource, 'add', detail=False)