Skip to content

Commit 099f3b2

Browse files
pheusjeremystretch
authored andcommitted
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 1b83d32 commit 099f3b2

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
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_BUTTON
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_BUTTON,
43+
)
4044

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

netbox/core/tables/template_code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@
2626
<span class="text-muted">&mdash;</span>
2727
{% endif %}
2828
"""
29+
30+
DATA_SOURCE_SYNC_BUTTON = """
31+
{% load helpers %}
32+
{% load i18n %}
33+
{% if perms.core.sync_datasource %}
34+
{% if record.ready_for_sync %}
35+
<button class="btn btn-primary btn-sm" type="submit" 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+
<button class="btn btn-primary btn-sm" disabled>
40+
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
41+
</button>
42+
{% endif %}
43+
{% endif %}
44+
"""

netbox/core/views.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
from utilities.htmx import htmx_partial
3434
from utilities.json import ConfigJSONEncoder
3535
from utilities.query import count_related
36-
from utilities.views import ContentTypePermissionRequiredMixin, GetRelatedModelsMixin, ViewTab, register_model_view
36+
from utilities.views import (
37+
ContentTypePermissionRequiredMixin,
38+
GetRelatedModelsMixin,
39+
GetReturnURLMixin,
40+
ViewTab,
41+
register_model_view,
42+
)
3743
from . import filtersets, forms, tables
3844
from .jobs import SyncDataSourceJob
3945
from .models import *
@@ -66,7 +72,7 @@ def get_extra_context(self, request, instance):
6672

6773

6874
@register_model_view(DataSource, 'sync')
69-
class DataSourceSyncView(BaseObjectView):
75+
class DataSourceSyncView(GetReturnURLMixin, BaseObjectView):
7076
queryset = DataSource.objects.all()
7177

7278
def get_required_permission(self):
@@ -85,7 +91,7 @@ def post(self, request, pk):
8591
request,
8692
_("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource)
8793
)
88-
return redirect(datasource.get_absolute_url())
94+
return redirect(self.get_return_url(request, datasource))
8995

9096

9197
@register_model_view(DataSource, 'add', detail=False)

0 commit comments

Comments
 (0)