From 4b02a99879d68d0223de804b171ce96aaa1a263b Mon Sep 17 00:00:00 2001 From: Claire Peters Date: Thu, 29 Jun 2023 09:23:23 -0700 Subject: [PATCH 1/2] add sync dt values to user and allocation usage tables --- .../templates/allocation/allocation_detail.html | 6 +++++- coldfront/core/allocation/views.py | 14 ++++++++++++++ .../project/templates/project/project_detail.html | 1 + coldfront/core/project/views.py | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/coldfront/core/allocation/templates/allocation/allocation_detail.html b/coldfront/core/allocation/templates/allocation/allocation_detail.html index 4ba5e5b3f..aabe36ddd 100644 --- a/coldfront/core/allocation/templates/allocation/allocation_detail.html +++ b/coldfront/core/allocation/templates/allocation/allocation_detail.html @@ -116,7 +116,9 @@

Allocation Information

Total Usage (TB): - {{ allocation_usage_tb|floatformat:2 }} + {{ allocation_usage_tb|floatformat:2 }} + Last Synced {{user_sync_dt}} + Quota (TB): @@ -335,6 +337,8 @@

Alloc

Users in Allocation

{{allocation_users.count}} + + Last Sync: {{user_sync_dt}}
{% comment %} diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index 4f4fc8292..8650b4683 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -7,6 +7,7 @@ from dateutil.relativedelta import relativedelta from django import forms +from django.conf import settings from django.contrib import messages from django.contrib.auth import get_user_model from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin @@ -64,6 +65,9 @@ from coldfront.core.utils.common import get_domain_url, import_from_settings from coldfront.core.utils.mail import send_allocation_admin_email, send_allocation_customer_email +if 'django_q' in settings.INSTALLED_APPS: + from django_q.tasks import Task + ALLOCATION_ENABLE_ALLOCATION_RENEWAL = import_from_settings( 'ALLOCATION_ENABLE_ALLOCATION_RENEWAL', True) ALLOCATION_DEFAULT_ALLOCATION_LENGTH = import_from_settings( @@ -203,6 +207,16 @@ def get_context_data(self, **kwargs): attributes_with_usage, allocation_obj.allocationuser_set.all() ) + + if 'django_q' in settings.INSTALLED_APPS: + # get last successful runs of djangoq task responsible for allocationuser data pull + user_sync_dt = Task.objects.filter( + func__contains="pull_sf_push_cf_redash", success=True + ).order_by('started').last().started + else: + user_sync_dt = None + context['user_sync_dt'] = user_sync_dt + context['allocation_quota_bytes'] = quota_bytes context['allocation_usage_bytes'] = usage_bytes quota_tb = 0 if not quota_bytes else quota_bytes / 1099511627776 diff --git a/coldfront/core/project/templates/project/project_detail.html b/coldfront/core/project/templates/project/project_detail.html index a6721c6ed..3b660022d 100644 --- a/coldfront/core/project/templates/project/project_detail.html +++ b/coldfront/core/project/templates/project/project_detail.html @@ -247,6 +247,7 @@