adding get email list management command
This commit is contained in:
56
rowers/management/commands/getemail_list.py
Normal file
56
rowers/management/commands/getemail_list.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/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 *
|
||||||
|
from rowsandall_app.settings import BASE_DIR
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
def getemails():
|
||||||
|
rs = Rower.objects.all()
|
||||||
|
firstnames = [r.user.first_name for r in rs]
|
||||||
|
lastnames = [r.user.last_name for r in rs]
|
||||||
|
emails = [r.user.email for r in rs]
|
||||||
|
is_actives = [r.user.is_active for r in rs]
|
||||||
|
df = pd.DataFrame({
|
||||||
|
'first_name':firstnames,
|
||||||
|
'last_name':lastnames,
|
||||||
|
'email':emails,
|
||||||
|
'is_active':is_actives
|
||||||
|
})
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
email_list = getemails()
|
||||||
|
email_list.to_csv('email_list.csv')
|
||||||
|
|
||||||
|
fullemail = 'roosendaalsander@gmail.com'
|
||||||
|
subject = "Rowsandall users list"
|
||||||
|
message = "Dear Sander,\n\n"
|
||||||
|
message += "Best Regards, the Rowsandall Team"
|
||||||
|
message += "Users list attached \n\n"
|
||||||
|
|
||||||
|
email = EmailMessage(subject, message,
|
||||||
|
'Rowsandall <info@rowsandall.com>',
|
||||||
|
[fullemail])
|
||||||
|
|
||||||
|
email.attach_file('email_list.csv')
|
||||||
|
|
||||||
|
os.remove('email_list.csv')
|
||||||
|
|
||||||
|
res = email.send()
|
||||||
@@ -4448,10 +4448,16 @@ def oterankings_view(request,theuser=0,
|
|||||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||||
|
|
||||||
if startdatestring != "":
|
if startdatestring != "":
|
||||||
startdate = iso8601.parse_date(startdatestring)
|
try:
|
||||||
|
startdate = iso8601.parse_date(startdatestring)
|
||||||
|
except ParseError:
|
||||||
|
pass
|
||||||
|
|
||||||
if enddatestring != "":
|
if enddatestring != "":
|
||||||
enddate = iso8601.parse_date(enddatestring)
|
try:
|
||||||
|
enddate = iso8601.parse_date(enddatestring)
|
||||||
|
except ParseError:
|
||||||
|
pass
|
||||||
|
|
||||||
if enddate < startdate:
|
if enddate < startdate:
|
||||||
s = enddate
|
s = enddate
|
||||||
|
|||||||
Reference in New Issue
Block a user