Clean up action buttons

This commit is contained in:
Jeremy Stretch 2025-06-30 09:56:18 -04:00
parent 87e910421c
commit 12958e9653
13 changed files with 69 additions and 77 deletions

View File

@ -8,8 +8,6 @@ Blocks:
- content: Primary page content
- table_controls: Control elements for the child objects table
- bulk_controls: Bulk action buttons which appear beneath the child objects table
- bulk_edit_controls: Bulk edit buttons
- bulk_delete_controls: Bulk delete buttons
- bulk_extra_controls: Other bulk action buttons
- modals: Any pre-loaded modals

View File

@ -1,6 +1,3 @@
{% if url %}
{% load i18n %}
<a href="{{ url }}" type="button" class="btn btn-primary">
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}
<a href="{{ url }}" class="btn btn-primary" role="button">
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> {{ label }}
</a>

View File

@ -1,6 +1,3 @@
{% load i18n %}
{% if url %}
<button type="submit" name="_delete" {% formaction %}="{{ url }}" class="btn btn-red">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {% trans "Delete Selected" %}
</button>
{% endif %}
<button type="submit" name="_delete" {% formaction %}="{{ url }}" class="btn btn-red">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {{ label }}
</button>

View File

@ -1,6 +1,3 @@
{% load i18n %}
{% if url %}
<button type="submit" name="_disconnect" {% formaction %}="{{ url }}" class="btn btn-red">
<i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i> {{ label }}
</button>
{% endif %}
<button type="submit" name="_disconnect" {% formaction %}="{{ url }}" class="btn btn-red">
<i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i> {{ label }}
</button>

View File

@ -1,6 +1,3 @@
{% load i18n %}
{% if url %}
<button type="submit" name="_edit" {% formaction %}="{{ url }}" class="btn btn-yellow">
<i class="mdi mdi-pencil" aria-hidden="true"></i> {% trans "Edit Selected" %}
</button>
{% endif %}
<button type="submit" name="_edit" {% formaction %}="{{ url }}" class="btn btn-yellow">
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
</button>

View File

@ -1,6 +1,3 @@
{% load i18n %}
{% if url %}
<button type="submit" name="_rename" {% formaction %}="{{ url }}" class="btn btn-yellow">
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
</button>
{% endif %}
<button type="submit" name="_rename" {% formaction %}="{{ url }}" class="btn btn-yellow">
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
</button>

View File

@ -1,6 +1,3 @@
{% load i18n %}
{% if url %}
<button type="submit" name="_sync" {% formaction %}="{{ url }}" class="btn btn-primary">
<i class="mdi mdi-sync" aria-hidden="true"></i> {{ label }}
</button>
{% endif %}
<button type="submit" name="_sync" {% formaction %}="{{ url }}" class="btn btn-primary">
<i class="mdi mdi-sync" aria-hidden="true"></i> {{ label }}
</button>

View File

@ -1,12 +1,12 @@
{% load i18n %}
<a href="#"
hx-get="{{ url }}"
hx-target="#htmx-modal-content"
hx-swap="innerHTML"
hx-select="form"
class="btn btn-red"
role="button"
data-bs-toggle="modal"
data-bs-target="#htmx-modal"
>
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {% trans "Delete" %}
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {{ label }}
</a>

View File

@ -1,4 +1,3 @@
{% load i18n %}
<a href="{{ url }}" class="btn btn-yellow" role="button">
<i class="mdi mdi-pencil" aria-hidden="true"></i> {% trans "Edit" %}
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
</a>

View File

@ -1,7 +1,7 @@
{% load i18n %}
<div class="dropdown">
<button type="button" class="btn btn-purple dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="mdi mdi-download"></i> {% trans "Export" %}
<i class="mdi mdi-download" aria-hidden="true"></i> {{ label }}
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a id="export_current_view" class="dropdown-item" href="?{% if url_params %}{{ url_params }}&{% endif %}export=table">{% trans "Current View" %}</a></li>

View File

@ -1,6 +1,3 @@
{% load i18n %}
{% if url %}
<a href="{{ url }}" type="button" class="btn btn-cyan">
<i class="mdi mdi-upload"></i> {% trans "Import" %}
</a>
{% endif %}
<a href="{{ url }}" class="btn btn-cyan" role="button">
<i class="mdi mdi-upload" aria-hidden="true"></i> {{ label }}
</a>

View File

@ -1,7 +1,6 @@
{% load i18n %}
<form action="{{ url }}" method="post">
{% csrf_token %}
<button type="submit" class="btn btn-primary">
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
<i class="mdi mdi-sync" aria-hidden="true"></i> {{ label }}
</button>
</form>

View File

@ -3,6 +3,7 @@ from django.contrib.contenttypes.models import ContentType
from django.template import loader
from django.urls import NoReverseMatch, reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _
from core.models import ObjectType
from extras.models import Bookmark, ExportTemplate, Subscription
@ -37,10 +38,6 @@ def action_buttons(context, actions, obj, multi=False):
return mark_safe(''.join(buttons))
#
# Legacy object buttons
#
@register.inclusion_tag('buttons/bookmark.html', takes_context=True)
def bookmark_button(context, instance):
# Check if this user has already bookmarked the object
@ -90,26 +87,6 @@ def clone_button(instance):
}
@register.inclusion_tag('buttons/edit.html')
def edit_button(instance):
viewname = get_viewname(instance, 'edit')
url = reverse(viewname, kwargs={'pk': instance.pk})
return {
'url': url,
}
@register.inclusion_tag('buttons/delete.html')
def delete_button(instance):
viewname = get_viewname(instance, 'delete')
url = reverse(viewname, kwargs={'pk': instance.pk})
return {
'url': url,
}
@register.inclusion_tag('buttons/subscribe.html', takes_context=True)
def subscribe_button(context, instance):
# Skip for objects which don't support notifications
@ -145,12 +122,42 @@ def subscribe_button(context, instance):
}
#
# Legacy object buttons
#
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/edit.html')
def edit_button(instance):
viewname = get_viewname(instance, 'edit')
url = reverse(viewname, kwargs={'pk': instance.pk})
return {
'url': url,
'label': _('Edit'),
}
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/delete.html')
def delete_button(instance):
viewname = get_viewname(instance, 'delete')
url = reverse(viewname, kwargs={'pk': instance.pk})
return {
'url': url,
'label': _('Delete'),
}
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/sync.html')
def sync_button(instance):
viewname = get_viewname(instance, 'sync')
url = reverse(viewname, kwargs={'pk': instance.pk})
return {
'label': _('Sync'),
'url': url,
}
@ -159,6 +166,7 @@ def sync_button(instance):
# Legacy list buttons
#
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/add.html')
def add_button(model, action='add'):
try:
@ -168,9 +176,11 @@ def add_button(model, action='add'):
return {
'url': url,
'label': _('Add'),
}
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/import.html')
def import_button(model, action='bulk_import'):
try:
@ -180,9 +190,11 @@ def import_button(model, action='bulk_import'):
return {
'url': url,
'label': _('Import'),
}
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/export.html', takes_context=True)
def export_button(context, model):
object_type = ObjectType.objects.get_for_model(model)
@ -195,6 +207,7 @@ def export_button(context, model):
export_templates = ExportTemplate.objects.restrict(user, 'view').filter(object_types=object_type)
return {
'label': _('Export'),
'perms': context['perms'],
'object_type': object_type,
'url_params': context['request'].GET.urlencode() if context['request'].GET else '',
@ -203,6 +216,7 @@ def export_button(context, model):
}
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/bulk_edit.html', takes_context=True)
def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
try:
@ -213,11 +227,13 @@ def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
url = None
return {
'htmx_navigation': context.get('htmx_navigation'),
'label': _('Edit Selected'),
'url': url,
'htmx_navigation': context.get('htmx_navigation'),
}
# TODO: Remove in NetBox v4.6
@register.inclusion_tag('buttons/bulk_delete.html', takes_context=True)
def bulk_delete_button(context, model, action='bulk_delete', query_params=None):
try:
@ -228,6 +244,7 @@ def bulk_delete_button(context, model, action='bulk_delete', query_params=None):
url = None
return {
'htmx_navigation': context.get('htmx_navigation'),
'label': _('Delete Selected'),
'url': url,
'htmx_navigation': context.get('htmx_navigation'),
}