|
@@ -8,7 +8,7 @@ from core.models import ObjectType
|
|
|
from extras.models import Bookmark, ExportTemplate, Subscription
|
|
from extras.models import Bookmark, ExportTemplate, Subscription
|
|
|
from netbox.models.features import NotificationsMixin
|
|
from netbox.models.features import NotificationsMixin
|
|
|
from utilities.querydict import prepare_cloned_fields
|
|
from utilities.querydict import prepare_cloned_fields
|
|
|
-from utilities.views import get_viewname
|
|
|
|
|
|
|
+from utilities.views import get_action_url
|
|
|
|
|
|
|
|
__all__ = (
|
|
__all__ = (
|
|
|
'action_buttons',
|
|
'action_buttons',
|
|
@@ -110,9 +110,8 @@ def subscribe_button(context, instance):
|
|
|
@register.inclusion_tag('buttons/clone.html')
|
|
@register.inclusion_tag('buttons/clone.html')
|
|
|
def clone_button(instance):
|
|
def clone_button(instance):
|
|
|
# Resolve URL path
|
|
# Resolve URL path
|
|
|
- viewname = get_viewname(instance, 'add')
|
|
|
|
|
try:
|
|
try:
|
|
|
- url = reverse(viewname)
|
|
|
|
|
|
|
+ url = get_action_url(instance, action='add')
|
|
|
except NoReverseMatch:
|
|
except NoReverseMatch:
|
|
|
return {
|
|
return {
|
|
|
'url': None,
|
|
'url': None,
|
|
@@ -128,8 +127,7 @@ def clone_button(instance):
|
|
|
# TODO: Remove in NetBox v4.6
|
|
# TODO: Remove in NetBox v4.6
|
|
|
@register.inclusion_tag('buttons/edit.html')
|
|
@register.inclusion_tag('buttons/edit.html')
|
|
|
def edit_button(instance):
|
|
def edit_button(instance):
|
|
|
- viewname = get_viewname(instance, 'edit')
|
|
|
|
|
- url = reverse(viewname, kwargs={'pk': instance.pk})
|
|
|
|
|
|
|
+ url = get_action_url(instance, action='edit', kwargs={'pk': instance.pk})
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
'url': url,
|
|
'url': url,
|
|
@@ -140,8 +138,7 @@ def edit_button(instance):
|
|
|
# TODO: Remove in NetBox v4.6
|
|
# TODO: Remove in NetBox v4.6
|
|
|
@register.inclusion_tag('buttons/delete.html')
|
|
@register.inclusion_tag('buttons/delete.html')
|
|
|
def delete_button(instance):
|
|
def delete_button(instance):
|
|
|
- viewname = get_viewname(instance, 'delete')
|
|
|
|
|
- url = reverse(viewname, kwargs={'pk': instance.pk})
|
|
|
|
|
|
|
+ url = get_action_url(instance, action='delete', kwargs={'pk': instance.pk})
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
'url': url,
|
|
'url': url,
|
|
@@ -152,8 +149,7 @@ def delete_button(instance):
|
|
|
# TODO: Remove in NetBox v4.6
|
|
# TODO: Remove in NetBox v4.6
|
|
|
@register.inclusion_tag('buttons/sync.html')
|
|
@register.inclusion_tag('buttons/sync.html')
|
|
|
def sync_button(instance):
|
|
def sync_button(instance):
|
|
|
- viewname = get_viewname(instance, 'sync')
|
|
|
|
|
- url = reverse(viewname, kwargs={'pk': instance.pk})
|
|
|
|
|
|
|
+ url = get_action_url(instance, action='sync', kwargs={'pk': instance.pk})
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
'label': _('Sync'),
|
|
'label': _('Sync'),
|
|
@@ -169,7 +165,7 @@ def sync_button(instance):
|
|
|
@register.inclusion_tag('buttons/add.html')
|
|
@register.inclusion_tag('buttons/add.html')
|
|
|
def add_button(model, action='add'):
|
|
def add_button(model, action='add'):
|
|
|
try:
|
|
try:
|
|
|
- url = reverse(get_viewname(model, action))
|
|
|
|
|
|
|
+ url = get_action_url(model, action=action)
|
|
|
except NoReverseMatch:
|
|
except NoReverseMatch:
|
|
|
url = None
|
|
url = None
|
|
|
|
|
|
|
@@ -183,7 +179,7 @@ def add_button(model, action='add'):
|
|
|
@register.inclusion_tag('buttons/import.html')
|
|
@register.inclusion_tag('buttons/import.html')
|
|
|
def import_button(model, action='bulk_import'):
|
|
def import_button(model, action='bulk_import'):
|
|
|
try:
|
|
try:
|
|
|
- url = reverse(get_viewname(model, action))
|
|
|
|
|
|
|
+ url = get_action_url(model, action=action)
|
|
|
except NoReverseMatch:
|
|
except NoReverseMatch:
|
|
|
url = None
|
|
url = None
|
|
|
|
|
|
|
@@ -219,7 +215,7 @@ def export_button(context, model):
|
|
|
@register.inclusion_tag('buttons/bulk_edit.html', takes_context=True)
|
|
@register.inclusion_tag('buttons/bulk_edit.html', takes_context=True)
|
|
|
def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
|
|
def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
|
|
|
try:
|
|
try:
|
|
|
- url = reverse(get_viewname(model, action))
|
|
|
|
|
|
|
+ url = get_action_url(model, action=action)
|
|
|
if query_params:
|
|
if query_params:
|
|
|
url = f'{url}?{query_params.urlencode()}'
|
|
url = f'{url}?{query_params.urlencode()}'
|
|
|
except NoReverseMatch:
|
|
except NoReverseMatch:
|
|
@@ -236,7 +232,7 @@ def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
|
|
|
@register.inclusion_tag('buttons/bulk_delete.html', takes_context=True)
|
|
@register.inclusion_tag('buttons/bulk_delete.html', takes_context=True)
|
|
|
def bulk_delete_button(context, model, action='bulk_delete', query_params=None):
|
|
def bulk_delete_button(context, model, action='bulk_delete', query_params=None):
|
|
|
try:
|
|
try:
|
|
|
- url = reverse(get_viewname(model, action))
|
|
|
|
|
|
|
+ url = get_action_url(model, action=action)
|
|
|
if query_params:
|
|
if query_params:
|
|
|
url = f'{url}?{query_params.urlencode()}'
|
|
url = f'{url}?{query_params.urlencode()}'
|
|
|
except NoReverseMatch:
|
|
except NoReverseMatch:
|