diff --git a/frontend/css/card.css b/frontend/css/card.css index 12ef31740..1cdbc6c9b 100644 --- a/frontend/css/card.css +++ b/frontend/css/card.css @@ -156,6 +156,8 @@ .card-item-title :is(h3, h4) { margin: 0; font-size: var(--font-md, 1rem); + font-family: var(--font-sans, "Source Sans Pro"); + font-feature-settings: "ss04" on; font-weight: 600; color: var(--gray-5, #233944); overflow-wrap: anywhere; diff --git a/squarelet/core/tests/test_usage.py b/squarelet/core/tests/test_usage.py index 10a0b9e4e..3f48fdeb5 100644 --- a/squarelet/core/tests/test_usage.py +++ b/squarelet/core/tests/test_usage.py @@ -43,6 +43,16 @@ def test_a_service_with_no_stats_is_left_out(self, services): assert list(get_usage_stats(org, [])) == [services["muckrock"].name] + def test_a_service_with_only_empty_balances_is_left_out(self, services): + org = OrganizationFactory( + client_stats={ + "muckrock": {"requests": _requests()}, + "documentcloud": {"ai_credits": {"number_ai_credits": 4}}, + } + ) + + assert list(get_usage_stats(org, [])) == [services["documentcloud"].name] + def test_an_organization_reads_its_own_balances(self, services): org = OrganizationFactory( client_stats={ @@ -215,15 +225,6 @@ def test_inherited_requests_are_attributed_to_memberships(self): "from your organization memberships." in html ) - def test_more_than_100_inherited_requests_shows_100_plus(self): - html = _card(_card_stats(inherited=1500)) - - assert ( - "This organization has 100+ additional requests " - "from its organization memberships." in html - ) - assert "1,500" not in html - def test_a_single_inherited_request_is_singular(self): html = _card(_card_stats(inherited=1)) diff --git a/squarelet/core/usage.py b/squarelet/core/usage.py index 41eefc368..771f8bd9e 100644 --- a/squarelet/core/usage.py +++ b/squarelet/core/usage.py @@ -33,24 +33,26 @@ def get_usage_stats(user_or_org, other_orgs): service_name = services[service].name if service in services else service - usage[service_name] = {} - for resource, label in resources: own = own_service.get(f"{prefix}{resource}") or {} - inherited = [stats.get(resource) or {} for stats in org_services] + inherited_stats = [stats.get(resource) or {} for stats in org_services] allowance = own.get(f"{resource}_per_month") or 0 - - usage[service_name][label] = { - "allowance_monthly": allowance, - "used_monthly": allowance - (own.get(f"monthly_{resource}") or 0), - "available_purchased": own.get(f"number_{resource}") or 0, - # Remaining monthly and purchased resource count across all orgs - "available_inherited": sum( - (org.get(f"number_{resource}") or 0) - + (org.get(f"monthly_{resource}") or 0) - for org in inherited - ), - } + used = allowance - (own.get(f"monthly_{resource}") or 0) + purchased = own.get(f"number_{resource}") or 0 + # Remaining monthly and purchased resource count across all orgs + inherited = sum( + (org.get(f"number_{resource}") or 0) + + (org.get(f"monthly_{resource}") or 0) + for org in inherited_stats + ) + + if allowance > 0 or purchased > 0 or inherited > 0: + usage.setdefault(service_name, {})[label] = { + "allowance_monthly": allowance, + "used_monthly": used, + "available_purchased": purchased, + "available_inherited": inherited, + } return usage diff --git a/squarelet/templates/organizations/includes/usage_card.html b/squarelet/templates/organizations/includes/usage_card.html index 4806305c7..5f3208319 100644 --- a/squarelet/templates/organizations/includes/usage_card.html +++ b/squarelet/templates/organizations/includes/usage_card.html @@ -16,7 +16,7 @@

{% trans "Monthly" %} {{ resource }}s

{{ stats.used_monthly|intcomma }} / {{ stats.allowance_monthly|intcomma }} {% trans "used" %} {% else %} -

{{ resource|title }}s

+

{{ resource|capfirst }}s

{% endif %} {% if stats.allowance_monthly %} @@ -36,11 +36,7 @@

{{ resource|title }}s

{{ subject }} {{ amount }} {{ resource }}s that never expire. {% endblocktrans %} {% endif %} - {% if stats.available_inherited > 100 %} - {% blocktrans trimmed with resource=resource subject=subject pronoun=pronoun %} - {{ subject }} 100+ additional {{ resource }}s from {{ pronoun }} organization memberships. - {% endblocktrans %} - {% elif stats.available_inherited %} + {% if stats.available_inherited %} {% blocktrans trimmed count counter=stats.available_inherited with amount=stats.available_inherited|intcomma resource=resource subject=subject pronoun=pronoun %} {{ subject }} {{ amount }} additional {{ resource }} from {{ pronoun }} organization memberships. {% plural %}