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:
@@ -1,11 +1,12 @@
|
||||
from django_rq.queues import get_connection
|
||||
from rq import Worker
|
||||
from rq import Retry, Worker
|
||||
|
||||
from netbox.config import get_config
|
||||
from netbox.constants import RQ_QUEUE_DEFAULT
|
||||
|
||||
__all__ = (
|
||||
'get_queue_for_model',
|
||||
'get_rq_retry',
|
||||
'get_workers_for_queue',
|
||||
)
|
||||
|
||||
@@ -22,3 +23,14 @@ def get_workers_for_queue(queue_name):
|
||||
Returns True if a worker process is currently servicing the specified queue.
|
||||
"""
|
||||
return Worker.count(get_connection(queue_name))
|
||||
|
||||
|
||||
def get_rq_retry():
|
||||
"""
|
||||
If RQ_RETRY_MAX is defined and greater than zero, instantiate and return a Retry object to be
|
||||
used when queuing a job. Otherwise, return None.
|
||||
"""
|
||||
retry_max = get_config().RQ_RETRY_MAX
|
||||
retry_interval = get_config().RQ_RETRY_INTERVAL
|
||||
if retry_max:
|
||||
return Retry(max=retry_max, interval=retry_interval)
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ def to_meters(length, unit):
|
||||
if unit == CableLengthUnitChoices.UNIT_FOOT:
|
||||
return length * Decimal(0.3048)
|
||||
if unit == CableLengthUnitChoices.UNIT_INCH:
|
||||
return length * Decimal(0.3048) * 12
|
||||
return length * Decimal(0.0254)
|
||||
raise ValueError(f"Unknown unit {unit}. Must be 'km', 'm', 'cm', 'mi', 'ft', or 'in'.")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user