Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Management command to be run from cron and send email alerts about ex…
…piring domains
- Loading branch information
1 parent
a6c490d
commit e6b867e
Showing
3 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from domaintools.models import Domain | ||
|
||
|
||
ALERT_SEND_DAYS = [14, 3, 1] | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Sends notifications by email when domains are going to expire.' | ||
|
||
def handle(self, *args, **options): | ||
for domain in Domain.objects.all(): | ||
days_remaining = domain.days_remaining() | ||
if days_remaining < max(ALERT_SEND_DAYS): | ||
print 'Domain {} expires in {} days'.format(domain.id, domain.days_remaining()) | ||
if days_remaining in ALERT_SEND_DAYS: | ||
send_mail('Domain Expiring: {}'.format(domain.id), | ||
'The domain {} is going to expire on {} ({} days)'.format(domain.id, domain.expiry_date, days_remaining), | ||
'webmaster@epixstudios.co.uk', | ||
[admin[1] for admin in settings.ADMINS]) |