mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 03:42:25 -06:00
Merge branch 'develop' into feature
This commit is contained in:
3
netbox/utilities/templates/builtins/copy_content.html
Normal file
3
netbox/utilities/templates/builtins/copy_content.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<a class="btn btn-sm {{ color }} copy-content" data-clipboard-target="{{ target }}" title="Copy to clipboard">
|
||||
<i class="mdi mdi-content-copy"></i>
|
||||
</a>
|
||||
@@ -1,9 +1,12 @@
|
||||
from django import template
|
||||
from django.http import QueryDict
|
||||
|
||||
from utilities.utils import dict_to_querydict
|
||||
|
||||
__all__ = (
|
||||
'badge',
|
||||
'checkmark',
|
||||
'copy_content',
|
||||
'customfield_value',
|
||||
'tag',
|
||||
)
|
||||
@@ -77,6 +80,17 @@ def checkmark(value, show_false=True, true='Yes', false='No'):
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('builtins/copy_content.html')
|
||||
def copy_content(target, prefix=None, color='primary'):
|
||||
"""
|
||||
Display a copy button to copy the content of a field.
|
||||
"""
|
||||
return {
|
||||
'target': f'#{prefix or ""}{target}',
|
||||
'color': f'btn-{color}'
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('builtins/htmx_table.html', takes_context=True)
|
||||
def htmx_table(context, viewname, return_url=None, **kwargs):
|
||||
"""
|
||||
@@ -87,8 +101,7 @@ def htmx_table(context, viewname, return_url=None, **kwargs):
|
||||
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 = dict_to_querydict(kwargs)
|
||||
url_params['return_url'] = return_url or context['request'].path
|
||||
return {
|
||||
'viewname': viewname,
|
||||
|
||||
@@ -11,8 +11,9 @@ from django.core import serializers
|
||||
from django.db.models import Count, OuterRef, Subquery
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.http import QueryDict
|
||||
from django.utils.html import escape
|
||||
from django.utils import timezone
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.html import escape
|
||||
from django.utils.timezone import localtime
|
||||
from jinja2.sandbox import SandboxedEnvironment
|
||||
from mptt.models import MPTTModel
|
||||
@@ -231,6 +232,19 @@ def dict_to_filter_params(d, prefix=''):
|
||||
return params
|
||||
|
||||
|
||||
def dict_to_querydict(d, mutable=True):
|
||||
"""
|
||||
Create a QueryDict instance from a regular Python dictionary.
|
||||
"""
|
||||
qd = QueryDict(mutable=True)
|
||||
for k, v in d.items():
|
||||
item = MultiValueDict({k: v}) if isinstance(v, (list, tuple, set)) else {k: v}
|
||||
qd.update(item)
|
||||
if not mutable:
|
||||
qd._mutable = False
|
||||
return qd
|
||||
|
||||
|
||||
def normalize_querydict(querydict):
|
||||
"""
|
||||
Convert a QueryDict to a normal, mutable dictionary, preserving list values. For example,
|
||||
|
||||
Reference in New Issue
Block a user