summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2020-05-11 12:58:20 +1000
committerYingtong Li <runassudo@yingtongli.me>2020-05-11 12:59:45 +1000
commit435aa15d17c27f6a71743123a5d4337c66b8cadf (patch)
treeeaf41584ed9b2f1fb88a98364f523964760b839d
parent62119cc83c68ab696d95a4df9fc52e2d092c15fe (diff)
Don't send emails if membership expired, etc.
-rw-r--r--ssmembership/management/commands/sendmdemail.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/ssmembership/management/commands/sendmdemail.py b/ssmembership/management/commands/sendmdemail.py
index 9aace7d..4c4992b 100644
--- a/ssmembership/management/commands/sendmdemail.py
+++ b/ssmembership/management/commands/sendmdemail.py
@@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.core.management.base import BaseCommand, CommandError
+from django.utils import timezone
from ssmain.email import Emailer
import ssmembership.models
@@ -28,6 +29,7 @@ class Command(BaseCommand):
parser.add_argument('ids', nargs='*', type=int, help='Members with ID numbers equal to these values will be emailed (default all)')
def handle(self, *args, **options):
+ today = timezone.localtime(timezone.now()).date()
members = ssmembership.models.Member.objects.all()
if len(options['ids']) > 0:
@@ -37,5 +39,9 @@ class Command(BaseCommand):
emailer = Emailer()
for member in members:
+ if member.member_type != 1 or member.expires < today:
+ self.stdout.write('Skipping {} at {}'.format(member.id, member.email))
+ continue
+
self.stdout.write('Emailing {} at {}'.format(member.id, member.email))
emailer.send_mail([member.email], options['subject'], 'ssmembership/email/' + options['template'] + '.md', {})
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.