Skip to content

Commit 8fa97ae

Browse files
committed
nudge PIs to submit grants and publications
new file: coldfront/core/user/management/commands/pi_grants_publications_request.py new file: coldfront/templates/email/request_to_add_grants.txt new file: coldfront/templates/email/request_to_add_publications.txt
1 parent b178563 commit 8fa97ae

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import logging
2+
import argparse
3+
4+
from django.core.management.base import BaseCommand
5+
6+
from coldfront.core.grant.models import Grant
7+
from coldfront.core.project.models import Project
8+
from coldfront.core.publication.models import Publication
9+
from coldfront.core.user.models import UserProfile
10+
from coldfront.core.utils.common import import_from_settings
11+
from coldfront.core.utils.mail import send_email_template
12+
13+
logger = logging.getLogger(__name__)
14+
15+
16+
EMAIL_SIGNATURE = import_from_settings("EMAIL_SIGNATURE")
17+
EMAIL_SENDER = import_from_settings("EMAIL_SENDER")
18+
CENTER_BASE_URL = import_from_settings("CENTER_BASE_URL")
19+
20+
21+
class Command(BaseCommand):
22+
help = "Send emails to PIs with projects that have no grants/publications associated with them"
23+
24+
def add_arguments(self, parser):
25+
parser.add_argument(
26+
"--dry-run",
27+
action=argparse.BooleanOptionalAction,
28+
default=False,
29+
help="dry run, log email content and recipients without sending the emails",
30+
)
31+
32+
def handle(self, *args, **options):
33+
dry_run: bool = options["dry_run"]
34+
for pi_profile in UserProfile.objects.filter(is_pi=True):
35+
try:
36+
logger.info(f"processing projects for PI: {pi_profile.user.username}")
37+
projects_for_pi = Project.objects.filter(pi=pi_profile.user, status__name__in=["Active", "New"])
38+
projects_without_grants = {}
39+
projects_without_publications = {}
40+
41+
for project in projects_for_pi:
42+
logger.info(f"processing project: {project}")
43+
if Grant.objects.filter(project=project).count() == 0:
44+
projects_without_grants[project.title] = f"{CENTER_BASE_URL.strip('/')}/project/{project.pk}/"
45+
46+
if Publication.objects.filter(project=project).count() == 0:
47+
projects_without_publications[project.title] = (
48+
f"{CENTER_BASE_URL.strip('/')}/project/{project.pk}/"
49+
)
50+
51+
grant_notification_context = {
52+
"pi_first_name": pi_profile.user.first_name,
53+
"project_dict": projects_without_grants,
54+
"signature": EMAIL_SIGNATURE,
55+
}
56+
logger.info(f"grant nudge context: {grant_notification_context}")
57+
if projects_without_grants and not dry_run:
58+
logger.info(f"sending grant nudge to {pi_profile.username}")
59+
send_email_template(
60+
"Please update grant info for HPC project",
61+
"email/request_to_add_grants.txt",
62+
grant_notification_context,
63+
EMAIL_SENDER,
64+
pi_profile.user.email,
65+
)
66+
67+
publication_notification_context = {
68+
"pi_first_name": pi_profile.user.first_name,
69+
"project_dict": projects_without_publications,
70+
"signature": EMAIL_SIGNATURE,
71+
}
72+
logger.info(f"publication nudge context: {publication_notification_context}")
73+
if projects_without_publications and not dry_run:
74+
logger.info(f"sending publication nudge to {pi_profile.username}")
75+
send_email_template(
76+
"Please update publication info for HPC projects",
77+
"email/request_to_add_publications.txt",
78+
publication_notification_context,
79+
EMAIL_SENDER,
80+
pi_profile.user.email,
81+
)
82+
except Exception:
83+
logger.exception("Exception occurred with traceback:", exc_info=True)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Dear {{pi_first_name}},
2+
3+
The following projects within the HPC projects portal currently have no grants associated with them:
4+
{% for project_key, project_url in project_dict.items %}
5+
Project Title: {{ project_key }}
6+
Project URL: {{ project_url }}
7+
{% endfor %}
8+
9+
Please add grants that are associated with your project(s) as it will enable us to justify the necessity of offering the HPC service.
10+
11+
Thank you,
12+
{{ signature }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Dear {{pi_first_name}},
2+
3+
Your project(s) within the HPC projects portal currently have no publications associated with them:
4+
{% for project_key, project_url in project_dict.items %}
5+
Project Title: {{ project_key }}
6+
Project URL: {{ project_url }}
7+
{% endfor %}
8+
9+
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.
10+
11+
Thank you,
12+
{{ signature }}

0 commit comments

Comments
 (0)