Merge pull request #20537 from netbox-community/17571-remove-htmx-navigation
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CI / build (20.x, 3.13) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled

#17571 - Remove HTMX navigation
This commit is contained in:
bctiemann 2025-10-09 17:49:35 -04:00 committed by GitHub
commit a91af996d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 6 additions and 54 deletions

View File

@ -34,9 +34,6 @@ Sets the default number of rows displayed on paginated tables.
### Paginator placement
Controls where pagination controls are rendered relative to a table.
### HTMX navigation (experimental)
Enables partialpage navigation for supported views. Disable this preference if unexpected behavior is observed.
### Striped table rows
Toggles alternating row backgrounds on tables.

View File

@ -28,7 +28,6 @@ def preferences(request):
user_preferences = request.user.config if request.user.is_authenticated else {}
return {
'preferences': user_preferences,
'htmx_navigation': user_preferences.get('ui.htmx_navigation', False) == 'true'
}

View File

@ -26,16 +26,6 @@ def get_csv_delimiters():
PREFERENCES = {
# User interface
'ui.htmx_navigation': UserPreference(
label=_('HTMX Navigation'),
choices=(
('', _('Disabled')),
('true', _('Enabled')),
),
description=_('Enable dynamic UI navigation'),
default=False,
warning=_('Experimental feature')
),
'locale.language': UserPreference(
label=_('Language'),
choices=(

View File

@ -95,7 +95,7 @@ Blocks:
{# Page content #}
<div class="page-wrapper">
<div id="page-content" {% htmx_boost %}>
<div id="page-content">
{# Page header #}
{% block header %}

View File

@ -33,7 +33,7 @@
</div>
</div>
</a>
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow" {% htmx_boost %}>
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
<a href="{% url 'account:profile' %}" class="dropdown-item">
<i class="mdi mdi-account"></i> {% trans "Profile" %}
</a>

View File

@ -61,8 +61,7 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
class UserConfigForm(forms.ModelForm, metaclass=UserConfigFormMetaclass):
fieldsets = (
FieldSet(
'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.htmx_navigation',
'ui.tables.striping',
'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.tables.striping',
name=_('User Interface')
),
FieldSet('data_format', 'csv_delimiter', name=_('Miscellaneous')),

View File

@ -2,7 +2,7 @@
{% load i18n %}
{% load navigation %}
<ul class="navbar-nav pt-lg-2" {% htmx_boost %}>
<ul class="navbar-nav pt-lg-2">
<li class="nav-item d-block d-lg-none">
<form action="{% url 'search' %}" method="get" autocomplete="off" novalidate>
<div class="input-group mb-1 mt-2">

View File

@ -1,5 +1,4 @@
from django import template
from django.utils.safestring import mark_safe
from extras.choices import CustomFieldTypeChoices
from utilities.querydict import dict_to_querydict
@ -121,9 +120,7 @@ def htmx_table(context, viewname, return_url=None, **kwargs):
@register.simple_tag(takes_context=True)
def formaction(context):
"""
Replace the 'formaction' attribute on an HTML element with the appropriate HTMX attributes
if HTMX navigation is enabled (per the user's preferences).
A hook for overriding the 'formaction' attribute on an HTML element, for example to replace
with 'hx-push-url="true" hx-post' for HTMX navigation.
"""
if context.get('htmx_navigation', False):
return mark_safe('hx-push-url="true" hx-post')
return 'formaction'

View File

@ -226,7 +226,6 @@ def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
return {
'label': _('Edit Selected'),
'url': url,
'htmx_navigation': context.get('htmx_navigation'),
}
@ -243,5 +242,4 @@ def bulk_delete_button(context, model, action='bulk_delete', query_params=None):
return {
'label': _('Delete Selected'),
'url': url,
'htmx_navigation': context.get('htmx_navigation'),
}

View File

@ -1,11 +1,9 @@
from django import template
from django.utils.safestring import mark_safe
from netbox.navigation.menu import MENUS
__all__ = (
'nav',
'htmx_boost',
)
@ -43,30 +41,4 @@ def nav(context):
return {
'nav_items': nav_items,
'htmx_navigation': context['htmx_navigation']
}
@register.simple_tag(takes_context=True)
def htmx_boost(context, target='#page-content', select='#page-content'):
"""
Renders the HTML attributes needed to effect HTMX boosting within an element if
HTMX navigation is enabled for the request. The target and select parameters are
rendered as `hx-target` and `hx-select`, respectively. For example:
<div id="page-content" {% htmx_boost %}>
If HTMX navigation is not enabled, the tag renders no content.
"""
if not context.get('htmx_navigation', False):
return ''
hx_params = {
'hx-boost': 'true',
'hx-target': target,
'hx-select': select,
'hx-swap': 'outerHTML show:window:top',
}
htmx_params = ' '.join([
f'{k}="{v}"' for k, v in hx_params.items()
])
return mark_safe(htmx_params)