Skip to content

Commit ff963f1

Browse files
Johan Lübckeboxed
authored andcommitted
Move the data-endpoint and data-iommi-id html attributes to the table container
This is to avoid them being over-written by any empty_message provided resulting in no table tag being rendered
1 parent dd71535 commit ff963f1

File tree

6 files changed

+81
-77
lines changed

6 files changed

+81
-77
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ repos:
1111
- id: black
1212
language_version: python3.8
1313
- repo: https://github.com/pycqa/flake8.git
14-
rev: 3.9.2
14+
rev: 7.0.0
1515
hooks:
1616
- id: flake8

iommi/edit_table__tests.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def test_edit_table_rendering():
5858
# language=html
5959
expected_html="""
6060
<form enctype="multipart/form-data" method="post">
61-
<div class="iommi-table-container">
61+
<div class="iommi-table-container" data-endpoint="/endpoints/tbody" data-iommi-id="">
6262
<div class="iommi-table-plus-paginator">
6363
<table class="table" data-add-template=\'&lt;tr data-pk="#sentinel#"&gt;&lt;td&gt;&lt;input id="id_editable_thing__#sentinel#" name="editable_thing/#sentinel#" type="text" value=""&gt;&lt;/td&gt;
64-
&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;\' data-endpoint="/endpoints/tbody" data-iommi-id="" data-next-virtual-pk="-1">
64+
&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;\' data-next-virtual-pk="-1">
6565
<thead>
6666
<tr>
6767
<th class="first_column subheader"> Editable thing </th>
@@ -336,12 +336,12 @@ def test_edit_table_post_create_hardcoded():
336336
'POST',
337337
**{
338338
# edit
339-
f'columns/a/{foo.pk}': f'2',
339+
f'columns/a/{foo.pk}': '2',
340340
f'columns/b/{foo.pk}': 'hardcoded column should be ignored',
341341
# create
342-
'columns/a/-2': f'4',
342+
'columns/a/-2': '4',
343343
'columns/b/-2': 'hardcoded column should be ignored',
344-
'columns/a/-1': f'3',
344+
'columns/a/-1': '3',
345345
'columns/b/-1': 'hardcoded column should be ignored',
346346
'-actions/submit': '',
347347
},
@@ -351,10 +351,7 @@ def test_edit_table_post_create_hardcoded():
351351
response = edit_table.render_to_response()
352352
assert response.status_code == 302
353353

354-
assert [
355-
dict(a=x.a, b=x.b)
356-
for x in TFoo.objects.all().order_by('pk')
357-
] == [
354+
assert [dict(a=x.a, b=x.b) for x in TFoo.objects.all().order_by('pk')] == [
358355
dict(a=2, b='asd'),
359356
dict(a=3, b='hardcoded'),
360357
dict(a=4, b='hardcoded'),

iommi/static/js/iommi.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ class IommiBase {
179179
}
180180

181181
async updateTableContainer(container, params, extra){
182-
const tbodyPath = container.querySelector('[data-endpoint]').getAttribute(
183-
'data-endpoint'
184-
);
182+
const tbodyPath = container.getAttribute('data-endpoint');
185183

186184
this.callDeprecatedSpinner(true, container); // deprecated, use event "iommi.loading.start" instead
187185

iommi/style__tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ def test_get_style_error():
324324

325325

326326
class MyRefinableObject(RefinableObject):
327-
328327
foo: 'MyRefinableObject' = Refinable()
329328
bar: int = Refinable()
330329
baz: int = Refinable()
@@ -789,7 +788,7 @@ class TestTable(Table):
789788
table=TestTable(rows=(x for x in [Struct(foo=True)]), iommi_style='base', attrs__class__table=True),
790789
# language=html
791790
expected_html="""
792-
<table class="table" data-endpoint="/endpoints/tbody" data-iommi-id="">
791+
<table class="table">
793792
<thead>
794793
<tr>
795794
<th class="first_column iommi_sort_header subheader"> <a href="?order=foo"> Foo </a> </th>
@@ -808,7 +807,7 @@ class TestTable(Table):
808807
table=TestTable(rows=(x for x in [Struct(foo=True)]), iommi_style='bulma', attrs__class__table=True),
809808
# language=html
810809
expected_html="""
811-
<table class="is-fullwidth is-hoverable table" data-endpoint="/endpoints/tbody" data-iommi-id="">
810+
<table class="is-fullwidth is-hoverable table">
812811
<thead>
813812
<tr>
814813
<th class="first_column iommi_sort_header subheader"> <a href="?order=foo"> Foo </a> </th>
@@ -827,7 +826,7 @@ class TestTable(Table):
827826
table=TestTable(rows=(x for x in [Struct(foo=True)]), iommi_style='bootstrap5', attrs__class__table=True),
828827
# language=html
829828
expected_html="""
830-
<table class="table table-sm" data-endpoint="/endpoints/tbody" data-iommi-id="">
829+
<table class="table table-sm">
831830
<thead>
832831
<tr>
833832
<th class="first_column iommi_sort_header subheader text-nowrap"> <a href="?order=foo"> Foo </a> </th>

iommi/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ class Meta:
17131713
}
17141714
endpoints__csv__func = endpoint__csv
17151715

1716-
attrs = Namespace(
1716+
container__attrs = Namespace(
17171717
{
17181718
'data-endpoint': lambda table, **_: DISPATCH_PREFIX + table.endpoints.tbody.iommi_path,
17191719
'data-iommi-id': lambda table, **_: table.iommi_path,

0 commit comments

Comments
 (0)