Arthur hai 1 semana
pai
achega
06e33d65bf

+ 3 - 2
netbox/dcim/forms/bulk_edit.py

@@ -1122,7 +1122,8 @@ class CoolingSourceBulkEditForm(PrimaryModelBulkEditForm):
         ),
     )
     nullable_fields = (
-        'location', 'cooling_capacity', 'supply_temperature', 'return_temperature', 'description', 'comments',
+        'location', 'cooling_capacity', 'supply_temperature', 'return_temperature', 'temperature_unit',
+        'description', 'comments',
     )
 
 
@@ -1217,7 +1218,7 @@ class CoolingFeedBulkEditForm(PrimaryModelBulkEditForm):
     )
     nullable_fields = (
         'rack', 'fluid_type', 'cooling_capacity', 'flow_rate', 'flow_rate_unit', 'pressure', 'pressure_unit',
-        'supply_temperature', 'return_temperature', 'tenant', 'description', 'comments',
+        'supply_temperature', 'return_temperature', 'temperature_unit', 'tenant', 'description', 'comments',
     )
 
 

+ 1 - 86
netbox/dcim/models/cooling.py

@@ -4,11 +4,9 @@ from django.db import models
 from django.utils.translation import gettext_lazy as _
 
 from dcim.choices import *
-from netbox.choices import TemperatureUnitChoices
 from netbox.models import PrimaryModel
 from netbox.models.features import ContactsMixin, ImageAttachmentsMixin
-from netbox.models.mixins import FlowRateMixin, PressureMixin
-from utilities.conversion import to_celsius
+from netbox.models.mixins import CoolingTemperatureMixin, FlowRateMixin, PressureMixin
 
 from .device_components import CabledObjectModel, PathEndpoint
 
@@ -22,89 +20,6 @@ __all__ = (
 # Cooling
 #
 
-class CoolingTemperatureMixin(models.Model):
-    """
-    Adds design supply/return temperatures sharing a single unit, with normalized (°C) fields for ordering.
-    """
-    supply_temperature = models.DecimalField(
-        verbose_name=_('supply temperature'),
-        max_digits=6,
-        decimal_places=2,
-        blank=True,
-        null=True,
-        help_text=_('Supply (cold) temperature')
-    )
-    return_temperature = models.DecimalField(
-        verbose_name=_('return temperature'),
-        max_digits=6,
-        decimal_places=2,
-        blank=True,
-        null=True,
-        help_text=_('Return (warm) temperature')
-    )
-    temperature_unit = models.CharField(
-        verbose_name=_('temperature unit'),
-        max_length=50,
-        choices=TemperatureUnitChoices,
-        blank=True,
-        null=True,
-    )
-    # Stores the normalized temperatures (in degrees Celsius) for database ordering
-    _abs_supply_temperature = models.DecimalField(
-        max_digits=8,
-        decimal_places=4,
-        blank=True,
-        null=True
-    )
-    _abs_return_temperature = models.DecimalField(
-        max_digits=8,
-        decimal_places=4,
-        blank=True,
-        null=True
-    )
-
-    class Meta:
-        abstract = True
-
-    @property
-    def abs_supply_temperature(self):
-        # Public alias for _abs_supply_temperature; Django templates cannot access underscore-prefixed attributes.
-        return self._abs_supply_temperature
-
-    @property
-    def abs_return_temperature(self):
-        # Public alias for _abs_return_temperature; Django templates cannot access underscore-prefixed attributes.
-        return self._abs_return_temperature
-
-    def save(self, *args, **kwargs):
-        # Store the given temperatures (if any) in degrees Celsius for use in database ordering
-        if self.temperature_unit:
-            self._abs_supply_temperature = (
-                to_celsius(self.supply_temperature, self.temperature_unit)
-                if self.supply_temperature is not None else None
-            )
-            self._abs_return_temperature = (
-                to_celsius(self.return_temperature, self.temperature_unit)
-                if self.return_temperature is not None else None
-            )
-        else:
-            self._abs_supply_temperature = None
-            self._abs_return_temperature = None
-
-        # Clear temperature_unit if no temperatures are defined
-        if self.supply_temperature is None and self.return_temperature is None:
-            self.temperature_unit = None
-
-        super().save(*args, **kwargs)
-
-    def clean(self):
-        super().clean()
-
-        # A temperature unit is required when a temperature is set
-        if (self.supply_temperature is not None or self.return_temperature is not None) and not self.temperature_unit:
-            raise ValidationError(_("Must specify a unit when setting a temperature"))
-
-
 class CoolingSource(CoolingTemperatureMixin, ContactsMixin, ImageAttachmentsMixin, PrimaryModel):
     """
     A facility-level source of cooling; e.g. a chiller, cooling tower, or dry cooler.

+ 1 - 1
netbox/dcim/ui/panels.py

@@ -417,7 +417,7 @@ class CoolingFeedPanel(panels.ObjectAttributesPanel):
     connected_device = attrs.TemplatedAttr(
         'connected_endpoints',
         label=_('Connected device'),
-        template_name='dcim/powerfeed/attrs/connected_device.html',
+        template_name='dcim/coolingfeed/attrs/connected_device.html',
     )
 
 

+ 92 - 1
netbox/netbox/models/mixins.py

@@ -4,9 +4,17 @@ from django.db import models
 from django.utils.translation import gettext_lazy as _
 
 from netbox.choices import *
-from utilities.conversion import to_grams, to_kilopascals, to_liters_per_minute, to_meters, to_millimeters
+from utilities.conversion import (
+    to_celsius,
+    to_grams,
+    to_kilopascals,
+    to_liters_per_minute,
+    to_meters,
+    to_millimeters,
+)
 
 __all__ = (
+    'CoolingTemperatureMixin',
     'DiameterMixin',
     'DistanceMixin',
     'FlowRateMixin',
@@ -237,6 +245,89 @@ class PressureMixin(models.Model):
             raise ValidationError(_("Must specify a unit when setting a pressure"))
 
 
+class CoolingTemperatureMixin(models.Model):
+    """
+    Adds supply/return temperatures sharing a single unit, with normalized (°C) fields for ordering.
+    """
+    supply_temperature = models.DecimalField(
+        verbose_name=_('supply temperature'),
+        max_digits=6,
+        decimal_places=2,
+        blank=True,
+        null=True,
+        help_text=_('Supply (cold) temperature')
+    )
+    return_temperature = models.DecimalField(
+        verbose_name=_('return temperature'),
+        max_digits=6,
+        decimal_places=2,
+        blank=True,
+        null=True,
+        help_text=_('Return (warm) temperature')
+    )
+    temperature_unit = models.CharField(
+        verbose_name=_('temperature unit'),
+        max_length=50,
+        choices=TemperatureUnitChoices,
+        blank=True,
+        null=True,
+    )
+    # Stores the normalized temperatures (in degrees Celsius) for database ordering
+    _abs_supply_temperature = models.DecimalField(
+        max_digits=8,
+        decimal_places=4,
+        blank=True,
+        null=True
+    )
+    _abs_return_temperature = models.DecimalField(
+        max_digits=8,
+        decimal_places=4,
+        blank=True,
+        null=True
+    )
+
+    class Meta:
+        abstract = True
+
+    @property
+    def abs_supply_temperature(self):
+        # Public alias for _abs_supply_temperature; Django templates cannot access underscore-prefixed attributes.
+        return self._abs_supply_temperature
+
+    @property
+    def abs_return_temperature(self):
+        # Public alias for _abs_return_temperature; Django templates cannot access underscore-prefixed attributes.
+        return self._abs_return_temperature
+
+    def save(self, *args, **kwargs):
+        # Store the given temperatures (if any) in degrees Celsius for use in database ordering
+        if self.temperature_unit:
+            self._abs_supply_temperature = (
+                to_celsius(self.supply_temperature, self.temperature_unit)
+                if self.supply_temperature is not None else None
+            )
+            self._abs_return_temperature = (
+                to_celsius(self.return_temperature, self.temperature_unit)
+                if self.return_temperature is not None else None
+            )
+        else:
+            self._abs_supply_temperature = None
+            self._abs_return_temperature = None
+
+        # Clear temperature_unit if no temperatures are defined
+        if self.supply_temperature is None and self.return_temperature is None:
+            self.temperature_unit = None
+
+        super().save(*args, **kwargs)
+
+    def clean(self):
+        super().clean()
+
+        # A temperature unit is required when a temperature is set
+        if (self.supply_temperature is not None or self.return_temperature is not None) and not self.temperature_unit:
+            raise ValidationError(_("Must specify a unit when setting a temperature"))
+
+
 class DistanceMixin(models.Model):
     distance = models.DecimalField(
         verbose_name=_('distance'),

+ 6 - 0
netbox/templates/dcim/coolingfeed/attrs/connected_device.html

@@ -0,0 +1,6 @@
+{% load helpers %}
+{% if value %}
+  {{ value.0.device|linkify }} ({{ value.0|linkify:"name" }})
+{% else %}
+  {{ ''|placeholder }}
+{% endif %}