Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/css/card.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions squarelet/core/tests/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down Expand Up @@ -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 <strong>100+ additional requests</strong> "
"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))

Expand Down
32 changes: 17 additions & 15 deletions squarelet/core/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions squarelet/templates/organizations/includes/usage_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h4>{% trans "Monthly" %} {{ resource }}s</h4>
{{ stats.used_monthly|intcomma }} / {{ stats.allowance_monthly|intcomma }} {% trans "used" %}
</span>
{% else %}
<h4>{{ resource|title }}s</h4>
<h4>{{ resource|capfirst }}s</h4>
{% endif %}
</div>
{% if stats.allowance_monthly %}
Expand All @@ -36,11 +36,7 @@ <h4>{{ resource|title }}s</h4>
{{ subject }} <strong>{{ amount }} {{ resource }}s</strong> that never expire.
{% endblocktrans %}
{% endif %}
{% if stats.available_inherited > 100 %}
{% blocktrans trimmed with resource=resource subject=subject pronoun=pronoun %}
{{ subject }} <strong>100+ additional {{ resource }}s</strong> 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 }} <strong>{{ amount }} additional {{ resource }}</strong> from {{ pronoun }} organization memberships.
{% plural %}
Expand Down
Loading