Private
Public Access
1
0

fixing strava export bug

This commit is contained in:
Sander Roosendaal
2019-12-29 09:31:06 +01:00
parent 961d66a19e
commit ad249b8c6d
2 changed files with 20 additions and 20 deletions

View File

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

View File

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