Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2017-05-09 11:46:16 +02:00
parent 7e573d9bdf
commit 7887c46721
2 changed files with 78 additions and 25 deletions

View File

@@ -54,7 +54,7 @@ import c2stuff
from c2stuff import C2NoTokenError,c2_open
from runkeeperstuff import RunKeeperNoTokenError,runkeeper_open
from sporttracksstuff import SportTracksNoTokenError,sporttracks_open
from tpstuff import TPNoTokenError
from tpstuff import TPNoTokenError,tp_open
from iso8601 import ParseError
import stravastuff
from stravastuff import StravaNoTokenError
@@ -1037,29 +1037,6 @@ def add_workout_from_underarmourdata(user,importid,data):
# Checks if user has UnderArmour token, renews them if they are expired
def tp_open(user):
r = Rower.objects.get(user=user)
if (r.tptoken == '') or (r.tptoken is None):
s = "Token doesn't exist. Need to authorize"
raise TPNoTokenError("User has no token")
else:
if (timezone.now()>r.tptokenexpirydate):
res = tpstuff.do_refresh_token(r.tprefreshtoken)
if res[0] != 0:
r.tptoken = res[0]
r.tprefreshtoken = res[2]
expirydatetime = timezone.now()+datetime.timedelta(seconds=res[1])
r.tptokenexpirydate = expirydatetime
r.save()
thetoken = r.tptoken
else:
raise TPNoTokenError("Refresh token invalid")
else:
thetoken = r.tptoken
return thetoken
# Export workout to TCX and send to user's email address
@login_required()
@@ -5891,6 +5868,14 @@ def workout_upload_view(request,message="",
)
except UnderArmourNoTokenError:
pass
if (upload_to_tp):
try:
tpmessage,tpid = tpstuff.workout_tp_upload(
request.user,w
)
except TPNoTokenError:
pass
if message:
url = reverse(workout_edit_view,