Private
Public Access
1
0

Merge branch 'release/v23.1.11'

This commit is contained in:
2025-01-20 21:21:48 +01:00
5 changed files with 28 additions and 12 deletions
+5 -3
View File
@@ -15,7 +15,7 @@ from rowingdata import rowingdata
from rowers.rower_rules import is_workout_user from rowers.rower_rules import is_workout_user
import time import time
from django_rq import job from django_rq import job
from rowers.mytypes import tpmapping from rowers.mytypes import tpmapping, tcxmapping
from rowers.tasks import check_tp_workout_id, handle_workout_tp_upload from rowers.tasks import check_tp_workout_id, handle_workout_tp_upload
@@ -68,7 +68,8 @@ class TPIntegration(SyncIntegration):
newnotes = 'from '+w.workoutsource+' via rowsandall.com' newnotes = 'from '+w.workoutsource+' via rowsandall.com'
try: try:
row.exporttotcx(tcxfilename, notes=newnotes, sport=tpmapping[w.workouttype]) #row.exporttotcx(tcxfilename, notes=newnotes, sport=tcxmapping[w.workouttype])
row.exporttotcx(tcxfilename, notes=newnotes, sport=None)
except KeyError: except KeyError:
row.exporttotcx(tcxfilename, notes=newnotes, sport='other') row.exporttotcx(tcxfilename, notes=newnotes, sport='other')
@@ -83,7 +84,8 @@ class TPIntegration(SyncIntegration):
handle_workout_tp_upload, handle_workout_tp_upload,
workout, workout,
thetoken, thetoken,
tcxfilename tcxfilename,
tpmapping[workout.workouttype]
) )
return job.id return job.id
+3
View File
@@ -3974,8 +3974,11 @@ class SyncRecord(models.Model):
intervalsid = models.CharField(unique=True, null=True, default=None, max_length=100) intervalsid = models.CharField(unique=True, null=True, default=None, max_length=100)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
try:
if self.workout: if self.workout:
self.rower = self.workout.user self.rower = self.workout.user
except:
pass
return super(SyncRecord, self).save(*args, **kwargs) return super(SyncRecord, self).save(*args, **kwargs)
def __str__(self): def __str__(self):
+17 -7
View File
@@ -461,9 +461,10 @@ def handle_add_workouts_team(ws, t, debug=False, **kwargs): # pragma: no cover
return 1 return 1
def uploadactivity(access_token, filename, description='', def uploadactivity(access_token, filename, description='',
name='Rowsandall.com workout'): # pragma: no cover name='Rowsandall.com workout', workouttype='rowing'): # pragma: no cover
data_gz = BytesIO() data_gz = BytesIO()
try: try:
with open(filename, 'rb') as inF: with open(filename, 'rb') as inF:
s = inF.read() s = inF.read()
@@ -478,12 +479,13 @@ def uploadactivity(access_token, filename, description='',
'Authorization': 'Bearer %s' % access_token 'Authorization': 'Bearer %s' % access_token
} }
# Data field is base64 encoded file read from filename
data = { data = {
"UploadClient": "rowsandall", "UploadClient": "rowsandall",
"Filename": filename, "Filename": filename,
"SetWorkoutPublic": True, "SetWorkoutPublic": True,
"Title": name, "Title": name,
"Type": "rowing", "Type": workouttype,
"Comment": description, "Comment": description,
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii") "Data": base64.b64encode(data_gz.getvalue()).decode("ascii")
} }
@@ -495,7 +497,7 @@ def uploadactivity(access_token, filename, description='',
if resp.status_code not in (200, 202): # pragma: no cover if resp.status_code not in (200, 202): # pragma: no cover
dologging('tp_export.log',resp.status_code) dologging('tp_export.log',resp.status_code)
dologging('tp_export.log',resp.reason) dologging('tp_export.log',resp.reason)
dologging('tp_export.log',json.dumps(data))
return 0, resp.reason, resp.status_code, headers return 0, resp.reason, resp.status_code, headers
else: else:
return 1, "ok", 200, resp.headers return 1, "ok", 200, resp.headers
@@ -564,26 +566,34 @@ def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs): #
workout.uploadedtotp = tpid workout.uploadedtotp = tpid
record = create_or_update_syncrecord(workout.user, workout, tpid=tpid) record = create_or_update_syncrecord(workout.user, workout, tpid=tpid)
workout.save() workout.save()
else:
dologging('tp_export.log','failed to get workout id from trainingpeaks')
dologging('tp_export.log',response.text)
dologging('tp_export.log',status)
return 0
else:
dologging('tp_export.log','failed to get workout id from trainingpeaks')
dologging('tp_export.log',response.text)
return 0
return 1 return 1
@app.task @app.task
def handle_workout_tp_upload(w, thetoken, tcxfilename, debug=False, **kwargs): # pragma: no cover def handle_workout_tp_upload(w, thetoken, tcxfilename, workouttype, debug=False, **kwargs): # pragma: no cover
tpid = 0 tpid = 0
r = w.user r = w.user
dologging('tp_export.log','uploading workout {workoutid} to trainingpeaks for user {id}'.format(id=r.id,workoutid=w.id)) dologging('tp_export.log','uploading workout {workoutid} to trainingpeaks for user {id}'.format(id=r.id,workoutid=w.id))
if not tcxfilename: if not tcxfilename:
return 0 return 0
res, reason, status_code, headers = uploadactivity( res, reason, status_code, headers = uploadactivity(
thetoken, tcxfilename, thetoken, tcxfilename,
name=w.name name=w.name, workouttype=workouttype,
) )
if res == 0: if res == 0:
w.tpid = -1 w.uploadedtotcx = -1
try: try:
os.remove(tcxfilename) os.remove(tcxfilename)
except: except:
+1
View File
@@ -986,6 +986,7 @@ def mocked_requests(*args, **kwargs):
def __init__(self, json_data, status_code): def __init__(self, json_data, status_code):
self.json_data = json_data self.json_data = json_data
self.status_code = status_code self.status_code = status_code
self.reason = 'mock reason'
self.ok = True self.ok = True
self.headers = { self.headers = {
'Location':'MockLocation', 'Location':'MockLocation',
Binary file not shown.