Sfoglia il codice sorgente

review fixes - make location panel

Arthur 2 giorni fa
parent
commit
8615d64494

+ 17 - 7
netbox/dcim/ui/panels.py

@@ -37,6 +37,11 @@ class SitePanel(panels.ObjectAttributesPanel):
     facility = attrs.TextAttr('facility')
     description = attrs.TextAttr('description')
     timezone = attrs.TimezoneAttr('time_zone')
+
+
+class SiteLocationPanel(panels.ObjectAttributesPanel):
+    title = _('Location')
+
     physical_address = attrs.AddressAttr('physical_address', map_url=True, copy_button=True)
     shipping_address = attrs.AddressAttr('shipping_address', map_url=True, copy_button=True)
     gps_coordinates = attrs.GPSCoordinatesAttr()
@@ -115,15 +120,8 @@ class RackTypePanel(panels.ObjectAttributesPanel):
 
 
 class DevicePanel(panels.ObjectAttributesPanel):
-    region = attrs.NestedObjectAttr('site.region', linkify=True)
-    site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group')
-    location = attrs.NestedObjectAttr('location', linkify=True)
-    rack = attrs.TemplatedAttr('rack', template_name='dcim/device/attrs/rack.html')
     virtual_chassis = attrs.RelatedObjectAttr('virtual_chassis', linkify=True)
     parent_device = attrs.TemplatedAttr('parent_bay', template_name='dcim/device/attrs/parent_device.html')
-    gps_coordinates = attrs.GPSCoordinatesAttr()
-    mercator_x = attrs.NumericAttr('mercator_x', label=_('Web Mercator X'), copy_button=True, localize=False)
-    mercator_y = attrs.NumericAttr('mercator_y', label=_('Web Mercator Y'), copy_button=True, localize=False)
     tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
     description = attrs.TextAttr('description')
     cooling_method = attrs.ChoiceAttr('cooling_method')
@@ -133,6 +131,18 @@ class DevicePanel(panels.ObjectAttributesPanel):
     config_template = attrs.RelatedObjectAttr('config_template', linkify=True)
 
 
+class DeviceLocationPanel(panels.ObjectAttributesPanel):
+    title = _('Location')
+
+    region = attrs.NestedObjectAttr('site.region', linkify=True)
+    site = attrs.RelatedObjectAttr('site', linkify=True, grouped_by='group')
+    location = attrs.NestedObjectAttr('location', linkify=True)
+    rack = attrs.TemplatedAttr('rack', template_name='dcim/device/attrs/rack.html')
+    gps_coordinates = attrs.GPSCoordinatesAttr()
+    mercator_x = attrs.NumericAttr('mercator_x', label=_('Web Mercator X'), copy_button=True, localize=False)
+    mercator_y = attrs.NumericAttr('mercator_y', label=_('Web Mercator Y'), copy_button=True, localize=False)
+
+
 class DeviceManagementPanel(panels.ObjectAttributesPanel):
     title = _('Management')
 

+ 2 - 0
netbox/dcim/views.py

@@ -550,6 +550,7 @@ class SiteView(GetRelatedModelsMixin, generic.ObjectView):
     layout = layout.SimpleLayout(
         left_panels=[
             panels.SitePanel(),
+            panels.SiteLocationPanel(),
             CustomFieldsPanel(),
             TagsPanel(),
             CommentsPanel(),
@@ -2964,6 +2965,7 @@ class DeviceView(generic.ObjectView):
     layout = layout.SimpleLayout(
         left_panels=[
             panels.DevicePanel(),
+            panels.DeviceLocationPanel(),
             panels.VirtualChassisMembersPanel(),
             CustomFieldsPanel(),
             TagsPanel(),

+ 6 - 0
netbox/netbox/tests/test_ui.py

@@ -738,6 +738,12 @@ class WeightAttrTestCase(SimpleTestCase):
         self.assertIn('10', result)
         self.assertIn('lbs', result)
 
+    def test_render_localized(self):
+        attr = attrs.WeightAttr('weight')
+        obj = self._obj(Decimal('2.5'), 'kg', 2500, 'Kilograms')
+        with translation.override('de'):
+            self.assertIn('2,5', attr.render(obj, self._ctx()))
+
 
 class DistanceAttrTestCase(SimpleTestCase):
 

+ 1 - 1
netbox/templates/ui/attrs/numeric.html

@@ -1,6 +1,6 @@
 {% load i18n l10n %}
 <span>
-  <span{% if name %} id="attr_{{ name }}"{% endif %}>{% if localize %}{{ value }}{% else %}{{ value|unlocalize }}{% endif %}</span>
+  <span{% if name %} id="attr_{{ name }}"{% endif %}>{% if localize is False %}{{ value|unlocalize }}{% else %}{{ value }}{% endif %}</span>
   {% if unit %}
     {{ unit|lower }}
   {% endif %}