Private
Public Access
1
0

added expired user email management command

This commit is contained in:
Sander Roosendaal
2017-05-16 18:21:55 +02:00
parent 762a69f926
commit 8d91cf7b4c

View File

@@ -0,0 +1,47 @@
#!/srv/venv/bin/python
import sys
import os
# If you find a solution that does not need the two paths, please comment!
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'
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
def getexpired():
rs = Rower.objects.all()
lijst = []
for r in rs:
if r.planexpires < datetime.datetime.now().date():
lijst.append(r)
return lijst
class Command(BaseCommand):
def handle(self, *args, **options):
expiredrowers = getexpired()
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])
res = email.send()