Rename bulk attr to multi

This commit is contained in:
Jeremy Stretch 2025-06-30 09:10:28 -04:00
parent 759ac64a1b
commit 0da5000a2c
8 changed files with 27 additions and 17 deletions

View File

@ -13,6 +13,6 @@ class BulkSync(ObjectAction):
"""
name = 'bulk_sync'
label = _('Sync Data')
bulk = True
multi = True
permissions_required = {'sync'}
template_name = 'buttons/bulk_sync.html'

View File

@ -13,6 +13,6 @@ class BulkDisconnect(ObjectAction):
"""
name = 'bulk_disconnect'
label = _('Disconnect Selected')
bulk = True
multi = True
permissions_required = {'change'}
template_name = 'buttons/bulk_disconnect.html'

View File

@ -18,9 +18,19 @@ __all__ = (
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 = ''
label = None
bulk = False
multi = False
permissions_required = set()
url_kwargs = []
@ -117,7 +127,7 @@ class BulkEdit(ObjectAction):
"""
name = 'bulk_edit'
label = _('Edit Selected')
bulk = True
multi = True
permissions_required = {'change'}
template_name = 'buttons/bulk_edit.html'
@ -128,7 +138,7 @@ class BulkRename(ObjectAction):
"""
name = 'bulk_rename'
label = _('Rename Selected')
bulk = True
multi = True
permissions_required = {'change'}
template_name = 'buttons/bulk_rename.html'
@ -139,6 +149,6 @@ class BulkDelete(ObjectAction):
"""
name = 'bulk_delete'
label = _('Delete Selected')
bulk = True
multi = True
permissions_required = {'delete'}
template_name = 'buttons/bulk_delete.html'

View File

@ -152,13 +152,13 @@ class ObjectListView(BaseMultiObjectView, ActionsMixin, TableMixin):
# Determine the available actions
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:
# Export the current table view
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]
return self.export_table(table, columns)
@ -176,11 +176,11 @@ class ObjectListView(BaseMultiObjectView, ActionsMixin, TableMixin):
# Fall back to default table/YAML export
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)
# 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 htmx_partial(request):

View File

@ -143,10 +143,10 @@ class ObjectChildrenView(ObjectView, ActionsMixin, TableMixin):
# Determine the available actions
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 = 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 htmx_partial(request):

View File

@ -37,7 +37,7 @@ Context:
</div>
<div class="d-print-none mt-2">
{% block bulk_controls %}
{% action_buttons actions model bulk=True %}
{% action_buttons actions model multi=True %}
{% block bulk_extra_controls %}{% endblock %}
{% endblock bulk_controls %}
</div>

View File

@ -84,7 +84,7 @@ Context:
</label>
</div>
<div class="bulk-action-buttons">
{% action_buttons actions model bulk=True %}
{% action_buttons actions model multi=True %}
</div>
</div>
</div>
@ -113,7 +113,7 @@ Context:
{% block bulk_buttons %}
<div class="bulk-action-buttons">
{% block extra_bulk_buttons %}{% endblock %}
{% action_buttons actions model bulk=True %}
{% action_buttons actions model multi=True %}
</div>
{% endblock %}
</div>

View File

@ -29,10 +29,10 @@ register = template.Library()
@register.simple_tag(takes_context=True)
def action_buttons(context, actions, obj, bulk=False):
def action_buttons(context, actions, obj, multi=False):
buttons = [
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))