Skip to content

Commit 3b4894c

Browse files
committed
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
1 parent 545773e commit 3b4894c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

netbox/core/tables/data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from core.models import *
55
from netbox.tables import NetBoxTable, columns
66
from .columns import BackendTypeColumn
7+
from .template_code import DATA_SOURCE_SYNC_BUTTONS
78

89
__all__ = (
910
'DataFileTable',
@@ -37,6 +38,9 @@ class DataSourceTable(NetBoxTable):
3738
tags = columns.TagColumn(
3839
url_name='core:datasource_list',
3940
)
41+
actions = columns.ActionsColumn(
42+
extra_buttons=DATA_SOURCE_SYNC_BUTTONS,
43+
)
4044

4145
class Meta(NetBoxTable.Meta):
4246
model = DataSource

netbox/core/tables/template_code.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,21 @@
2626
<span class="text-muted">&mdash;</span>
2727
{% endif %}
2828
"""
29+
30+
DATA_SOURCE_SYNC_BUTTONS = """
31+
{% load helpers %}
32+
{% load i18n %}
33+
{% if perms.core.sync_datasource %}
34+
{% if record.ready_for_sync %}
35+
<button type="submit" class="btn btn-primary btn-sm" formaction="{% url 'core:datasource_sync' pk=record.pk %}?return_url={{ request.get_full_path|urlencode }}" formmethod="post">
36+
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
37+
</button>
38+
{% else %}
39+
<span class="inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-delay="100" data-bs-placement="bottom">
40+
<button class="btn btn-primary" disabled>
41+
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
42+
</button>
43+
</span>
44+
{% endif %}
45+
{% endif %}
46+
"""

netbox/core/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def post(self, request, pk):
8585
request,
8686
_("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource)
8787
)
88+
if return_url := request.POST.get('return_url'):
89+
return redirect(return_url)
8890
return redirect(datasource.get_absolute_url())
8991

9092

0 commit comments

Comments
 (0)