diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index 8e900112..b004cd39 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -4,7 +4,7 @@ from rowers.tasks import handle_sendemail_unrecognized from django_mailbox.models import Mailbox,Message,MessageAttachment from rowers.models import Workout, User, Rower, WorkoutForm,RowerForm,GraphImage,AdvancedWorkoutForm from django.core.files.base import ContentFile - +from django.core.mail import send_mail, BadHeaderError,EmailMessage from rowsandall_app.settings import BASE_DIR from rowingdata import rower as rrower @@ -19,6 +19,22 @@ from rowingdata import summarydata,get_file_type from scipy.signal import savgol_filter +def send_confirm(u,name,link): + fullemail = u.email + subject = 'Workout added: '+name + message = 'Dear '+u.first_name+',\n\n' + message += "Your workout has been added to Rowsandall.com.\n" + message += "Link to workout: "+link+"\n\n" + message += "Best Regards, the Rowsandall Team" + + email = EmailMessage(subject,message, + 'Rowsandall ', + [fullemail]) + + res = email.send() + + return 1 + def rdata(file,rower=rrower()): try: res = rrdata(file,rower=rower) @@ -49,7 +65,11 @@ def processattachments(): rr = Rower.objects.get(user=u.id) # move attachment and make workout try: - res += [make_new_workout_from_email(rr,a.document,name)] + wid = [make_new_workout_from_email(rr,a.document,name)] + res += wid + print wid + link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' + dd = send_confirm(u,name,link) except: # replace with code to process error res += ['fail: '+name] @@ -221,7 +241,7 @@ def make_new_workout_from_email(rr,f2,name,cntr=0): startdatetime=row.rowdatetime) w.save() - return 1 + return w.id diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 99151d61..4e24d3ef 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -30,7 +30,7 @@ from rowingdata import make_cumvalues from rowingdata import summarydata,get_file_type from scipy.signal import savgol_filter -from rowers.mailprocessing import make_new_workout_from_email +from rowers.mailprocessing import make_new_workout_from_email,send_confirm def rdata(file,rower=rrower()): try: @@ -60,7 +60,11 @@ class Command(BaseCommand): rr = Rower.objects.get(user=u.id) # move attachment and make workout try: - res += [make_new_workout_from_email(rr,a.document,name,cntr=cntr)] + wid = [make_new_workout_from_email(rr,a.document,name)] + res += wid + link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' + dd = send_confirm(u,name,link) + except: # replace with code to process error res += ['fail: '+name]