Fixes #21095: Add IEC unit labels support and rename humanize helpers to be unit-agnostic #48

Closed
opened 2026-04-05 16:21:19 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jsenecal on 3/31/2026

Fixes: #21095

Summary

  • _humanize_capacity() (renamed from _humanize_megabytes()) now emits IEC labels
    (MiB, GiB, TiB, PiB) when the divisor is 1024, and SI labels (MB, GB, TB, PB) when 1000
  • Renamed humanize_disk_megabytes / humanize_ram_megabytes template filters to
    humanize_disk_capacity / humanize_ram_capacity to reflect that stored values
    are unit-agnostic, not strictly megabytes
  • Form labels in bulk edit and filter forms dynamically reflect the configured
    RAM_BASE_UNIT / DISK_BASE_UNIT setting via get_capacity_unit_label()
  • VM table memory column now humanized via render_memory() (disk already was)

No conversion logic is needed on save. The database stores a raw integer whose
interpretation as MB or MiB is determined by the RAM_BASE_UNIT / DISK_BASE_UNIT
setting. The same setting controls both input labels and display humanization,
keeping the roundtrip consistent.

Tests

  • Unit tests for _humanize_capacity with both SI (1000) and IEC (1024) divisors
  • Unit tests for get_capacity_unit_label helper
  • Full virtualization test suite passes (410 tests)
  • Django system check and migration check pass
*Originally created by @jsenecal on 3/31/2026* ### Fixes: #21095 ## Summary - `_humanize_capacity()` (renamed from `_humanize_megabytes()`) now emits IEC labels (MiB, GiB, TiB, PiB) when the divisor is 1024, and SI labels (MB, GB, TB, PB) when 1000 - Renamed `humanize_disk_megabytes` / `humanize_ram_megabytes` template filters to `humanize_disk_capacity` / `humanize_ram_capacity` to reflect that stored values are unit-agnostic, not strictly megabytes - Form labels in bulk edit and filter forms dynamically reflect the configured `RAM_BASE_UNIT` / `DISK_BASE_UNIT` setting via `get_capacity_unit_label()` - VM table memory column now humanized via `render_memory()` (disk already was) No conversion logic is needed on save. The database stores a raw integer whose interpretation as MB or MiB is determined by the `RAM_BASE_UNIT` / `DISK_BASE_UNIT` setting. The same setting controls both input labels and display humanization, keeping the roundtrip consistent. ## Tests - [x] Unit tests for `_humanize_capacity` with both SI (1000) and IEC (1024) divisors - [x] Unit tests for `get_capacity_unit_label` helper - [x] Full virtualization test suite passes (410 tests) - [x] Django system check and migration check pass
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#48