Rename render_partial() to htmx_partial()

This commit is contained in:
Jeremy Stretch 2024-03-27 09:24:39 -04:00
parent 5fcc0fc2a4
commit 6c540e56ff
6 changed files with 17 additions and 16 deletions

View File

@ -25,7 +25,7 @@ from netbox.views import generic
from netbox.views.generic.base import BaseObjectView
from netbox.views.generic.mixins import TableMixin
from utilities.forms import ConfirmationForm
from utilities.htmx import render_partial
from utilities.htmx import htmx_partial
from utilities.query import count_related
from utilities.views import ContentTypePermissionRequiredMixin, register_model_view
from . import filtersets, forms, tables
@ -321,7 +321,7 @@ class BackgroundTaskListView(TableMixin, BaseRQView):
table = self.get_table(data, request, False)
# If this is an HTMX request, return only the rendered table HTML
if render_partial(request):
if htmx_partial(request):
return render(request, 'htmx/table.html', {
'table': table,
})
@ -490,7 +490,7 @@ class WorkerListView(TableMixin, BaseRQView):
table = self.get_table(data, request, False)
# If this is an HTMX request, return only the rendered table HTML
if render_partial(request):
if htmx_partial(request):
if not request.htmx.target:
table.embedded = True
# Hide selection checkboxes

View File

@ -20,7 +20,7 @@ from netbox.views import generic
from netbox.views.generic.mixins import TableMixin
from utilities.data import shallow_compare_dict
from utilities.forms import ConfirmationForm, get_field_value
from utilities.htmx import render_partial
from utilities.htmx import htmx_partial
from utilities.paginator import EnhancedPaginator, get_paginate_count
from utilities.query import count_related
from utilities.querydict import normalize_querydict
@ -1225,7 +1225,7 @@ class ScriptResultView(TableMixin, generic.ObjectView):
}
# If this is an HTMX request, return only the result HTML
if render_partial(request):
if htmx_partial(request):
response = render(request, 'extras/htmx/script_result.html', context)
if job.completed or not job.started:
response.status_code = 286

View File

@ -23,7 +23,7 @@ from utilities.error_handlers import handle_protectederror
from utilities.exceptions import AbortRequest, AbortTransaction, PermissionsViolation
from utilities.forms import BulkRenameForm, ConfirmationForm, restrict_form_fields
from utilities.forms.bulk_import import BulkImportForm
from utilities.htmx import render_partial
from utilities.htmx import htmx_partial
from utilities.permissions import get_permission_for_model
from utilities.views import GetReturnURLMixin, get_viewname
from .base import BaseMultiObjectView
@ -162,7 +162,7 @@ class ObjectListView(BaseMultiObjectView, ActionsMixin, TableMixin):
table = self.get_table(self.queryset, request, has_bulk_actions)
# If this is an HTMX request, return only the rendered table HTML
if render_partial(request):
if htmx_partial(request):
if not request.htmx.target:
table.embedded = True
# Hide selection checkboxes

View File

@ -17,7 +17,7 @@ from extras.signals import clear_events
from utilities.error_handlers import handle_protectederror
from utilities.exceptions import AbortRequest, PermissionsViolation
from utilities.forms import ConfirmationForm, restrict_form_fields
from utilities.htmx import render_partial
from utilities.htmx import htmx_partial
from utilities.permissions import get_permission_for_model
from utilities.querydict import normalize_querydict, prepare_cloned_fields
from utilities.views import GetReturnURLMixin, get_viewname
@ -139,7 +139,7 @@ class ObjectChildrenView(ObjectView, ActionsMixin, TableMixin):
table = self.get_table(table_data, request, has_bulk_actions)
# If this is an HTMX request, return only the rendered table HTML
if render_partial(request):
if htmx_partial(request):
return render(request, 'htmx/table.html', {
'object': instance,
'table': table,
@ -227,7 +227,7 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
restrict_form_fields(form, request.user)
# If this is an HTMX request, return only the rendered form HTML
if render_partial(request):
if htmx_partial(request):
return render(request, 'htmx/form.html', {
'form': form,
})
@ -483,7 +483,7 @@ class ComponentCreateView(GetReturnURLMixin, BaseObjectView):
instance = self.alter_object(self.queryset.model(), request)
# If this is an HTMX request, return only the rendered form HTML
if render_partial(request):
if htmx_partial(request):
return render(request, 'htmx/form.html', {
'form': form,
})

View File

@ -17,7 +17,7 @@ from netbox.forms import SearchForm
from netbox.search import LookupTypes
from netbox.search.backends import search_backend
from netbox.tables import SearchTable
from utilities.htmx import render_partial
from utilities.htmx import htmx_partial
from utilities.paginator import EnhancedPaginator, get_paginate_count
__all__ = (
@ -105,7 +105,7 @@ class SearchView(View):
}).configure(table)
# If this is an HTMX request, return only the rendered table HTML
if render_partial(request):
if htmx_partial(request):
return render(request, 'htmx/table.html', {
'table': table,
})

View File

@ -1,12 +1,13 @@
__all__ = (
'render_partial',
'htmx_partial',
)
PAGE_CONTAINER_ID = 'page-content'
def render_partial(request):
def htmx_partial(request):
"""
Determines whether to render a partial response.
Determines whether to render partial (versus complete) HTML content
in response to an HTMX request, based on the target element.
"""
return request.htmx and request.htmx.target != PAGE_CONTAINER_ID