Skip to content

Commit

Permalink
Merge pull request #233 from fasrc/cp_uifixes
Browse files Browse the repository at this point in the history
add allocation usage, remove project attrs from projectdetail page
  • Loading branch information
claire-peters authored Jun 27, 2023
2 parents 374699a + 1569a35 commit 79525d9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
20 changes: 15 additions & 5 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from enum import Enum

from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.db import models
from django.db.models import Q
from django.utils.html import mark_safe
Expand Down Expand Up @@ -136,17 +136,27 @@ def save(self, *args, **kwargs):

@property
def size(self):
return self.allocationattribute_set.get(allocation_attribute_type_id=1).value
try:
return self.allocationattribute_set.get(allocation_attribute_type_id=1).value
except ObjectDoesNotExist:
return None


@property
def usage(self):
return self.allocationattribute_set.get(allocation_attribute_type_id=1).allocationattributeusage.value
try:
return self.allocationattribute_set.get(
allocation_attribute_type_id=1
).allocationattributeusage.value
except ObjectDoesNotExist:
return None

@property
def path(self):
subdir_attribute = AllocationAttributeType.objects.get(name='Subdirectory')
attr_filter = ( Q(allocation_id=self.id) &
Q(allocation_attribute_type_id=subdir_attribute.pk))
attr_filter = (
Q(allocation_id=self.id) & Q(allocation_attribute_type_id=subdir_attribute.pk)
)
if AllocationAttribute.objects.filter(attr_filter):
return AllocationAttribute.objects.get(attr_filter).value
return ''
Expand Down
15 changes: 13 additions & 2 deletions coldfront/core/allocation/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.test import TestCase

from coldfront.core.test_helpers.factories import setup_models
from coldfront.core.test_helpers.factories import setup_models, AllocationFactory

UTIL_FIXTURES = [
"coldfront/core/test_helpers/test_data/test_fixtures/ifx.json",
Expand All @@ -19,7 +19,18 @@ def setUpTestData(cls):

def test_allocation_str(self):
"""test that allocation str method returns correct string"""
allocation_str = '%s (%s)' % (self.proj_allocation.get_parent_resource.name, self.proj_allocation.project.pi)
allocation_str = '%s (%s)' % (
self.proj_allocation.get_parent_resource.name,
self.proj_allocation.project.pi
)

self.assertEqual(str(self.proj_allocation), allocation_str)

def test_allocation_usage_property(self):
"""Test that allocation usage property displays correctly"""
self.assertEqual(self.proj_allocation.usage, 10)

def test_allocation_usage_property_na(self):
"""Create allocation with no usage. Usage property should return None"""
allocation = AllocationFactory()
self.assertIsNone(allocation.usage)
8 changes: 5 additions & 3 deletions coldfront/core/project/templates/project/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ <h3 class="d-inline"><i class="fas fa-file-invoice-dollar" aria-hidden="true"></
<th scope="col">Resource Type</th>
<th scope="col">Location</th>
<th scope="col">User Count</th>
<th scope="col">Total Space (TB)</th>
<th scope="col">Space (TB)</th>
<th scope="col">Used (TB)</th>
<th scope="col">Monthly Cost</th>
<th scope="col" class="nosort">Actions</th>
</tr>
Expand All @@ -111,6 +112,7 @@ <h3 class="d-inline"><i class="fas fa-file-invoice-dollar" aria-hidden="true"></
<td>{{ allocation.path }}</td>
<td>{{ allocation.allocationuser_set.count }}</td>
<td>{{ allocation.size|floatformat:1 }}</td>
<td>{{ allocation.usage|floatformat:1 }}</td>
<td>${{allocation.cost|floatformat:2 }}</td>
<td>
<a href="{% url 'allocation-detail' allocation.pk %}">
Expand Down Expand Up @@ -337,6 +339,7 @@ <h3 class="d-inline" id="users"><i class="fas fa-users" aria-hidden="true"></i>
</div>
<!-- End Project Users -->

{% comment %}
<!-- Start Project Attributes -->
<div class="card mb-3">
<div class="card-header">
Expand Down Expand Up @@ -414,14 +417,12 @@ <h3 class="d-inline" id="grants"><i class="fas fa-trophy" aria-hidden="true"></i
<span class="badge badge-info">Last Updated: {{project.latest_grant.modified|date:"M. d, Y"}}</span>
{% endif %}

{% comment %}
{% if project.status.name != 'Archived' and is_allowed_to_update_project %}
<a class="btn btn-success" href="{% url 'grant-create' project.id %}" role="button"><i class="fas fa-plus" aria-hidden="true"></i> Add Grant</a>
{% if grants %}
<a class="btn btn-danger" href="{% url 'grant-delete-grants' project.pk %}" role="button"><i class="fas fa-minus" aria-hidden="true"></i> Delete Grants</a>
{% endif %}
{% endif %}
{% endcomment %}

</div>
</div>
Expand Down Expand Up @@ -563,6 +564,7 @@ <h3 class="d-inline" id="research_outputs"><i class="far fa-newspaper" aria-hidd
</div>
<!-- End Project ResearchOutputs -->

{% endcomment %}

<!-- Start Admin Messages -->
{% note_table request.user 'project-note-add' project %}
Expand Down
14 changes: 7 additions & 7 deletions coldfront/core/project/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def test_projectdetail_edituser_button_visibility(self):
utils.page_does_not_contain_for_user(self, self.project_user, self.url, 'fa-user-edit') # non-manager user cannot see edit button


def test_projectdetail_addattribute_button_visibility(self):
"""Test visibility of project detail add attribute button to different projectuser levels"""
utils.page_contains_for_user(self, self.admin_user, self.url, 'Add Attribute') # admin can see add attribute button

utils.page_does_not_contain_for_user(self, self.pi_user, self.url, 'Add Attribute') # pi cannot see add attribute button

utils.page_does_not_contain_for_user(self, self.project_user, self.url, 'Add Attribute') # non-manager user cannot see add attribute button
# def test_projectdetail_addattribute_button_visibility(self):
# """Test visibility of project detail add attribute button to different projectuser levels"""
# utils.page_contains_for_user(self, self.admin_user, self.url, 'Add Attribute') # admin can see add attribute button
#
# utils.page_does_not_contain_for_user(self, self.pi_user, self.url, 'Add Attribute') # pi cannot see add attribute button
#
# utils.page_does_not_contain_for_user(self, self.project_user, self.url, 'Add Attribute') # non-manager user cannot see add attribute button

def test_projectdetail_addnotification_button_visibility(self):
"""Test visibility of project detail add notification button to different projectuser levels"""
Expand Down
4 changes: 2 additions & 2 deletions coldfront/core/test_helpers/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ def setup_models(test_case):
AAttributeTypeFactory(name=attribute_type)
for status in ['Pending', 'Approved', 'Denied']:
AllocationChangeStatusChoiceFactory(name=status)
for allocation_attribute_type in ['Storage Quota (TB)']:
AllocationAttributeTypeFactory(name=allocation_attribute_type, is_private=False, is_changeable=True)
for alloc_attr_type in ['Storage Quota (TB)']:
AllocationAttributeTypeFactory(name=alloc_attr_type, is_private=False, is_changeable=True)
# users
test_case.admin_user = UserFactory(username='gvanrossum', is_staff=True, is_superuser=True)
# pi is a project admin but not an AllocationUser.
Expand Down

0 comments on commit 79525d9

Please sign in to comment.