mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
Rename bulk attr to multi
This commit is contained in:
parent
759ac64a1b
commit
0da5000a2c
@ -13,6 +13,6 @@ class BulkSync(ObjectAction):
|
|||||||
"""
|
"""
|
||||||
name = 'bulk_sync'
|
name = 'bulk_sync'
|
||||||
label = _('Sync Data')
|
label = _('Sync Data')
|
||||||
bulk = True
|
multi = True
|
||||||
permissions_required = {'sync'}
|
permissions_required = {'sync'}
|
||||||
template_name = 'buttons/bulk_sync.html'
|
template_name = 'buttons/bulk_sync.html'
|
||||||
|
@ -13,6 +13,6 @@ class BulkDisconnect(ObjectAction):
|
|||||||
"""
|
"""
|
||||||
name = 'bulk_disconnect'
|
name = 'bulk_disconnect'
|
||||||
label = _('Disconnect Selected')
|
label = _('Disconnect Selected')
|
||||||
bulk = True
|
multi = True
|
||||||
permissions_required = {'change'}
|
permissions_required = {'change'}
|
||||||
template_name = 'buttons/bulk_disconnect.html'
|
template_name = 'buttons/bulk_disconnect.html'
|
||||||
|
@ -18,9 +18,19 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class ObjectAction:
|
class ObjectAction:
|
||||||
|
"""
|
||||||
|
Base class for single- and multi-object operations.
|
||||||
|
|
||||||
|
Params:
|
||||||
|
name: The action name
|
||||||
|
label: Human-friendly label for the rendered button
|
||||||
|
multi: Set to True if this action is performed by selecting multiple objects (i.e. using a table)
|
||||||
|
permissions_required: The set of permissions a user must have to perform the action
|
||||||
|
url_kwargs: The set of URL keyword arguments to pass when resolving the view's URL
|
||||||
|
"""
|
||||||
name = ''
|
name = ''
|
||||||
label = None
|
label = None
|
||||||
bulk = False
|
multi = False
|
||||||
permissions_required = set()
|
permissions_required = set()
|
||||||
url_kwargs = []
|
url_kwargs = []
|
||||||
|
|
||||||
@ -117,7 +127,7 @@ class BulkEdit(ObjectAction):
|
|||||||
"""
|
"""
|
||||||
name = 'bulk_edit'
|
name = 'bulk_edit'
|
||||||
label = _('Edit Selected')
|
label = _('Edit Selected')
|
||||||
bulk = True
|
multi = True
|
||||||
permissions_required = {'change'}
|
permissions_required = {'change'}
|
||||||
template_name = 'buttons/bulk_edit.html'
|
template_name = 'buttons/bulk_edit.html'
|
||||||
|
|
||||||
@ -128,7 +138,7 @@ class BulkRename(ObjectAction):
|
|||||||
"""
|
"""
|
||||||
name = 'bulk_rename'
|
name = 'bulk_rename'
|
||||||
label = _('Rename Selected')
|
label = _('Rename Selected')
|
||||||
bulk = True
|
multi = True
|
||||||
permissions_required = {'change'}
|
permissions_required = {'change'}
|
||||||
template_name = 'buttons/bulk_rename.html'
|
template_name = 'buttons/bulk_rename.html'
|
||||||
|
|
||||||
@ -139,6 +149,6 @@ class BulkDelete(ObjectAction):
|
|||||||
"""
|
"""
|
||||||
name = 'bulk_delete'
|
name = 'bulk_delete'
|
||||||
label = _('Delete Selected')
|
label = _('Delete Selected')
|
||||||
bulk = True
|
multi = True
|
||||||
permissions_required = {'delete'}
|
permissions_required = {'delete'}
|
||||||
template_name = 'buttons/bulk_delete.html'
|
template_name = 'buttons/bulk_delete.html'
|
||||||
|
@ -152,13 +152,13 @@ class ObjectListView(BaseMultiObjectView, ActionsMixin, TableMixin):
|
|||||||
|
|
||||||
# Determine the available actions
|
# Determine the available actions
|
||||||
actions = self.get_permitted_actions(request.user)
|
actions = self.get_permitted_actions(request.user)
|
||||||
has_bulk_actions = any(action.bulk for action in actions)
|
has_table_actions = any(action.multi for action in actions)
|
||||||
|
|
||||||
if 'export' in request.GET:
|
if 'export' in request.GET:
|
||||||
|
|
||||||
# Export the current table view
|
# Export the current table view
|
||||||
if request.GET['export'] == 'table':
|
if request.GET['export'] == 'table':
|
||||||
table = self.get_table(self.queryset, request, has_bulk_actions)
|
table = self.get_table(self.queryset, request, has_table_actions)
|
||||||
columns = [name for name, _ in table.selected_columns]
|
columns = [name for name, _ in table.selected_columns]
|
||||||
return self.export_table(table, columns)
|
return self.export_table(table, columns)
|
||||||
|
|
||||||
@ -176,11 +176,11 @@ class ObjectListView(BaseMultiObjectView, ActionsMixin, TableMixin):
|
|||||||
|
|
||||||
# Fall back to default table/YAML export
|
# Fall back to default table/YAML export
|
||||||
else:
|
else:
|
||||||
table = self.get_table(self.queryset, request, has_bulk_actions)
|
table = self.get_table(self.queryset, request, has_table_actions)
|
||||||
return self.export_table(table)
|
return self.export_table(table)
|
||||||
|
|
||||||
# Render the objects table
|
# Render the objects table
|
||||||
table = self.get_table(self.queryset, request, has_bulk_actions)
|
table = self.get_table(self.queryset, request, has_table_actions)
|
||||||
|
|
||||||
# If this is an HTMX request, return only the rendered table HTML
|
# If this is an HTMX request, return only the rendered table HTML
|
||||||
if htmx_partial(request):
|
if htmx_partial(request):
|
||||||
|
@ -143,10 +143,10 @@ class ObjectChildrenView(ObjectView, ActionsMixin, TableMixin):
|
|||||||
|
|
||||||
# Determine the available actions
|
# Determine the available actions
|
||||||
actions = self.get_permitted_actions(request.user, model=self.child_model)
|
actions = self.get_permitted_actions(request.user, model=self.child_model)
|
||||||
has_bulk_actions = any(action.bulk for action in actions)
|
has_table_actions = any(action.multi for action in actions)
|
||||||
|
|
||||||
table_data = self.prep_table_data(request, child_objects, instance)
|
table_data = self.prep_table_data(request, child_objects, instance)
|
||||||
table = self.get_table(table_data, request, has_bulk_actions)
|
table = self.get_table(table_data, request, has_table_actions)
|
||||||
|
|
||||||
# If this is an HTMX request, return only the rendered table HTML
|
# If this is an HTMX request, return only the rendered table HTML
|
||||||
if htmx_partial(request):
|
if htmx_partial(request):
|
||||||
|
@ -37,7 +37,7 @@ Context:
|
|||||||
</div>
|
</div>
|
||||||
<div class="d-print-none mt-2">
|
<div class="d-print-none mt-2">
|
||||||
{% block bulk_controls %}
|
{% block bulk_controls %}
|
||||||
{% action_buttons actions model bulk=True %}
|
{% action_buttons actions model multi=True %}
|
||||||
{% block bulk_extra_controls %}{% endblock %}
|
{% block bulk_extra_controls %}{% endblock %}
|
||||||
{% endblock bulk_controls %}
|
{% endblock bulk_controls %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -84,7 +84,7 @@ Context:
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="bulk-action-buttons">
|
<div class="bulk-action-buttons">
|
||||||
{% action_buttons actions model bulk=True %}
|
{% action_buttons actions model multi=True %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -113,7 +113,7 @@ Context:
|
|||||||
{% block bulk_buttons %}
|
{% block bulk_buttons %}
|
||||||
<div class="bulk-action-buttons">
|
<div class="bulk-action-buttons">
|
||||||
{% block extra_bulk_buttons %}{% endblock %}
|
{% block extra_bulk_buttons %}{% endblock %}
|
||||||
{% action_buttons actions model bulk=True %}
|
{% action_buttons actions model multi=True %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,10 +29,10 @@ register = template.Library()
|
|||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def action_buttons(context, actions, obj, bulk=False):
|
def action_buttons(context, actions, obj, multi=False):
|
||||||
buttons = [
|
buttons = [
|
||||||
loader.render_to_string(action.template_name, action.get_context(context, obj))
|
loader.render_to_string(action.template_name, action.get_context(context, obj))
|
||||||
for action in actions if action.bulk == bulk
|
for action in actions if action.multi == multi
|
||||||
]
|
]
|
||||||
return mark_safe(''.join(buttons))
|
return mark_safe(''.join(buttons))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user