Skip to content

Commit

Permalink
Only send emails if semester end is within 3 months.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fingel committed Jul 30, 2019
1 parent e0a61b6 commit 4918b4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
23 changes: 13 additions & 10 deletions observation_portal/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,19 @@ def add_users(self, emails, role):
logger.info('Users added to proposal {0}: {1}'.format(self, emails))

def send_time_allocation_reminder(self):
subject = _('Your LCO Time Allocation Summary')
message = render_to_string(
'proposals/timeallocationreminder.html',
{
'proposal': self,
'allocations': self.timeallocation_set.filter(semester=self.current_semester)
}
)

send_mail.send(subject, message, 'science-support@lco.global', [self.pi.email])
if self.pi:
subject = _('Your LCO Time Allocation Summary')
message = render_to_string(
'proposals/timeallocationreminder.html',
{
'proposal': self,
'allocations': self.timeallocation_set.filter(semester=self.current_semester)
}
)

send_mail.send(subject, message, 'science-support@lco.global', [self.pi.email])
else:
logger.warn('Proposal {} does not have a PI!'.format(self))

def __str__(self):
return self.id
Expand Down
8 changes: 5 additions & 3 deletions observation_portal/proposals/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils import timezone
import dramatiq
import logging

Expand All @@ -9,8 +10,9 @@
@dramatiq.actor()
def time_allocation_reminder():
for proposal in Proposal.current_proposals().filter(active=True):
if proposal.pi:
# Only send an email if we are within 3 months of the end of the semester
# and the proposal has at least one allocation.
if (proposal.current_semester.end - timezone.now()).days <= 93 and \
proposal.timeallocation_set.count() > 0:
logger.info('Sending time allocation reminder for {}'.format(proposal))
proposal.send_time_allocation_reminder()
else:
logger.warn('Proposal {} does not have a PI!'.format(proposal))

0 comments on commit 4918b4e

Please sign in to comment.