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.c2stuff as c2stuff
|
||||
import rowers.stravastuff as stravastuff
|
||||
from rowers.models import User
|
||||
|
||||
workoutmailbox = Mailbox.objects.get(name='workouts')
|
||||
failedmailbox = Mailbox.objects.get(name='Failed')
|
||||
@@ -65,9 +66,20 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
|
||||
if testing:
|
||||
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 = [
|
||||
make_new_workout_from_email(rower, filename, title,testing=testing)
|
||||
make_new_workout_from_email(therower, filename, title,testing=testing)
|
||||
]
|
||||
|
||||
if testing:
|
||||
@@ -75,7 +87,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
|
||||
if workoutid[0]:
|
||||
link = settings.SITE_URL+reverse(
|
||||
rower.defaultlandingpage,
|
||||
therower.defaultlandingpage,
|
||||
kwargs = {
|
||||
'id':workoutid[0],
|
||||
}
|
||||
@@ -99,9 +111,9 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
)
|
||||
try:
|
||||
if workoutid and not testing:
|
||||
if rower.getemailnotifications and not rower.emailbounced:
|
||||
if therower.getemailnotifications and not therower.emailbounced:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
therower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
time.sleep(10)
|
||||
@@ -109,9 +121,9 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
try:
|
||||
time.sleep(10)
|
||||
if workoutid:
|
||||
if rower.getemailnotifications and not rower.emailbounced:
|
||||
if therower.getemailnotifications and not therower.emailbounced:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
therower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
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>
|
||||
</Track>
|
||||
</Lap>
|
||||
<Notes><Element 'Notes' at 0x14011cc0></Notes>
|
||||
<Notes><Element 'Notes' at 0x14a96cf8></Notes>
|
||||
</Activity>
|
||||
</Activities>
|
||||
<Creator>
|
||||
|
||||
@@ -82,6 +82,16 @@ def matchchart(line):
|
||||
if tester3.match(line.lower()):
|
||||
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):
|
||||
results = []
|
||||
tester = '((sync)|(synchronization)|(export))'
|
||||
@@ -176,6 +186,14 @@ def getplotoptions_body2(uploadoptions,body):
|
||||
|
||||
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):
|
||||
result = []
|
||||
for line in body.splitlines():
|
||||
@@ -261,6 +279,11 @@ def getboattype(uploadoptions,value,key):
|
||||
|
||||
return uploadoptions
|
||||
|
||||
def getuser(uploadoptions,value,key):
|
||||
uploadoptions['username'] = value
|
||||
|
||||
return uploadoptions
|
||||
|
||||
def getsource(uploadoptions,value,key):
|
||||
workoutsource = 'unknown'
|
||||
for type,verb in workoutsources:
|
||||
@@ -306,6 +329,8 @@ def upload_options(body):
|
||||
uploadoptions = getboattype(uploadoptions,value,'boattype')
|
||||
if 'source' in lowkey:
|
||||
uploadoptions = getsource(uploadoptions,value,'workoutsource')
|
||||
if 'username' in lowkey:
|
||||
uploadoptions = getuser(uploadoptions,value,'workoutuser')
|
||||
except AttributeError:
|
||||
#pass
|
||||
raise yaml.YAMLError
|
||||
@@ -317,6 +342,7 @@ def upload_options(body):
|
||||
uploadoptions = gettypeoptions_body2(uploadoptions,body)
|
||||
uploadoptions = getstravaid(uploadoptions,body)
|
||||
uploadoptions = getworkoutsources(uploadoptions,body)
|
||||
uploadoptions = getuseroptions_body2(uploadoptions,body)
|
||||
except IOError:
|
||||
pm = exc.problem_mark
|
||||
strpm = str(pm)
|
||||
|
||||
Reference in New Issue
Block a user