Skip to content

Commit

Permalink
add fairshare to user table
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Nov 17, 2023
1 parent e94085a commit 3c145b3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ def handle(self, *args, **options):
for choice in ('Active', 'Error', 'Removed', ):
AllocationUserStatusChoice.objects.get_or_create(name=choice)

for name, attribute_type, is_private, is_changeable in (
('Fairshare', 'Int', False, True)
for name, attribute_type, is_private in (
('Fairshare', 'Int', False)
):
AllocationUserAttributeType.objects.update_or_create(
name=name,
defaults={
'attribute_type': AttributeType.objects.get(name=attribute_type),
'is_private': is_private,
'is_changeable': is_changeable,
}
)

Expand Down
27 changes: 27 additions & 0 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,33 @@ class Meta:
verbose_name_plural = 'Allocation User Status'
unique_together = ('user', 'allocation')

def get_attribute(self, name, expand=True, typed=True,
extra_allocations=[]):
"""
Params:
name (str): name of the allocation attribute type
expand (bool): indicates whether or not to return the expanded value with attributes/parameters for attributes with a base type of 'Attribute Expanded Text'
typed (bool): indicates whether or not to convert the attribute value to an int/ float/ str based on the base AttributeType name
extra_allocations (list[Allocation]): allocations which are available to reference in the attribute list in addition to those associated with this AllocationAttribute
Returns:
str: the value of the first attribute found for this allocation with the specified name
"""

attr = self.allocationuserattribute_set.filter(
allocation_attribute_type__name=name).first()
if attr:
if expand:
return attr.expanded_value(
extra_allocations=extra_allocations, typed=typed)
if typed:
return attr.typed_value()
return attr.value
return None

@property
def fairshare(self):
return self.get_attribute('Fairshare')


class AllocationUserAttributeType(TimeStampedModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ <h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Al
<th scope="col">Percentage Usage</th>
{% if "Storage" in allocation.get_parent_resource.resource_type.name %}
<th scope="col">Cost Per User (TB/month)</th>
{% else %}
<th scope="col">Fairshare</th>
{% endif %}
<!-- <th scope="col">Status</th> -->
<!-- <th scope="col">Last Modified</th> -->
Expand Down Expand Up @@ -493,11 +495,13 @@ <h3 class="d-inline"><i class="fas fa-users" aria-hidden="true"></i> Users in Al
<td>{{userusage|div:allocationusage|mul:100|floatformat:2 }}%</td>
{% endif %}

{% if user.unit != "CPU Hours" %}
{% if "Storage" in allocation.get_parent_resource.resource_type.name %}
{% cost_bytes userusage as cost %}
{% if cost %}
<td>{{ cost }}</td>
{% endif %}
{% else %}
<td>user.fairshare</td>
{% endif %}
</tr>
{% endfor %}
Expand Down

0 comments on commit 3c145b3

Please sign in to comment.