diff --git a/computes/templates/computes/capacity_line.txt b/computes/templates/computes/capacity_line.txt
index fd472d2d..9a1d704b 100644
--- a/computes/templates/computes/capacity_line.txt
+++ b/computes/templates/computes/capacity_line.txt
@@ -1,5 +1,5 @@
{% load i18n %}{% autoescape off %}{% if given %}
-{% blocktrans with vcpus=given.vcpus.all ratio=given.ratio|floatformat:1 assigned=given.assigned.all|filesizeformat %}Given to VMs: {{ vcpus }} vCPUs ({{ ratio }}:1), {{ assigned }} memory.{% endblocktrans %}
+{% blocktrans count counter=given.vcpus.all with ratio=given.ratio|floatformat:1 assigned=given.assigned.all|filesizeformat %}Given to VMs: {{ counter }} vCPU ({{ ratio }}:1), {{ assigned }} memory.{% plural %}Given to VMs: {{ counter }} vCPUs ({{ ratio }}:1), {{ assigned }} memory.{% endblocktrans %}
{% with pool=given.pools.0 %}{% if pool %}{% blocktrans with name=pool.name free=pool.free|filesizeformat %}Pool {{ name }}: {{ free }} free.{% endblocktrans %}{% endif %}{% endwith %}
{% else %}
{% trans "The capacity could not be read." %}
diff --git a/computes/templates/computes/list.html b/computes/templates/computes/list.html
index e824498b..ad5ad4a0 100644
--- a/computes/templates/computes/list.html
+++ b/computes/templates/computes/list.html
@@ -56,7 +56,7 @@
{% if given %}
{{ given.ratio|floatformat:1 }}:1
- {% blocktrans with all=given.vcpus.all cpus=given.cpus %}{{ all }} vCPUs on {{ cpus }} CPUs{% endblocktrans %}
+ {% blocktrans count counter=given.vcpus.all %}{{ counter }} vCPU{% plural %}{{ counter }} vCPUs{% endblocktrans %} {% blocktrans count counter=given.cpus %}on {{ counter }} CPU{% plural %}on {{ counter }} CPUs{% endblocktrans %}
{% blocktrans with running=given.vcpus.running %}{{ running }} running{% endblocktrans %}
|
diff --git a/computes/tests/test_capacity.py b/computes/tests/test_capacity.py
index 749f18ad..785a7ad3 100644
--- a/computes/tests/test_capacity.py
+++ b/computes/tests/test_capacity.py
@@ -89,6 +89,21 @@ class ComputesPageTests(TestCase):
self.assertEqual(more.xpath(".//div[@class='small']/text()"), ["backup", "iso", "nfs"])
+class SingularTests(TestCase):
+ def test_one_vcpu_on_one_cpu_is_singular(self):
+ admin = get_user_model().objects.create_superuser("cap-one", "one@example.com", "pw")
+ self.client.force_login(admin)
+ c = Compute.objects.create(name="host-one", hostname="192.0.2.1", login="u", password="p", type=1)
+ given = {"cpus": 1, "memory": 4 * GIB, "vcpus": {"all": 1, "running": 1},
+ "assigned": {"all": GIB, "running": GIB}, "ratio": 1.0, "pools": []}
+ with patch.object(Compute, "capacity", new=given), patch.object(Compute, "status", new=True):
+ page = html.fromstring(self.client.get(reverse("computes")).content)
+ line = self.client.get(reverse("compute_capacity", args=[c.id])).content.decode()
+ (cell,) = page.xpath("//tbody/tr/td[2]")
+ self.assertIn("1 vCPU on 1 CPU", " ".join(cell.text_content().split()))
+ self.assertEqual(" ".join(line.split()), "Given to VMs: 1 vCPU (1.0:1), 1.0 GB memory.")
+
+
class NewVmDialogLineTests(TestCase):
"""The new-VM dialog loads one line per host when it opens."""
|