mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 03:27:21 -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:
parent
3e77daff01
commit
dbd3c6de24
@ -234,8 +234,12 @@ class ActionsColumn(tables.Column):
|
||||
return ''
|
||||
|
||||
model = table.Meta.model
|
||||
request = getattr(table, 'context', {}).get('request')
|
||||
url_appendix = f'?return_url={quote(request.get_full_path())}' if request else ''
|
||||
if request := getattr(table, 'context', {}).get('request'):
|
||||
return_url = request.GET.get('return_url', request.get_full_path())
|
||||
url_appendix = f'?return_url={quote(return_url)}'
|
||||
else:
|
||||
url_appendix = ''
|
||||
|
||||
html = ''
|
||||
|
||||
# Compile actions menu
|
||||
|
@ -1,12 +1,8 @@
|
||||
{% load helpers %}
|
||||
|
||||
<div class="card">
|
||||
<h5 class="card-header">
|
||||
Images
|
||||
</h5>
|
||||
<div class="card-body htmx-container table-responsive"
|
||||
hx-get="{% url 'extras:imageattachment_list' %}?content_type_id={{ object|content_type_id }}&object_id={{ object.pk }}"
|
||||
hx-trigger="load"></div>
|
||||
<h5 class="card-header">Images</h5>
|
||||
{% htmx_table 'extras:imageattachment_list' content_type_id=object|content_type_id object_id=object.pk %}
|
||||
{% if perms.extras.add_imageattachment %}
|
||||
<div class="card-footer text-end noprint">
|
||||
<a href="{% url 'extras:imageattachment_add' %}?content_type={{ object|content_type_id }}&object_id={{ object.pk }}" class="btn btn-primary btn-sm">
|
||||
|
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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user