Private
Public Access
1
0

Merge branch 'develop' into feature/metrics

This commit is contained in:
Sander Roosendaal
2020-01-01 15:24:02 +01:00
3 changed files with 24 additions and 21 deletions

View File

@@ -821,7 +821,10 @@ def get_userid(access_token):
return 0 return 0
me_json = response.json() try:
me_json = response.json()
except JSONDecodeError:
return 0
try: try:
res = me_json['data']['id'] res = me_json['data']['id']
except KeyError: except KeyError:

View File

@@ -61,7 +61,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
if testing: if testing:
print('Attribute Error', filename) print('Attribute Error', filename)
# test if file exists and is not empty # test if file exists and is not empty
try: try:
with io.open('media/'+filename,'rb') as fop: with io.open('media/'+filename,'rb') as fop:
@@ -83,13 +83,13 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
return 0 return 0
else: else:
therower = rower therower = rower
workoutid = [ workoutid = [
make_new_workout_from_email(therower, filename, title,testing=testing) make_new_workout_from_email(therower, filename, title,testing=testing)
] ]
if 'raceid' in uploadoptions and workoutid[0] and rower.user.is_staff: if 'raceid' in uploadoptions and workoutid[0] and rower.user.is_staff:
if testing and workoutid[0]: if testing and workoutid[0]:
w = Workout.objects.get(id = workoutid[0]) w = Workout.objects.get(id = workoutid[0])
@@ -142,7 +142,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
try: try:
time.sleep(10) time.sleep(10)
if workoutid: if workoutid:
if therower.getemailnotifications and not therower.emailbounced: if therower.getemailnotifications and not therower.emailbounced:
email_sent = send_confirm( email_sent = send_confirm(
therower.user, title, link, therower.user, title, link,
uploadoptions uploadoptions
@@ -155,7 +155,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
def get_from_address(message): def get_from_address(message):
from_address = message.from_address[0].lower() from_address = message.from_address[0].lower()
if message.encoded: if message.encoded:
body = message.text.splitlines() body = message.text.splitlines()
else: else:
@@ -194,7 +194,7 @@ class Command(BaseCommand):
default='workouts', default='workouts',
help="Changing mailbox name", help="Changing mailbox name",
) )
"""Run the Email processing command """ """Run the Email processing command """
def handle(self, *args, **options): def handle(self, *args, **options):
if 'testing' in options: if 'testing' in options:
@@ -221,7 +221,7 @@ class Command(BaseCommand):
for r in rowers: for r in rowers:
c2stuff.get_c2_workouts(r) c2stuff.get_c2_workouts(r)
messages = Message.objects.filter(mailbox_id = workoutmailbox.id) messages = Message.objects.filter(mailbox_id = workoutmailbox.id)
message_ids = [m.id for m in messages] message_ids = [m.id for m in messages]
attachments = MessageAttachment.objects.filter( attachments = MessageAttachment.objects.filter(
@@ -239,11 +239,11 @@ class Command(BaseCommand):
body = "\n".join(message.text.splitlines()) body = "\n".join(message.text.splitlines())
else: else:
body = message.get_body() body = message.get_body()
uploadoptions = uploads.upload_options(body) uploadoptions = uploads.upload_options(body)
from_address = get_from_address(message) from_address = get_from_address(message)
name = message.subject name = message.subject
# get a list of users # get a list of users
# theusers = User.objects.filter(email=from_address) # theusers = User.objects.filter(email=from_address)
@@ -265,7 +265,7 @@ class Command(BaseCommand):
title = name+' ('+str(id+1)+')' title = name+' ('+str(id+1)+')'
else: else:
title = name title = name
workoutid = processattachment( workoutid = processattachment(
rower, datafile, title, uploadoptions, rower, datafile, title, uploadoptions,
testing=testing testing=testing
@@ -284,7 +284,7 @@ class Command(BaseCommand):
print(attachment.document) print(attachment.document)
except UnicodeEncodeError: except UnicodeEncodeError:
pass pass
workoutid = processattachment( workoutid = processattachment(
rower, attachment.document, name, uploadoptions, rower, attachment.document, name, uploadoptions,
testing=testing testing=testing

View File

@@ -506,6 +506,7 @@ def do_sync(w,options):
try: try:
if options['stravaid'] != 0: if options['stravaid'] != 0:
w.uploadedtostrava = options['stravaid'] w.uploadedtostrava = options['stravaid']
options['upload_to_Strava'] = False
w.save() w.save()
except KeyError: except KeyError:
pass pass
@@ -524,14 +525,13 @@ def do_sync(w,options):
if ('upload_to_Strava' in options and not options['upload_to_Strava']): if ('upload_to_Strava' in options and not options['upload_to_Strava']):
pass pass
else: else:
if options['stravaid'] != 0: try:
try: message,id = stravastuff.workout_strava_upload(
message,id = stravastuff.workout_strava_upload( w.user.user,w
w.user.user,w )
) except NoTokenError:
except NoTokenError: id = 0
id = 0 message = "Please connect to Strava first"
message = "Please connect to Strava first"
if ('upload_to_SportTracks' in options and options['upload_to_SportTracks']) or (w.user.sporttracks_auto_export and isprorower(w.user)): if ('upload_to_SportTracks' in options and options['upload_to_SportTracks']) or (w.user.sporttracks_auto_export and isprorower(w.user)):