Skip to content

Commit

Permalink
templatefix
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Nov 16, 2023
1 parent 3af6551 commit 504bd0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ <h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Al
<th scope="col">Status</th>
<th scope="col">Logical Usage</th>
<th scope="col">Percentage Usage</th>
<th scope="col">Cost Per User (TB/month)</th>
{% if "Storage" in allocation.get_parent_resource.resource_type.name %}
<th scope="col">Cost Per User (TB/month)</th>
{% endif %}
<!-- <th scope="col">Status</th> -->
<!-- <th scope="col">Last Modified</th> -->
</tr>
Expand All @@ -462,7 +464,7 @@ <h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Al
<tbody>
{% for user in allocation_users %}
{% if user.unit == "CPU Hours" %}
{% firstof user.usage_bytes as userusage %}
{% firstof user.usage as userusage %}
{% firstof allocation.usage as allocationusage %}
{% else %}
{% firstof user.usage_bytes as userusage %}
Expand All @@ -482,13 +484,18 @@ <h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Al
{% if userusage is None %}
0 {{ user.unit }}
{% else %}
{{ user.usage|floatformat:1 }}{{ user.unit }}
{{ user.usage|floatformat:1 }} {{ user.unit }}
{% endif %}
</td>
{% if allocationusage == None or allocationusage == 0 %}
<td>0</td>
{% else %}
<td>{{userusage|div:allocationusage|mul:100|floatformat:2 }}%</td>
{% if user.unit == "CPU Hours" %}
<td>{{userusage|div:allocation.size|mul:100|floatformat:2 }}%</td>
{% else %}
<td>{{userusage|div:allocationusage|mul:100|floatformat:2 }}%</td>
{% endif %}

{% endif %}
{% if user.unit == "CPU Hours" %}
{% cost_cpuhours userusage as cost %}
Expand Down
6 changes: 3 additions & 3 deletions coldfront/core/utils/templatetags/fasrc_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@register.simple_tag(takes_context=True)
def cost_bytes(context, amount):
a_price = get_resource_rate(context['allocation'].get_resources_as_string)
amount_tb = amount / 1099511627776
amount_tb = int(amount) / 1099511627776
if a_price:
return "${:,.2f}".format(a_price * amount_tb)
return None
Expand All @@ -21,6 +21,6 @@ def cost_tb(context, amount):
@register.simple_tag(takes_context=True)
def cost_cpuhours(context, amount):
a_price = get_resource_rate(context['allocation'].get_resources_as_string)
if a_price:
return "${:,.2f}".format(float(a_price) * amount)
if amount and a_price:
return "${:,.2f}".format(float(a_price) * float(amount))
return None

0 comments on commit 504bd0e

Please sign in to comment.