[PR #17579] [MERGED] Fixes: #17126 - Respect the weight unit of the DeviceType when displaying the Device detail #15128

Closed
opened 2025-12-30 00:20:09 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/17579
Author: @bctiemann
Created: 9/23/2024
Status: Merged
Merged: 9/24/2024
Merged by: @jeremystretch

Base: developHead: 17126-consistent-weight-in-device-detail


📝 Commits (2)

  • f769f77 Respect the weight unit of the DeviceType when displaying the Device details
  • 0c90284 Reuse the same weight formatting construct as in rack.html, and add placeholder in rack if empty

📊 Changes

2 files changed (+7 additions, -2 deletions)

View changed files

📝 netbox/templates/dcim/device.html (+1 -0)
📝 netbox/templates/dcim/rack.html (+6 -2)

📄 Description

Fixes: #17126

Changes device.html to conditionally convert a device's total_weight to pounds if the DeviceType defines the weight in pounds in the weight_unit.

Note that this compares the weight_unit value to the literal string 'lb' or 'kg', rather than to an enum value in the WeightUnitChoiceSet. It would be more DRY to pass the enum to the template context, but less elegant as the data construct does not seem to allow direct access to class attrs in the template, meaning the enum would need to be transformed or deconstructed to pass into the template properly.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/17579 **Author:** [@bctiemann](https://github.com/bctiemann) **Created:** 9/23/2024 **Status:** ✅ Merged **Merged:** 9/24/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `17126-consistent-weight-in-device-detail` --- ### 📝 Commits (2) - [`f769f77`](https://github.com/netbox-community/netbox/commit/f769f773f1bbfdcebc2d15e79f233ba3e6a829c1) Respect the weight unit of the DeviceType when displaying the Device details - [`0c90284`](https://github.com/netbox-community/netbox/commit/0c90284448247623101a580d207d58d66fa1d5ec) Reuse the same weight formatting construct as in rack.html, and add placeholder in rack if empty ### 📊 Changes **2 files changed** (+7 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `netbox/templates/dcim/device.html` (+1 -0) 📝 `netbox/templates/dcim/rack.html` (+6 -2) </details> ### 📄 Description ### Fixes: #17126 Changes `device.html` to conditionally convert a device's `total_weight` to pounds if the DeviceType defines the weight in pounds in the `weight_unit`. Note that this compares the `weight_unit` value to the literal string `'lb'` or `'kg'`, rather than to an enum value in the `WeightUnitChoiceSet`. It would be more DRY to pass the enum to the template context, but less elegant as the data construct does not seem to allow direct access to class attrs in the template, meaning the enum would need to be transformed or deconstructed to pass into the template properly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:20:09 +01:00
adam closed this issue 2025-12-30 00:20:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15128