mirror of
https://github.com/netbox-community/netbox.git
synced 2025-09-06 14:23:36 -06:00
Merge 29ba9cb0ce
into c9f823167c
This commit is contained in:
commit
f5fba66a8a
@ -4,6 +4,7 @@ import django_tables2 as tables
|
|||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.tables import NetBoxTable, columns
|
from netbox.tables import NetBoxTable, columns
|
||||||
from .columns import BackendTypeColumn
|
from .columns import BackendTypeColumn
|
||||||
|
from .template_code import DATA_SOURCE_SYNC_BUTTON
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'DataFileTable',
|
'DataFileTable',
|
||||||
@ -37,6 +38,9 @@ class DataSourceTable(NetBoxTable):
|
|||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='core:datasource_list',
|
url_name='core:datasource_list',
|
||||||
)
|
)
|
||||||
|
actions = columns.ActionsColumn(
|
||||||
|
extra_buttons=DATA_SOURCE_SYNC_BUTTON,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = DataSource
|
model = DataSource
|
||||||
|
@ -26,3 +26,19 @@ PLUGIN_IS_INSTALLED = """
|
|||||||
<span class="text-muted">—</span>
|
<span class="text-muted">—</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DATA_SOURCE_SYNC_BUTTON = """
|
||||||
|
{% load helpers %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% if perms.core.sync_datasource %}
|
||||||
|
{% if record.ready_for_sync %}
|
||||||
|
<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">
|
||||||
|
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
|
||||||
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<button class="btn btn-primary btn-sm" disabled>
|
||||||
|
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
@ -33,7 +33,13 @@ from utilities.forms import ConfirmationForm
|
|||||||
from utilities.htmx import htmx_partial
|
from utilities.htmx import htmx_partial
|
||||||
from utilities.json import ConfigJSONEncoder
|
from utilities.json import ConfigJSONEncoder
|
||||||
from utilities.query import count_related
|
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 . import filtersets, forms, tables
|
||||||
from .jobs import SyncDataSourceJob
|
from .jobs import SyncDataSourceJob
|
||||||
from .models import *
|
from .models import *
|
||||||
@ -66,7 +72,7 @@ class DataSourceView(GetRelatedModelsMixin, generic.ObjectView):
|
|||||||
|
|
||||||
|
|
||||||
@register_model_view(DataSource, 'sync')
|
@register_model_view(DataSource, 'sync')
|
||||||
class DataSourceSyncView(BaseObjectView):
|
class DataSourceSyncView(GetReturnURLMixin, BaseObjectView):
|
||||||
queryset = DataSource.objects.all()
|
queryset = DataSource.objects.all()
|
||||||
|
|
||||||
def get_required_permission(self):
|
def get_required_permission(self):
|
||||||
@ -85,7 +91,7 @@ class DataSourceSyncView(BaseObjectView):
|
|||||||
request,
|
request,
|
||||||
_("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource)
|
_("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)
|
@register_model_view(DataSource, 'add', detail=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user