forked from dbca-wa/ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from gaiaresources/1845-renewal-sent-flag
Added renewal_sent flag to licences
- Loading branch information
Showing
11 changed files
with
106 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
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
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,29 @@ | ||
from datetime import date, timedelta | ||
|
||
from django_cron import CronJobBase, Schedule | ||
|
||
from wildlifelicensing.apps.main.models import WildlifeLicence | ||
from wildlifelicensing.apps.main.emails import send_licence_renewal_email_notification | ||
|
||
|
||
class CheckLicenceRenewalsCronJob(CronJobBase): | ||
RUN_AT_TIMES = ['00:00'] | ||
LICENCE_RENEWAL_NOTIFICATION_DAYS = 30 | ||
|
||
schedule = Schedule(run_at_times=RUN_AT_TIMES) | ||
code = 'main.check_licence_renewals' | ||
|
||
def do(self): | ||
expiry_notification_date = date.today() + timedelta(days=self.LICENCE_RENEWAL_NOTIFICATION_DAYS) | ||
|
||
renewal_conditions = { | ||
'end_date__lte': expiry_notification_date, | ||
'is_renewable': True, | ||
'renewal_sent': False, | ||
'replaced_by__isnull': True | ||
} | ||
|
||
for licence in WildlifeLicence.objects.filter(**renewal_conditions): | ||
if send_licence_renewal_email_notification(licence): | ||
licence.renewal_sent = True | ||
licence.save() |
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,19 @@ | ||
from wildlifelicensing.apps.emails.emails import TemplateEmailBase, host_reverse | ||
|
||
|
||
class LicenceRenewalNotificationEmail(TemplateEmailBase): | ||
subject = 'Your wildlife licence is due for renewal.' | ||
html_template = 'wl/emails/renew_licence_notification.html' | ||
txt_template = 'wl/emails/renew_licence_notification.txt' | ||
|
||
|
||
def send_licence_renewal_email_notification(licence): | ||
email = LicenceRenewalNotificationEmail() | ||
url = host_reverse('wl_home') | ||
|
||
context = { | ||
'url': url, | ||
'licence': licence | ||
} | ||
|
||
return email.send(licence.profile.email, context=context) is not None |
29 changes: 29 additions & 0 deletions
29
wildlifelicensing/apps/main/migrations/0020_auto_20161011_1127.py
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,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.7 on 2016-10-11 03:27 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wl_main', '0019_auto_20160905_1454'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='wildlifelicence', | ||
old_name='previous_licence', | ||
new_name='replaced_by', | ||
), | ||
migrations.RemoveField( | ||
model_name='wildlifelicence', | ||
name='sequence_number', | ||
), | ||
migrations.AddField( | ||
model_name='wildlifelicence', | ||
name='renewal_sent', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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
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
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
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