Minor fix in CRUDKit build_href: We don't necessarily only want to link to CRUDKit blueprints.

This commit is contained in:
Yaro Kasear 2025-09-22 15:04:15 -05:00
parent d8e8790987
commit 15d0de44fe
4 changed files with 11 additions and 11 deletions

View file

@ -677,8 +677,9 @@ def _build_href(spec: Dict[str, Any], row: Dict[str, Any], obj) -> Optional[str]
if any(v is None for v in params.values()):
return None
try:
return url_for('crudkit.' + spec["endpoint"], **params)
return url_for(spec["endpoint"], **params)
except Exception as e:
print(f"Cannot create endpoint for {spec['endpoint']}: {str(e)}")
return None
def _humanize(field: str) -> str:
@ -725,7 +726,6 @@ def get_crudkit_template(env, name):
def render_field(field, value):
env = get_env()
print(field)
# 1) custom template field
field_type = field.get('type', 'text')

View file

@ -43,7 +43,7 @@ def init_listing_routes(app):
{"field": "model"},
{"field": "device_type.description", "label": "Device Type"},
{"field": "condition"},
{"field": "owner.label", "label": "Contact", "link": {"endpoint": "user.get_item", "params": {"id": "{owner.id}"}}},
{"field": "owner.label", "label": "Contact", "link": {"endpoint": "entry.entry", "params": {"id": "{owner.id}", "model": "user"}}},
{"field": "location.label", "label": "Room"},
]
elif model.lower() == 'user':
@ -60,7 +60,7 @@ def init_listing_routes(app):
{"field": "label", "label": "Full Name"},
{"field": "last_name"},
{"field": "first_name"},
{"field": "supervisor.label", "label": "Supervisor", "link": {"endpoint": "user.get_item", "params": {"id": "{supervisor.id}"}}},
{"field": "supervisor.label", "label": "Supervisor", "link": {"endpoint": "entry.entry", "params": {"id": "{supervisor.id}", "model": "user"}}},
{"field": "staff", "format": "yesno"},
{"field": "active", "format": "yesno"},
]
@ -80,8 +80,8 @@ def init_listing_routes(app):
"complete",
]}
columns = [
{"field": "work_item.label", "label": "Work Item", "link": {"endpoint": "inventory.get_item", "params": {"id": "{work_item.id}"}}},
{"field": "contact.label", "label": "Contact", "link": {"endpoint": "user.get_item", "params": {"id": "{contact.id}"}}},
{"field": "work_item.label", "label": "Work Item", "link": {"endpoint": "entry.entry", "params": {"id": "{work_item.id}", "model": "inventory"}}},
{"field": "contact.label", "label": "Contact", "link": {"endpoint": "entry.entry", "params": {"id": "{contact.id}", "model": "user"}}},
{"field": "start_time", "format": "datetime"},
{"field": "end_time", "format": "datetime"},
{"field": "complete", "format": "yesno"},

View file

@ -10,7 +10,7 @@
<tbody>
{% if rows %}
{% for row in rows %}
<tr onclick="location.href='{{ url_for( 'crudkit.' + kwargs['object_class'] + '.get_item', id=row.id) }}'" style="cursor: pointer;" class="{{ row.class or '' }}">
<tr onclick="location.href='{{ url_for( 'entry.entry', model=kwargs['object_class'], id=row.id) }}'" style="cursor: pointer;" class="{{ row.class or '' }}">
{% for cell in row.cells %}
{% if cell.href %}
<td class="{{ cell.class or '' }}"><a href="{{ cell.href }}" class="link-success link-underline link-underline-opacity-0 fw-semibold">{{ cell.text if cell.text is not none else '-' }}</a></td>

View file

@ -1,4 +1,4 @@
<img src="{{ url_for('static', filename=field['value_label']) }}" alt="{{ value }}"
{% if field['attrs'] %}{% for k,v in field['attrs'].items() %}
{{k}}{% if v is not sameas true %}="{{ v }}"{% endif %}
{% endfor %}{% endif %}>
{% if value %}
<img src="{{ url_for('static', filename=field['value_label']) }}" alt="{{ value }}" {% if field['attrs'] %}{% for k,v in
field['attrs'].items() %} {{k}}{% if v is not sameas true %}="{{ v }}" {% endif %} {% endfor %}{% endif %}>
{% endif %}