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
import time
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
@@ -68,7 +68,8 @@ class TPIntegration(SyncIntegration):
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
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:
row.exporttotcx(tcxfilename, notes=newnotes, sport='other')
@@ -83,7 +84,8 @@ class TPIntegration(SyncIntegration):
handle_workout_tp_upload,
workout,
thetoken,
tcxfilename
tcxfilename,
tpmapping[workout.workouttype]
)
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)
def save(self, *args, **kwargs):
try:
if self.workout:
self.rower = self.workout.user
except:
pass
return super(SyncRecord, self).save(*args, **kwargs)
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
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()
try:
with open(filename, 'rb') as inF:
s = inF.read()
@@ -478,12 +479,13 @@ def uploadactivity(access_token, filename, description='',
'Authorization': 'Bearer %s' % access_token
}
# Data field is base64 encoded file read from filename
data = {
"UploadClient": "rowsandall",
"Filename": filename,
"SetWorkoutPublic": True,
"Title": name,
"Type": "rowing",
"Type": workouttype,
"Comment": description,
"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
dologging('tp_export.log',resp.status_code)
dologging('tp_export.log',resp.reason)
dologging('tp_export.log',json.dumps(data))
return 0, resp.reason, resp.status_code, headers
else:
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
record = create_or_update_syncrecord(workout.user, workout, tpid=tpid)
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
@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
r = w.user
dologging('tp_export.log','uploading workout {workoutid} to trainingpeaks for user {id}'.format(id=r.id,workoutid=w.id))
if not tcxfilename:
return 0
res, reason, status_code, headers = uploadactivity(
thetoken, tcxfilename,
name=w.name
name=w.name, workouttype=workouttype,
)
if res == 0:
w.tpid = -1
w.uploadedtotcx = -1
try:
os.remove(tcxfilename)
except:
+1
View File
@@ -986,6 +986,7 @@ def mocked_requests(*args, **kwargs):
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
self.reason = 'mock reason'
self.ok = True
self.headers = {
'Location':'MockLocation',
Binary file not shown.