Private
Public Access
1
0

add workouttype & boattype to email processing

This commit is contained in:
Sander Roosendaal
2018-03-25 20:31:12 +02:00
parent 15dbbef449
commit e1eab77a52
3 changed files with 48 additions and 4 deletions

View File

@@ -72,6 +72,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
workout = Workout.objects.get(id=workoutid[0])
uploads.do_sync(workout, uploadoptions)
uploads.make_private(workout, uploadoptions)
uploads.set_workouttype(workout, uploadoptions)
if 'make_plot' in uploadoptions:
plottype = uploadoptions['plottype']
workoutcsvfilename = workout.csvfilename[6:-4]

View File

@@ -362,7 +362,11 @@ class EmailTests(TestCase):
from_header = u.email,
subject = filename,
body="""
chart time
---
chart: time
workouttype: water
boattype: 4x
...
""")
m.save()
a2 = 'media/mailbox_attachments/'+filename

View File

@@ -27,6 +27,8 @@ queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low')
from types import workouttypes,boattypes
try:
from cStringIO import StringIO
except:
@@ -96,6 +98,29 @@ def matchsync(line):
return results
def gettypeoptions_body2(uploadoptions,body):
tester = re.compile('^(workout)')
testerb = re.compile('^(boat)')
for line in body.splitlines():
if tester.match(line.lower()):
for typ,verb in workouttypes:
str1 = '^(workout)(.*)({a})'.format(
a = typ
)
testert = re.compile(str1)
if testert.match(line.lower()):
uploadoptions['workouttype'] = typ
if testerb.match(line.lower()):
for typ,verb in boattypes:
str1 = '^(boat)(.*)({a})'.format(
a = typ
)
testert = re.compile(str1)
if testert.match(line.lower()):
uploadoptions['boattype'] = typ
return uploadoptions
def getprivateoptions_body2(uploadoptions,body):
tester = re.compile('^(priva)')
for line in body.splitlines():
@@ -181,7 +206,6 @@ def getplotoptions(uploadoptions,value):
return uploadoptions
from types import workouttypes,boattypes
def gettype(uploadoptions,value,key):
workouttype = 'rower'
@@ -235,10 +259,10 @@ def upload_options(body):
uploadoptions = getplotoptions(uploadoptions,value)
if 'priva' in lowkey:
uploadoptions = getboolean(uploadoptions,value,'makeprivate')
if 'type' in lowkey:
if 'workout' in lowkey:
uploadoptions = gettype(uploadoptions,value,'workouttype')
if 'boat' in lowkey:
uploadoptions = getboattype(uploadoptions,value,'workouttype')
uploadoptions = getboattype(uploadoptions,value,'boattype')
except AttributeError:
#pass
raise yaml.YAMLError
@@ -247,6 +271,7 @@ def upload_options(body):
uploadoptions = getplotoptions_body2(uploadoptions,body)
uploadoptions = getsyncoptions_body2(uploadoptions,body)
uploadoptions = getprivateoptions_body2(uploadoptions,body)
typeoptions = gettypeoptions_body2(uploadoptions,body)
except IOError:
pm = exc.problem_mark
strpm = str(pm)
@@ -327,6 +352,20 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
import c2stuff,stravastuff,sporttracksstuff,runkeeperstuff
import underarmourstuff,tpstuff
def set_workouttype(w,options):
try:
w.workouttype = options['workouttype']
w.save()
except KeyError:
pass
try:
w.boattype = options['boattype']
w.save()
except KeyError:
pass
return 1
def make_private(w,options):
if 'makeprivate' in options and options['makeprivate']:
w.privacy = 'hidden'