Skip to content

Commit 57d0cd5

Browse files
authored
Merge pull request #794 from Tufts-Technology-Services/bug-fix-grant-sum-summary
fix issue 793: Sum of char field
2 parents 4613f8e + 250a1f0 commit 57d0cd5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: (C) ColdFront Authors
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
import logging
6+
7+
from django.test import TestCase
8+
9+
logging.disable(logging.CRITICAL)
10+
11+
12+
class PortalViewBaseTest(TestCase):
13+
"""Base class for portal view tests."""
14+
15+
@classmethod
16+
def setUpTestData(cls):
17+
"""Test Data setup for all portal view tests."""
18+
pass
19+
20+
21+
class CenterSummaryViewTest(PortalViewBaseTest):
22+
"""Tests for center summary view"""
23+
24+
@classmethod
25+
def setUpTestData(cls):
26+
"""Set up users and project for testing"""
27+
cls.url = "/center-summary"
28+
super(PortalViewBaseTest, cls).setUpTestData()
29+
30+
def test_centersummary_renders(self):
31+
response = self.client.get(self.url)
32+
self.assertEqual(response.status_code, 200)
33+
self.assertContains(response, "Active Allocations and Users")
34+
self.assertContains(response, "Resources and Allocations Summary")
35+
self.assertNotContains(response, "We're having a bit of system trouble at the moment. Please check back soon!")

coldfront/core/portal/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from django.conf import settings
99
from django.contrib.humanize.templatetags.humanize import intcomma
10-
from django.db.models import Count, Q, Sum
10+
from django.db.models import Count, FloatField, Q, Sum
11+
from django.db.models.functions import Cast
1112
from django.shortcuts import render
1213
from django.views.decorators.cache import cache_page
1314

@@ -137,7 +138,9 @@ def center_summary(request):
137138

138139
# Grants Card
139140
total_grants_by_agency_sum = list(
140-
Grant.objects.values("funding_agency__name").annotate(total_amount=Sum("total_amount_awarded"))
141+
Grant.objects.values("funding_agency__name").annotate(
142+
total_amount=Sum(Cast("total_amount_awarded", FloatField()))
143+
)
141144
)
142145

143146
total_grants_by_agency_count = list(

0 commit comments

Comments
 (0)