membershipworks: Slightly simplify admin task "last run time" logic

This commit is contained in:
Adam Goldsmith 2024-01-17 11:19:32 -05:00
parent 1fe097ca86
commit 27c705668c

View File

@ -36,14 +36,14 @@ class BaseMembershipWorksAdmin(DjangoObjectActions, ReadOnlyAdmin):
def _get_tool_dict(self, tool_name):
tool = super(DjangoObjectActions, self)._get_tool_dict(tool_name)
if tool_name == "refresh_membershipworks_data":
last_run = (
try:
last_run_time = naturaltime(
Task.objects.filter(group="Scrape Data from MembershipWorks")
.order_by("started")
.last()
)
last_run_time = (
naturaltime(last_run.started) if last_run is not None else "Never"
.values_list("started", flat=True)
.latest("started")
)
except Task.DoesNotExist:
last_run_time = "Never"
tool["label"] = f"Refresh Data [Last Run {last_run_time}]"
return tool