52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
import sys
|
|
import os
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from django.conf import settings
|
|
from django.core.mail import send_mail, BadHeaderError, EmailMessage
|
|
|
|
import datetime
|
|
from rowers.models import Rower
|
|
from rowsandall_app.settings import BASE_DIR
|
|
|
|
sys.path.append('$path_to_root_of_project$')
|
|
sys.path.append('$path_to_root_of_project$/$project_name$')
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
|
|
|
|
|
|
def getexpired():
|
|
rs = Rower.objects.all()
|
|
lijst = []
|
|
for r in rs:
|
|
if r.planexpires < datetime.datetime.now().date():
|
|
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
|
|
lijst.append(r)
|
|
if r.teamplanexpires < datetime.datetime.now().date():
|
|
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
|
|
lijst.append(r)
|
|
return lijst
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
expiredrowers = getexpired()
|
|
|
|
if len(expiredrowers) > 0:
|
|
fullemail = 'roosendaalsander@gmail.com'
|
|
subject = "Expired rowers report"
|
|
message = "Dear Sander,\n\n"
|
|
message += "Best Regards, the Rowsandall Team"
|
|
message += "Expired rowers report\n\n"
|
|
|
|
for r in expiredrowers:
|
|
message += r.user.first_name+" "+r.user.last_name+" "+r.user.username
|
|
message += "\n"
|
|
|
|
email = EmailMessage(
|
|
subject, message,
|
|
'Rowsandall <info@rowsandall.com>',
|
|
[fullemail])
|
|
|
|
_ = email.send()
|