passing test for user
This commit is contained in:
@@ -23,6 +23,7 @@ from rowers.mailprocessing import make_new_workout_from_email, send_confirm
|
|||||||
import rowers.polarstuff as polarstuff
|
import rowers.polarstuff as polarstuff
|
||||||
import rowers.c2stuff as c2stuff
|
import rowers.c2stuff as c2stuff
|
||||||
import rowers.stravastuff as stravastuff
|
import rowers.stravastuff as stravastuff
|
||||||
|
from rowers.models import User
|
||||||
|
|
||||||
workoutmailbox = Mailbox.objects.get(name='workouts')
|
workoutmailbox = Mailbox.objects.get(name='workouts')
|
||||||
failedmailbox = Mailbox.objects.get(name='Failed')
|
failedmailbox = Mailbox.objects.get(name='Failed')
|
||||||
@@ -66,8 +67,19 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
if testing:
|
if testing:
|
||||||
print 'Creating workout from email'
|
print 'Creating workout from email'
|
||||||
|
|
||||||
|
# set user
|
||||||
|
if rower.user.is_staff and 'username' in uploadoptions:
|
||||||
|
users = User.objects.filter(username=uploadoptions['username'])
|
||||||
|
if len(users)==1:
|
||||||
|
therower = users[0].rower
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
therower = rower
|
||||||
|
|
||||||
|
|
||||||
workoutid = [
|
workoutid = [
|
||||||
make_new_workout_from_email(rower, filename, title,testing=testing)
|
make_new_workout_from_email(therower, filename, title,testing=testing)
|
||||||
]
|
]
|
||||||
|
|
||||||
if testing:
|
if testing:
|
||||||
@@ -75,7 +87,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
|
|
||||||
if workoutid[0]:
|
if workoutid[0]:
|
||||||
link = settings.SITE_URL+reverse(
|
link = settings.SITE_URL+reverse(
|
||||||
rower.defaultlandingpage,
|
therower.defaultlandingpage,
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'id':workoutid[0],
|
'id':workoutid[0],
|
||||||
}
|
}
|
||||||
@@ -99,9 +111,9 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if workoutid and not testing:
|
if workoutid and not testing:
|
||||||
if rower.getemailnotifications and not rower.emailbounced:
|
if therower.getemailnotifications and not therower.emailbounced:
|
||||||
email_sent = send_confirm(
|
email_sent = send_confirm(
|
||||||
rower.user, title, link,
|
therower.user, title, link,
|
||||||
uploadoptions
|
uploadoptions
|
||||||
)
|
)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
@@ -109,9 +121,9 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
try:
|
try:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
if workoutid:
|
if workoutid:
|
||||||
if rower.getemailnotifications and not rower.emailbounced:
|
if therower.getemailnotifications and not therower.emailbounced:
|
||||||
email_sent = send_confirm(
|
email_sent = send_confirm(
|
||||||
rower.user, title, link,
|
therower.user, title, link,
|
||||||
uploadoptions
|
uploadoptions
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
2
rowers/tests/testdata/testdata.tcx
vendored
2
rowers/tests/testdata/testdata.tcx
vendored
@@ -2502,7 +2502,7 @@
|
|||||||
</Trackpoint>
|
</Trackpoint>
|
||||||
</Track>
|
</Track>
|
||||||
</Lap>
|
</Lap>
|
||||||
<Notes><Element 'Notes' at 0x14011cc0></Notes>
|
<Notes><Element 'Notes' at 0x14a96cf8></Notes>
|
||||||
</Activity>
|
</Activity>
|
||||||
</Activities>
|
</Activities>
|
||||||
<Creator>
|
<Creator>
|
||||||
|
|||||||
@@ -82,6 +82,16 @@ def matchchart(line):
|
|||||||
if tester3.match(line.lower()):
|
if tester3.match(line.lower()):
|
||||||
return 'pieplot'
|
return 'pieplot'
|
||||||
|
|
||||||
|
def matchuser(line):
|
||||||
|
testert = '^(user)'
|
||||||
|
tester = re.compile(testert)
|
||||||
|
if tester.match(line.lower()):
|
||||||
|
words = line.split()
|
||||||
|
return words[1]
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def matchsync(line):
|
def matchsync(line):
|
||||||
results = []
|
results = []
|
||||||
tester = '((sync)|(synchronization)|(export))'
|
tester = '((sync)|(synchronization)|(export))'
|
||||||
@@ -176,6 +186,14 @@ def getplotoptions_body2(uploadoptions,body):
|
|||||||
|
|
||||||
return uploadoptions
|
return uploadoptions
|
||||||
|
|
||||||
|
def getuseroptions_body2(uploadoptions,body):
|
||||||
|
for line in body.splitlines():
|
||||||
|
user = matchuser(line)
|
||||||
|
if user:
|
||||||
|
uploadoptions['username'] = user
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
def getsyncoptions_body2(uploadoptions,body):
|
def getsyncoptions_body2(uploadoptions,body):
|
||||||
result = []
|
result = []
|
||||||
for line in body.splitlines():
|
for line in body.splitlines():
|
||||||
@@ -261,6 +279,11 @@ def getboattype(uploadoptions,value,key):
|
|||||||
|
|
||||||
return uploadoptions
|
return uploadoptions
|
||||||
|
|
||||||
|
def getuser(uploadoptions,value,key):
|
||||||
|
uploadoptions['username'] = value
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
def getsource(uploadoptions,value,key):
|
def getsource(uploadoptions,value,key):
|
||||||
workoutsource = 'unknown'
|
workoutsource = 'unknown'
|
||||||
for type,verb in workoutsources:
|
for type,verb in workoutsources:
|
||||||
@@ -306,6 +329,8 @@ def upload_options(body):
|
|||||||
uploadoptions = getboattype(uploadoptions,value,'boattype')
|
uploadoptions = getboattype(uploadoptions,value,'boattype')
|
||||||
if 'source' in lowkey:
|
if 'source' in lowkey:
|
||||||
uploadoptions = getsource(uploadoptions,value,'workoutsource')
|
uploadoptions = getsource(uploadoptions,value,'workoutsource')
|
||||||
|
if 'username' in lowkey:
|
||||||
|
uploadoptions = getuser(uploadoptions,value,'workoutuser')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
#pass
|
#pass
|
||||||
raise yaml.YAMLError
|
raise yaml.YAMLError
|
||||||
@@ -317,6 +342,7 @@ def upload_options(body):
|
|||||||
uploadoptions = gettypeoptions_body2(uploadoptions,body)
|
uploadoptions = gettypeoptions_body2(uploadoptions,body)
|
||||||
uploadoptions = getstravaid(uploadoptions,body)
|
uploadoptions = getstravaid(uploadoptions,body)
|
||||||
uploadoptions = getworkoutsources(uploadoptions,body)
|
uploadoptions = getworkoutsources(uploadoptions,body)
|
||||||
|
uploadoptions = getuseroptions_body2(uploadoptions,body)
|
||||||
except IOError:
|
except IOError:
|
||||||
pm = exc.problem_mark
|
pm = exc.problem_mark
|
||||||
strpm = str(pm)
|
strpm = str(pm)
|
||||||
|
|||||||
Reference in New Issue
Block a user