Update table config link when updating table

This commit is contained in:
Jeremy Stretch 2025-04-07 13:48:04 -04:00
parent 475dd7247b
commit 2f425fda34
3 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
from copy import deepcopy
from functools import cached_property
from urllib.parse import urlencode
import django_tables2 as tables
from django.conf import settings
@ -191,6 +192,14 @@ class BaseTable(tables.Table):
'ordering': self.order_by,
}
@property
def config_params(self):
return urlencode({
'object_type': ObjectType.objects.get_for_model(self.Meta.model).pk,
'table': self.name,
**self.configuration,
})
class NetBoxTable(BaseTable):
"""

View File

@ -19,6 +19,9 @@
{# Include the updated object count for display elsewhere on the page #}
<div hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>
{# Include the updated "save" link for the table configuration #}
<a class="dropdown-item" hx-swap-oob="outerHTML:#table_save_link" href="{% url 'extras:tableconfig_add' %}?{{ table.config_params }}&return_url={{ request.path }}" id="table_save_link">Save</a>
{# Update the bulk action buttons with new query parameters #}
{% if actions %}
<div class="bulk-action-buttons" hx-swap-oob="outerHTML:.bulk-action-buttons">

View File

@ -34,7 +34,7 @@
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url 'extras:tableconfig_add' %}?object_type={{ table.Meta.model|content_type_id }}&table={{ table.name }}&columns={{ table.configuration.columns }}&ordering={{ table.configuration.ordering }}">Save</a>
<a class="dropdown-item" href="{% url 'extras:tableconfig_add' %}?{{ table.config_params }}&return_url={{ request.path }}" id="table_save_link">Save</a>
{% if table_configs %}
<hr class="dropdown-divider">
{% for config in table_configs %}