Skip to content

Commit

Permalink
Merge pull request #261 from fasrc/cp_allocationrequest_email_reminders
Browse files Browse the repository at this point in the history
allocationrequest and allocationchangerequest email reminders
  • Loading branch information
claire-peters authored Oct 26, 2023
2 parents 3d3e243 + 49691d8 commit acaa9d3
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 121 deletions.
5 changes: 4 additions & 1 deletion coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def has_perm(self, user, perm):
def __str__(self):
tmp = self.get_parent_resource
if tmp is None:
return 'no parent resource'
return '%s' % (self.project.pi)
return '%s (%s)' % (self.get_parent_resource.name, self.project.pi)

class AllocationAdminNote(TimeStampedModel):
Expand Down Expand Up @@ -740,6 +740,9 @@ def get_parent_resource(self):
return self.allocation.resources.filter(is_allocatable=True).first()

def __str__(self):
tmp = self.get_parent_resource
if tmp is None:
return '(%s)' % (self.allocation.project.pi)
return '%s (%s)' % (self.get_parent_resource.name, self.allocation.project.pi)

class AllocationAttributeChangeRequest(TimeStampedModel):
Expand Down
281 changes: 166 additions & 115 deletions coldfront/core/allocation/tasks.py

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions coldfront/core/allocation/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

from django.test import TestCase

from django.utils import timezone

from coldfront.core.allocation.models import AllocationStatusChoice
from coldfront.core.test_helpers.factories import (
setup_models,
AllocationFactory,
AllocationChangeRequestFactory,
)
from coldfront.core.allocation.tasks import send_request_reminder_emails

UTIL_FIXTURES = [
"coldfront/core/test_helpers/test_data/test_fixtures/ifx.json",
]

class RequestReminderEmails(TestCase):

fixtures = UTIL_FIXTURES

def setUp(self):
"""set up test data"""
setup_models(self)

# create Allocations with status "new" and "created" dates of 5, 7, and 9 days ago
self.allocation1 = AllocationFactory(
status=AllocationStatusChoice.objects.get(name="New"),
created=timezone.now() - timezone.timedelta(days=5),
)
self.allocation2 = AllocationFactory(
status=AllocationStatusChoice.objects.get(name="New"),
created=timezone.now() - timezone.timedelta(days=7)
)
self.allocation3 = AllocationFactory(
status=AllocationStatusChoice.objects.get(name="New"),
created=timezone.now() - timezone.timedelta(days=9)
)

# create AllocationChangeRequests with status "pending" and "created" dates of 5, 7, and 9 days ago
self.acr1 = AllocationChangeRequestFactory(
created=timezone.now() - timezone.timedelta(days=5),
)
self.acr2 = AllocationChangeRequestFactory(
created=timezone.now() - timezone.timedelta(days=7)
)
self.acr3 = AllocationChangeRequestFactory(
created=timezone.now() - timezone.timedelta(days=9)
)

def test_send_request_reminder_emails(self):
"""test send_request_reminder_emails task"""
pending_changerequests, pending_allocations = send_request_reminder_emails()
14 changes: 11 additions & 3 deletions coldfront/core/utils/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ def build_link(url_path, domain_url=''):
def send_admin_email_template(subject, template_name, template_context):
"""Helper function for sending admin emails using a template
"""
send_email_template(subject, template_name, template_context, EMAIL_SENDER, [EMAIL_TICKET_SYSTEM_ADDRESS,])
send_email_template(
subject, template_name, template_context, EMAIL_SENDER, [EMAIL_TICKET_SYSTEM_ADDRESS,]
)


def send_allocation_admin_email(allocation_obj, subject, template_name, url_path='', domain_url='', other_vars=None):
def send_allocation_admin_email(
allocation_obj, subject, template_name,
url_path='', domain_url='', other_vars=None
):
"""Send allocation admin emails
"""
if not url_path:
Expand All @@ -118,7 +123,10 @@ def send_allocation_admin_email(allocation_obj, subject, template_name, url_path
ctx,
)

def send_allocation_customer_email(allocation_obj, subject, template_name, url_path='', domain_url=''):
def send_allocation_customer_email(
allocation_obj, subject, template_name,
url_path='', domain_url=''
):
"""Send allocation customer emails
"""
if not url_path:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ def handle(self, *args, **options):
next_run=date,
schedule_type=Schedule.DAILY,
**kwargs)

if f'coldfront.core.allocation.tasks.send_request_reminder_emails' not in scheduled:
schedule(
f'coldfront.core.allocation.tasks.send_request_reminder_emails',
next_run=date,
schedule_type=Schedule.WEEKLY,
**kwargs
)
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def handle(self, *args, **options):
'status': AllocationUserStatusChoice.objects.get(name='Active')}
)
except ValidationError:
logger.debug('adding PI %s to allocation %s failed', pi_obj.pi.username, allocation.pk)
logger.debug('adding PI %s to allocation %s failed', pi_obj.username, allocation.pk)
created = None
if created:
print('PI added: ' + project_obj.pi.username)
print('PI added: ' + pi_obj.username)
missing_projects = [{'title': title} for title in command_report['missing_projects']]
if not added_allocations_df.empty:
added_allocations_df['billing_code'] = None
Expand Down
13 changes: 13 additions & 0 deletions coldfront/templates/email/pending_allocation_changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This is a notice about pending allocation change requests on Coldfront that are
at least a week old:
---------------------
{% for change_request, change_attrs in pending_changerequests.items %}
Allocation: {{change_request.allocation}}

Requested changes:
{% for change_attr in change_attrs %}
{{change_attr.allocation_attribute.allocation_attribute_type.name}} - change to {{change_attr.new_value}}
{% endfor %}
Change it here: {{url_base}}{{change_request.pk}}/
---------------------
{% endfor %}
8 changes: 8 additions & 0 deletions coldfront/templates/email/pending_allocations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is a notice about pending allocation requests on Coldfront that are at
least a week old:
---------------------
{% for allocation in pending_allocations %}
Allocation: {{allocation}}
Review the request here: {{url_base}}{{allocation.pk}}/
---------------------
{% endfor %}

0 comments on commit acaa9d3

Please sign in to comment.