Skip to content

Commit 69d5106

Browse files
authored
Cleanup for class meta failing with Table(query=Query(...)) provided (#632)
1 parent e5c6c17 commit 69d5106

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

iommi/declarative/util.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,16 @@ def inject_args(args, kwargs, extra_args, pos_arg_names, merge_namespaces):
4444
else:
4545
new_args = args
4646

47-
for k, v in kwargs.items():
48-
new_value = new_kwargs.get(k, None)
49-
if merge_namespaces and isinstance(new_value, Namespace):
50-
if v is not None:
51-
new_kwargs[k] = Namespace(new_value, v)
52-
else:
53-
new_kwargs[k] = None
54-
else:
55-
new_kwargs[k] = v
47+
if merge_namespaces:
48+
new_kwargs = Namespace(new_kwargs, kwargs)
49+
else:
50+
new_kwargs.update(kwargs)
5651

5752
return new_args, new_kwargs
5853

5954

6055
def strip_prefix(s, *, prefix, strict=False):
6156
if s.startswith(prefix):
62-
return s[len(prefix):]
57+
return s[len(prefix) :]
6358
assert strict is False, f"String '{s}' does not start with prefix '{prefix}'"
6459
return s

iommi/table.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,13 @@ class TableAutoConfig(AutoConfig):
16361636

16371637
rows = Refinable()
16381638

1639+
def endpoint__tbody(table, **_):
1640+
return {
1641+
'html': table.container.__html__(
1642+
render=lambda fragment, context: fragment.render_text_or_children(context=context)
1643+
)
1644+
}
1645+
16391646

16401647
def endpoint__csv(table, **_):
16411648
from datetime import timezone
@@ -1780,8 +1787,6 @@ class Meta:
17801787
columns: Dict[str, Column] = RefinableMembers()
17811788

17821789
class Meta:
1783-
query__advanced__assets__query_form_toggle_script__template = "iommi/query/form_toggle_script.html"
1784-
assets__table_js_select_all__template = "iommi/table/js_select_all.html"
17851790
member_class = Column
17861791
form_class = Form
17871792
query_class = Query
@@ -1790,24 +1795,6 @@ class Meta:
17901795
cells_class = Cells
17911796
row_group_class = RowGroup
17921797

1793-
@staticmethod
1794-
def endpoints__tbody__func(table, **_):
1795-
return {
1796-
'html': table.container.__html__(
1797-
render=lambda fragment, context: fragment.render_text_or_children(context=context)
1798-
)
1799-
}
1800-
1801-
endpoints__csv__func = endpoint__csv
1802-
1803-
container__attrs = Namespace(
1804-
{
1805-
'data-endpoint': lambda table, **_: DISPATCH_PREFIX + table.endpoints.tbody.iommi_path,
1806-
'data-iommi-id': lambda table, **_: table.iommi_path,
1807-
}
1808-
)
1809-
1810-
query__form__attrs = {'data-iommi-id-of-table': lambda table, **_: table.iommi_path}
18111798
columns = EMPTY
18121799
parts = EMPTY
18131800
row__attrs__class = EMPTY
@@ -1875,6 +1862,17 @@ def post_bulk_edit(table, queryset, updates, **_):
18751862
# style
18761863
query__form__actions__submit__call_target=Action.button,
18771864
title=MISSING,
1865+
endpoints__tbody__func=endpoint__tbody,
1866+
endpoints__csv__func=endpoint__csv,
1867+
query__advanced__assets__query_form_toggle_script__template = "iommi/query/form_toggle_script.html",
1868+
query__form__attrs = {
1869+
'data-iommi-id-of-table': lambda table, **_: table.iommi_path,
1870+
},
1871+
assets__table_js_select_all__template = "iommi/table/js_select_all.html",
1872+
container__attrs ={
1873+
'data-endpoint': lambda table, **_: DISPATCH_PREFIX + table.endpoints.tbody.iommi_path,
1874+
'data-iommi-id': lambda table, **_: table.iommi_path,
1875+
},
18781876
)
18791877
def __init__(
18801878
self,

iommi/table__tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,3 +4561,20 @@ class TestTable(NoSortTable):
45614561
t = t.bind(request=req('get'))
45624562
verify_table_html(table=t, expected_html=expected_html)
45634563
verify_table_html(table=t, expected_html=expected_html)
4564+
4565+
4566+
def test_table_explicit_query():
4567+
Table(
4568+
rows=[],
4569+
query=Query(
4570+
filter=lambda rows, **_: rows,
4571+
),
4572+
).bind(request=req('get'))
4573+
4574+
4575+
def test_table_list_custom_query():
4576+
Table(
4577+
rows=[],
4578+
query__filter=lambda rows, **_: rows,
4579+
query__filters__foo=Filter(),
4580+
).bind(request=req('get'))

0 commit comments

Comments
 (0)