Skip to content

Commit

Permalink
Fix bulk form render when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jlubcke authored and boxed committed Apr 16, 2024
1 parent 1cdf9ee commit 109101f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions iommi/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2168,8 +2168,10 @@ def _bind_bulk_form(self):
return

bind_member(self, name='bulk')
if self.bulk is not None:
if self.should_render_form_tag():
self._bound_members.bulk = self.bulk
else:
self.bulk = None

# property for jinja2 compatibility
@property
Expand Down Expand Up @@ -2402,7 +2404,7 @@ def bulk_queryset(self, prefix='pk_'):
return self.selection(prefix=prefix).filter(**self.bulk_filter).exclude(**self.bulk_exclude)

def should_render_form_tag(self):
return bool(self.bulk)
return bool(self.bulk and self.bulk.actions)

@dispatch(
render=render_template,
Expand Down
9 changes: 9 additions & 0 deletions iommi/table__tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,15 @@ def test_bulk_fields_empty_by_default():
assert t.bulk.fields.number.initial == 11


@pytest.mark.django_db
def test_bulk_form_when_not_needed():
t = Table(
auto__model=DefaultsInForms,
bulk__actions__banana__include=False,
).bind()
assert t.bulk is None


@pytest.mark.django_db
def test_invalid_syntax_query():
class TestTable(Table):
Expand Down

0 comments on commit 109101f

Please sign in to comment.