diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index f40cebe5..563705f3 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -30,13 +30,15 @@ queuelow = django_rq.get_queue('low') queuehigh = django_rq.get_queue('default') # Sends a confirmation with a link to the workout -def send_confirm(u,name,link): +def send_confirm(u,name,link,options): 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" + if options: + message += "\n\n"+options email = EmailMessage(subject,message, 'Rowsandall ', diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 0533da49..31c88be4 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -72,15 +72,24 @@ class Command(BaseCommand): ] res += wid link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' + if uploadoptions and not 'error' in uploadoptions: + w = Workout.objects.get(wid[0]) + r = w.user + if 'make_plot' in uploadoptions: + plottype = uploadoptions['plottype'] + res = uploads.make_plot(r,w,plottype, + title,f2[6:],f2) try: if wid != 1: - dd = send_confirm(rr.user,title,link) + dd = send_confirm(rr.user,title,link, + uploadoptions) time.sleep(10) except: try: time.sleep(10) if wid != 1: - dd = send_confirm(rr.user,title,link) + dd = send_confirm(rr.user,title,link, + uploadoptions) except: pass @@ -94,7 +103,14 @@ class Command(BaseCommand): ] res += wid link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' - + if uploadoptions: + w = Workout.objects.get(wid[0]) + r = w.user + if 'make_plot' in uploadoptions: + plottype = uploadoptions['plottype'] + res = uploads.make_plot(r,w,plottype, + title,f2[6:],f2) + except: # replace with code to process error res += ['fail: '+name] @@ -102,7 +118,8 @@ class Command(BaseCommand): wid = 1 try: if wid != 1: - dd = send_confirm(rr.user,name,link) + dd = send_confirm(rr.user,name,link, + uploadoptions) time.sleep(10) except: pass diff --git a/rowers/uploads.py b/rowers/uploads.py index 90f66483..245acfe5 100644 --- a/rowers/uploads.py +++ b/rowers/uploads.py @@ -83,16 +83,32 @@ def getplotoptions(uploadoptions,value): return uploadoptions +def getboolean(uploadoptions,value,key): + b = True + if not value: + b = False + if value in [False,'false','False',None,'no']: + b = False + + uploadoptions[key] = b + + return uploadoptions + def upload_options(body): uploadoptions = {} body = cleanbody(body) try: yml = (yaml.load(body)) - for key, value in yml.iteritems(): - if key == 'sync' or key == 'synchronization': - uploadoptions = getsyncoptions(uploadoptions,value) - if key == 'chart' or key == 'static' or key == 'plot': - uploadoptions = getplotoptions(uploadoptions,value) + try: + for key, value in yml.iteritems(): + if key == 'sync' or key == 'synchronization': + uploadoptions = getsyncoptions(uploadoptions,value) + if key == 'chart' or key == 'static' or key == 'plot': + uploadoptions = getplotoptions(uploadoptions,value) + if 'priva' in key: + uploadoptions = getboolean(uploadoptions,value,'makeprivate') + except AttributeError: + pass except yaml.YAMLError as exc: pm = exc.problem_mark strpm = str(pm)