Private
Public Access
1
0

Merge branch 'hotfix/v2.73'

This commit is contained in:
Sander Roosendaal
2017-05-11 20:50:52 +02:00
3 changed files with 16 additions and 11 deletions

View File

@@ -122,11 +122,18 @@ def get_token(code):
response = requests.post(url, response = requests.post(url,
data=json.dumps(post_data), data=json.dumps(post_data),
headers=headers) headers=headers)
token_json = response.json() if response.status_code == 200 or response.status_code == 201:
thetoken = token_json['access_token'] token_json = response.json()
expires_in = token_json['expires_in'] thetoken = token_json['access_token']
refresh_token = token_json['refresh_token'] expires_in = token_json['expires_in']
try:
refresh_token = token_json['refresh_token']
except KeyError:
refresh_token = refreshtoken
else:
return [0,0,0]
return [thetoken,expires_in,refresh_token] return [thetoken,expires_in,refresh_token]
# Make authorization URL including random string # Make authorization URL including random string

View File

@@ -145,7 +145,7 @@ def do_refresh_token(refreshtoken):
data=post_data, data=post_data,
headers=headers) headers=headers)
if response.status_code == 200: if response.status_code == 200 or response.status_code == 201:
token_json = response.json() token_json = response.json()
thetoken = token_json['access_token'] thetoken = token_json['access_token']
expires_in = token_json['expires_in'] expires_in = token_json['expires_in']
@@ -316,9 +316,7 @@ def workout_tp_upload(user,w):
) )
if res == 0: if res == 0:
message = "Upload to TrainingPeaks failed with status code "+str(status_code)+": "+reason message = "Upload to TrainingPeaks failed with status code "+str(status_code)+": "+reason
w.uploadedtotp = -1
w.tpid = -1 w.tpid = -1
w.save()
try: try:
os.remove(tcxfile) os.remove(tcxfile)
except WindowsError: except WindowsError:

View File

@@ -1170,12 +1170,12 @@ def workout_tp_upload_view(request,id=0):
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
tcxfile = tpstuff.createtpworkoutdata(w) tcxfile = tpstuff.createtpworkoutdata(w)
if tcxfile: if tcxfile:
res,reason,status_code,headers = tpstuff.uploadactivity(r.tptoken,tcxfile, res,reason,status_code,headers = tpstuff.uploadactivity(
name=w.name) r.tptoken,tcxfile,
name=w.name
)
if res == 0: if res == 0:
message = "Upload to TrainingPeaks failed with status code "+str(status_code)+": "+reason message = "Upload to TrainingPeaks failed with status code "+str(status_code)+": "+reason
w.uploadedtotp = -1
w.save()
try: try:
os.remove(tcxfile) os.remove(tcxfile)
except WindowsError: except WindowsError: