Skip to content

Commit

Permalink
Update allocations admin list with more info
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Powers committed Dec 4, 2024
1 parent d8367c0 commit b8fab2c
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions allocations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class ChargeInline(admin.TabularInline):


class AllocationAdmin(admin.ModelAdmin):
def project_description(self, obj):
return str(obj.project.description)

def project_title(self, obj):
return str(obj.project.title)

def pi_name(self, obj):
return f"{obj.project.pi.first_name} {obj.project.pi.last_name}"

def pi_email(self, obj):
return f"{obj.project.pi.email}"

def pi_info(self, obj):
keycloak_client = KeycloakClient()
kc_user = keycloak_client.get_user_by_username(obj.project.pi.username)
Expand Down Expand Up @@ -302,12 +305,34 @@ def previous_allocations(self, obj):
"""
)

def alloc_count(self, obj):
return obj.project.allocations.count()

def last_su_used(self, obj):
"""Either su used for this alloc, if it isn't pending,
or the previous allocs su_used
"""
prev_used = None
if obj.status == "pending":
allocs = obj.project.allocations.all().order_by("-date_requested")
if len(allocs) > 1:
balance = su_calculators.project_balances([allocs[1].project.id])[0]
prev_used = balance["total"]
else:
balance = su_calculators.project_balances([obj.project.id])[0]
prev_used = balance["total"]
return prev_used

list_display = (
"date_requested",
"pi_name",
"pi_email",
"project",
"project_title",
"alloc_count",
"status",
"date_requested",
"date_reviewed",
"reviewer",
"last_su_used",
"justification",
)
fieldsets = (
(
Expand Down

0 comments on commit b8fab2c

Please sign in to comment.