mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 03:42:25 -06:00
Fixes return_url for image attachment (#12721)
* fixes return_url for image attachment #12538 * simplified conditions * handle nonetype error * fixed request check * Introduce htmx_table template tag for embedding HTMX-backed object tables --------- Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
This commit is contained in:
committed by
GitHub
parent
3e77daff01
commit
dbd3c6de24
4
netbox/utilities/templates/builtins/htmx_table.html
Normal file
4
netbox/utilities/templates/builtins/htmx_table.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="card-body htmx-container table-responsive"
|
||||
hx-get="{% url viewname %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}"
|
||||
hx-trigger="load"
|
||||
></div>
|
||||
@@ -1,4 +1,5 @@
|
||||
from django import template
|
||||
from django.http import QueryDict
|
||||
|
||||
__all__ = (
|
||||
'badge',
|
||||
@@ -74,3 +75,22 @@ def checkmark(value, show_false=True, true='Yes', false='No'):
|
||||
'true_label': true,
|
||||
'false_label': false,
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('builtins/htmx_table.html', takes_context=True)
|
||||
def htmx_table(context, viewname, return_url=None, **kwargs):
|
||||
"""
|
||||
Embed an object list table retrieved using HTMX. Any extra keyword arguments are passed as URL query parameters.
|
||||
|
||||
Args:
|
||||
context: The current request context
|
||||
viewname: The name of the view to use for the HTMX request (e.g. `dcim:site_list`)
|
||||
return_url: The URL to pass as the `return_url`. If not provided, the current request's path will be used.
|
||||
"""
|
||||
url_params = QueryDict(mutable=True)
|
||||
url_params.update(kwargs)
|
||||
url_params['return_url'] = return_url or context['request'].path
|
||||
return {
|
||||
'viewname': viewname,
|
||||
'url_params': url_params,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user