Some additional work done with CRUDKit. May start this over with a better design for CRUDKit.
This commit is contained in:
parent
f47fb6b505
commit
7738f1c9c2
5 changed files with 67 additions and 53 deletions
|
|
@ -56,7 +56,7 @@
|
|||
</li>
|
||||
{% else %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" hx-get="{{ _rows_url(model, page, per_page, sort, filters, fields_csv) }}" hx-target="#rows"
|
||||
<a class="page-link state-modifier" hx-get="{{ _rows_url(model, page, per_page, sort, filters, fields_csv) }}" hx-target="#rows"
|
||||
hx-swap="innerHTML" data-page="{{ page }}" {{ attrs|safe }}>
|
||||
{{ label }}
|
||||
</a>
|
||||
|
|
@ -103,18 +103,6 @@
|
|||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{# keep hidden pager-state in sync with one handler instead of inline click spam #}
|
||||
<script>
|
||||
document.currentScript?.previousElementSibling?.addEventListener?.('click', function (e) {
|
||||
const a = e.target.closest('a.page-link');
|
||||
if (!a) return;
|
||||
const targetPage = a.getAttribute('data-page');
|
||||
if (!targetPage) return;
|
||||
const inp = document.querySelector('#pager-state input[name=page]');
|
||||
if (inp) inp.value = targetPage;
|
||||
}, { capture: true });
|
||||
</script>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro form(schema, action, method="POST", obj_id=None, hx=False, csrf_token=None) -%}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ def _apply_dotted_ordering(stmt, Model, sort_tokens):
|
|||
rel = current_mapper.relationships.get(rel_name)
|
||||
if rel is None:
|
||||
# invalid sort key; skip quietly or raise
|
||||
# raise ValueError(f"Unknown relationship {current_mapper.class_.__name__}.{rel_name}")
|
||||
print(f"Unknown relationship {current_mapper.class_.__name__}.{rel_name}")
|
||||
entity = None
|
||||
break
|
||||
|
||||
|
|
@ -78,13 +78,20 @@ def _apply_dotted_ordering(stmt, Model, sort_tokens):
|
|||
continue
|
||||
|
||||
col_name = parts[-1]
|
||||
# Validate final column
|
||||
if col_name not in current_mapper.columns:
|
||||
# raise ValueError(f"Unknown column {current_mapper.class_.__name__}.{col_name}")
|
||||
continue
|
||||
# # Validate final column
|
||||
# if col_name not in current_mapper.columns:
|
||||
# print(f"Unknown column {current_mapper.class_.__name__}.{col_name}")
|
||||
# continue
|
||||
|
||||
col = getattr(entity, col_name) if entity is not Model else getattr(Model, col_name)
|
||||
stmt = stmt.order_by(col.desc() if direction == "desc" else col.asc())
|
||||
# col = getattr(entity, col_name) if entity is not Model else getattr(Model, col_name)
|
||||
|
||||
attr = getattr(entity, col_name, None)
|
||||
if attr is None:
|
||||
attr = getattr(current_mapper.class_, col_name, None)
|
||||
if attr is None:
|
||||
print(f"Unknown column {current_mapper.class_.__name__}.{col_name}")
|
||||
continue
|
||||
stmt = stmt.order_by(attr.desc() if direction == "desc" else attr.asc())
|
||||
|
||||
return stmt
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue