From 250a1f04754bdd8ee072322071c4e260a42f39d2 Mon Sep 17 00:00:00 2001 From: Chris Barnett Date: Mon, 15 Sep 2025 13:56:01 -0400 Subject: [PATCH] cast "total_amount_awarded" to FloatField before Sum applied added simple test to show that center-summary renders Signed-off-by: Chris Barnett --- coldfront/core/portal/tests/test_views.py | 35 +++++++++++++++++++++++ coldfront/core/portal/views.py | 7 +++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 coldfront/core/portal/tests/test_views.py diff --git a/coldfront/core/portal/tests/test_views.py b/coldfront/core/portal/tests/test_views.py new file mode 100644 index 0000000000..8cad2fd30d --- /dev/null +++ b/coldfront/core/portal/tests/test_views.py @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: (C) ColdFront Authors +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +import logging + +from django.test import TestCase + +logging.disable(logging.CRITICAL) + + +class PortalViewBaseTest(TestCase): + """Base class for portal view tests.""" + + @classmethod + def setUpTestData(cls): + """Test Data setup for all portal view tests.""" + pass + + +class CenterSummaryViewTest(PortalViewBaseTest): + """Tests for center summary view""" + + @classmethod + def setUpTestData(cls): + """Set up users and project for testing""" + cls.url = "/center-summary" + super(PortalViewBaseTest, cls).setUpTestData() + + def test_centersummary_renders(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Active Allocations and Users") + self.assertContains(response, "Resources and Allocations Summary") + self.assertNotContains(response, "We're having a bit of system trouble at the moment. Please check back soon!") diff --git a/coldfront/core/portal/views.py b/coldfront/core/portal/views.py index 7effdf07ea..63a81004e3 100644 --- a/coldfront/core/portal/views.py +++ b/coldfront/core/portal/views.py @@ -7,7 +7,8 @@ from django.conf import settings from django.contrib.humanize.templatetags.humanize import intcomma -from django.db.models import Count, Q, Sum +from django.db.models import Count, FloatField, Q, Sum +from django.db.models.functions import Cast from django.shortcuts import render from django.views.decorators.cache import cache_page @@ -137,7 +138,9 @@ def center_summary(request): # Grants Card total_grants_by_agency_sum = list( - Grant.objects.values("funding_agency__name").annotate(total_amount=Sum("total_amount_awarded")) + Grant.objects.values("funding_agency__name").annotate( + total_amount=Sum(Cast("total_amount_awarded", FloatField())) + ) ) total_grants_by_agency_count = list(