diff --git a/Containerfile.debugpy b/Containerfile.debugpy index 528eb50240..0d9862fffe 100644 --- a/Containerfile.debugpy +++ b/Containerfile.debugpy @@ -21,6 +21,7 @@ ENV PYTHONUNBUFFERED=1 ENV PLUGIN_SLURM=True ENV PLUGIN_XDMOD=True ENV PLUGIN_API=True +ENV EMAIL_ENABLED=True ENV XDMOD_API_URL="localhost" EXPOSE 8000 EXPOSE 5678 diff --git a/coldfront/core/user/management/commands/pi_grants_publications_request.py b/coldfront/core/user/management/commands/pi_grants_publications_request.py new file mode 100644 index 0000000000..22c7a2dfe5 --- /dev/null +++ b/coldfront/core/user/management/commands/pi_grants_publications_request.py @@ -0,0 +1,83 @@ +import argparse +import logging + +from django.core.management.base import BaseCommand + +from coldfront.core.grant.models import Grant +from coldfront.core.project.models import Project +from coldfront.core.publication.models import Publication +from coldfront.core.user.models import UserProfile +from coldfront.core.utils.common import import_from_settings +from coldfront.core.utils.mail import send_email_template + +logger = logging.getLogger(__name__) + + +EMAIL_SIGNATURE = import_from_settings("EMAIL_SIGNATURE") +EMAIL_SENDER = import_from_settings("EMAIL_SENDER") +CENTER_BASE_URL = import_from_settings("CENTER_BASE_URL") + + +class Command(BaseCommand): + help = "Send emails to PIs with projects that have no grants/publications associated with them" + + def add_arguments(self, parser): + parser.add_argument( + "--dry-run", + action=argparse.BooleanOptionalAction, + default=False, + help="dry run, log email content and recipients without sending the emails", + ) + + def handle(self, *args, **options): + dry_run: bool = options["dry_run"] + for pi_profile in UserProfile.objects.filter(is_pi=True): + try: + logger.info(f"processing projects for PI: {pi_profile.user.username}") + projects_for_pi = Project.objects.filter(pi=pi_profile.user, status__name__in=["Active", "New"]) + projects_without_grants = {} + projects_without_publications = {} + + for project in projects_for_pi: + logger.info(f"processing project: {project}") + if Grant.objects.filter(project=project).count() == 0: + projects_without_grants[project.title] = f"{CENTER_BASE_URL.strip('/')}/project/{project.pk}/" + + if Publication.objects.filter(project=project).count() == 0: + projects_without_publications[project.title] = ( + f"{CENTER_BASE_URL.strip('/')}/project/{project.pk}/" + ) + + grant_notification_context = { + "pi_first_name": pi_profile.user.first_name, + "project_dict": projects_without_grants, + "signature": EMAIL_SIGNATURE, + } + logger.info(f"grant nudge context: {grant_notification_context}") + if projects_without_grants and not dry_run: + logger.info(f"sending grant nudge to {pi_profile.user.username}") + send_email_template( + "Please update grant info for HPC project", + "email/request_to_add_grants.txt", + grant_notification_context, + EMAIL_SENDER, + pi_profile.user.email, + ) + + publication_notification_context = { + "pi_first_name": pi_profile.user.first_name, + "project_dict": projects_without_publications, + "signature": EMAIL_SIGNATURE, + } + logger.info(f"publication nudge context: {publication_notification_context}") + if projects_without_publications and not dry_run: + logger.info(f"sending publication nudge to {pi_profile.user.username}") + send_email_template( + "Please update publication info for HPC projects", + "email/request_to_add_publications.txt", + publication_notification_context, + EMAIL_SENDER, + pi_profile.user.email, + ) + except Exception: + logger.exception("Exception occurred with traceback:", exc_info=True) diff --git a/coldfront/templates/email/request_to_add_grants.txt b/coldfront/templates/email/request_to_add_grants.txt new file mode 100644 index 0000000000..0e5180b21b --- /dev/null +++ b/coldfront/templates/email/request_to_add_grants.txt @@ -0,0 +1,12 @@ +Dear {{pi_first_name}}, + +The following projects within the HPC projects portal currently have no grants associated with them: +{% for project_key, project_url in project_dict.items %} + Project Title: {{ project_key }} + Project URL: {{ project_url }} +{% endfor %} + +Please add grants that are associated with your project(s) as it will enable us to justify the necessity of offering the HPC service. + +Thank you, +{{ signature }} diff --git a/coldfront/templates/email/request_to_add_publications.txt b/coldfront/templates/email/request_to_add_publications.txt new file mode 100644 index 0000000000..d0aa5534fc --- /dev/null +++ b/coldfront/templates/email/request_to_add_publications.txt @@ -0,0 +1,12 @@ +Dear {{pi_first_name}}, + +Your project(s) within the HPC projects portal currently have no publications associated with them: +{% for project_key, project_url in project_dict.items %} + Project Title: {{ project_key }} + Project URL: {{ project_url }} +{% endfor %} + +Please add publications that have resulted from the use of HPC resources for this project as it will enable us to justify the necessity of offering the HPC service. + +Thank you, +{{ signature }}