Don't send emails if membership expired, etc.
This commit is contained in:
parent
62119cc83c
commit
435aa15d17
@ -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', {})
|
||||
|
Loading…
Reference in New Issue
Block a user