mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-18 19:32:24 -06:00
Merge branch 'fix/generic_prefetch_4.2' of github.com:Tishka17/netbox into fix/generic_prefetch_4.2
This commit is contained in:
@@ -2,7 +2,7 @@ import django_filters
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.forms import BoundField
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.urls import reverse
|
||||
|
||||
from utilities.forms import widgets
|
||||
from utilities.views import get_viewname
|
||||
@@ -171,10 +171,8 @@ class DynamicModelChoiceMixin:
|
||||
|
||||
# Include quick add?
|
||||
if self.quick_add:
|
||||
app_label = self.model._meta.app_label
|
||||
model_name = self.model._meta.model_name
|
||||
widget.quick_add_context = {
|
||||
'url': reverse_lazy(f'{app_label}:{model_name}_add'),
|
||||
'url': reverse(get_viewname(self.model, 'add')),
|
||||
'params': {},
|
||||
}
|
||||
for k, v in self.quick_add_params.items():
|
||||
|
||||
@@ -132,8 +132,9 @@ class TableConfigForm(forms.Form):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Initialize columns field based on table attributes
|
||||
self.fields['available_columns'].choices = table.available_columns
|
||||
self.fields['columns'].choices = table.selected_columns
|
||||
if table:
|
||||
self.fields['available_columns'].choices = table.available_columns
|
||||
self.fields['columns'].choices = table.selected_columns
|
||||
|
||||
@property
|
||||
def table_name(self):
|
||||
|
||||
@@ -30,13 +30,17 @@ class ReleaseInfo:
|
||||
edition: str
|
||||
published: Union[datetime.date, None] = None
|
||||
designation: Union[str, None] = None
|
||||
build: Union[str, None] = None
|
||||
features: FeatureSet = field(default_factory=FeatureSet)
|
||||
|
||||
@property
|
||||
def full_version(self):
|
||||
output = self.version
|
||||
if self.designation:
|
||||
return f"{self.version}-{self.designation}"
|
||||
return self.version
|
||||
output = f"{output}-{self.designation}"
|
||||
if self.build:
|
||||
output = f"{output}-{self.build}"
|
||||
return output
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
@@ -29,7 +29,7 @@ def serialize_object(obj, resolve_tags=True, extra=None, exclude=None):
|
||||
exclude = exclude or []
|
||||
|
||||
# Include custom_field_data as "custom_fields"
|
||||
if hasattr(obj, 'custom_field_data'):
|
||||
if 'custom_field_data' in data:
|
||||
data['custom_fields'] = data.pop('custom_field_data')
|
||||
|
||||
# Resolve any assigned tags to their names. Check for tags cached on the instance;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{% load helpers %}
|
||||
|
||||
{% if viewname %}<a href="{% url viewname %}?tag={{ tag.slug }}">{% endif %}<span class="badge" style="color: {{ tag.color|fgcolor }}; background-color: #{{ tag.color }}">{{ tag }}</span>{% if viewname %}</a>{% endif %}
|
||||
{% if viewname %}<a href="{% url viewname %}?tag={{ tag.slug }}">{% endif %}<span {% if tag.description %}title="{{ tag.description }}"{% endif %} class="badge" style="color: {{ tag.color|fgcolor }}; background-color: #{{ tag.color }}">{{ tag }}</span>{% if viewname %}</a>{% endif %}
|
||||
|
||||
@@ -8,6 +8,7 @@ from django.urls import NoReverseMatch, reverse
|
||||
from core.models import ObjectType
|
||||
from utilities.forms import get_selected_values, TableConfigForm
|
||||
from utilities.views import get_viewname
|
||||
from netbox.settings import DISK_BASE_UNIT, RAM_BASE_UNIT
|
||||
|
||||
__all__ = (
|
||||
'applied_filters',
|
||||
@@ -15,7 +16,8 @@ __all__ = (
|
||||
'divide',
|
||||
'get_item',
|
||||
'get_key',
|
||||
'humanize_megabytes',
|
||||
'humanize_disk_megabytes',
|
||||
'humanize_ram_megabytes',
|
||||
'humanize_speed',
|
||||
'icon_from_status',
|
||||
'kg_to_pounds',
|
||||
@@ -84,17 +86,16 @@ def humanize_speed(speed):
|
||||
return '{} Kbps'.format(speed)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def humanize_megabytes(mb):
|
||||
def _humanize_megabytes(mb, divisor=1000):
|
||||
"""
|
||||
Express a number of megabytes in the most suitable unit (e.g. gigabytes, terabytes, etc.).
|
||||
"""
|
||||
if not mb:
|
||||
return ""
|
||||
|
||||
PB_SIZE = 1000000000
|
||||
TB_SIZE = 1000000
|
||||
GB_SIZE = 1000
|
||||
PB_SIZE = divisor**3
|
||||
TB_SIZE = divisor**2
|
||||
GB_SIZE = divisor
|
||||
|
||||
if mb >= PB_SIZE:
|
||||
return f"{mb / PB_SIZE:.2f} PB"
|
||||
@@ -105,6 +106,24 @@ def humanize_megabytes(mb):
|
||||
return f"{mb} MB"
|
||||
|
||||
|
||||
@register.filter()
|
||||
def humanize_disk_megabytes(mb):
|
||||
"""
|
||||
Express a number of megabytes in the most suitable unit (e.g. gigabytes, terabytes, etc.).
|
||||
Use the DISK_BASE_UNIT setting to determine the divisor. Default is 1000.
|
||||
"""
|
||||
return _humanize_megabytes(mb, DISK_BASE_UNIT)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def humanize_ram_megabytes(mb):
|
||||
"""
|
||||
Express a number of megabytes in the most suitable unit (e.g. gigabytes, terabytes, etc.).
|
||||
Use the RAM_BASE_UNIT setting to determine the divisor. Default is 1000.
|
||||
"""
|
||||
return _humanize_megabytes(mb, RAM_BASE_UNIT)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def divide(x, y):
|
||||
"""
|
||||
|
||||
@@ -196,7 +196,10 @@ class GetRelatedModelsMixin:
|
||||
]
|
||||
related_models.extend(extra)
|
||||
|
||||
return sorted(related_models, key=lambda x: x[0].model._meta.verbose_name.lower())
|
||||
return sorted(
|
||||
filter(lambda qs: qs[0].exists(), related_models),
|
||||
key=lambda qs: qs[0].model._meta.verbose_name.lower(),
|
||||
)
|
||||
|
||||
|
||||
class ViewTab:
|
||||
|
||||
Reference in New Issue
Block a user