Don't send emails if membership expired, etc.

This commit is contained in:
Yingtong Li 2020-05-11 12:58:20 +10:00
parent 62119cc83c
commit 435aa15d17
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
from ssmain.email import Emailer from ssmain.email import Emailer
import ssmembership.models 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)') 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): def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()
members = ssmembership.models.Member.objects.all() members = ssmembership.models.Member.objects.all()
if len(options['ids']) > 0: if len(options['ids']) > 0:
@ -37,5 +39,9 @@ class Command(BaseCommand):
emailer = Emailer() emailer = Emailer()
for member in members: 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)) self.stdout.write('Emailing {} at {}'.format(member.id, member.email))
emailer.send_mail([member.email], options['subject'], 'ssmembership/email/' + options['template'] + '.md', {}) emailer.send_mail([member.email], options['subject'], 'ssmembership/email/' + options['template'] + '.md', {})