Private
Public Access
1
0

Merge branch 'release/v20.3.1'

This commit is contained in:
2023-11-20 19:07:37 +01:00
3 changed files with 52 additions and 40 deletions

View File

@@ -128,6 +128,8 @@ def send_template_email(from_email, to_email, subject,
umsg.save() umsg.save()
except User.DoesNotExist: except User.DoesNotExist:
pass pass
except Exception as e:
pass
if not emailbounced: if not emailbounced:
res = msg.send() res = msg.send()

Binary file not shown.

View File

@@ -15,7 +15,7 @@ from datetime import datetime as dt
import rowingdata.tcxtools as tcxtools import rowingdata.tcxtools as tcxtools
from rowingdata import TCXParser, rowingdata from rowingdata import TCXParser, rowingdata
import arrow
class XMLParser(BaseParser): class XMLParser(BaseParser):
media_type = "application/xml" media_type = "application/xml"
@@ -239,12 +239,14 @@ def strokedata_tcx(request):
Upload a TCX file through API Upload a TCX file through API
""" """
if request.method != 'POST': if request.method != 'POST':
dologging('apilog.log','GET request to TCX endpoint')
return HttpResponseNotAllowed("Method not supported") # pragma: no cover return HttpResponseNotAllowed("Method not supported") # pragma: no cover
if request.content_type.lower() != 'application/xml': if request.content_type.lower() != 'application/xml':
dologging('apilog.log','POST data not application/xml, request to TCX endpoint')
return HttpResponseNotAllowed("Need application/xml") return HttpResponseNotAllowed("Need application/xml")
dologging('apilog.log', request.user.username+" (strokedatajson_TCX POST)") dologging('apilog.log', request.user.username+" (strokedata_tcx POST)")
try: try:
tcxdata = request.data tcxdata = request.data
@@ -267,56 +269,64 @@ def strokedata_tcx(request):
total_duration += lap_duration_seconds total_duration += lap_duration_seconds
except Exception as e: except Exception as e:
dologgin('apilog.log','TCX')
dologging('apilog.log',e) dologging('apilog.log',e)
return HttpResponseNotAllowed("Could not parse TCX data") return HttpResponseNotAllowed("Could not parse TCX data")
tcxfilename = 'media/{code}.tcx'.format(code=uuid4().hex[:16]) try:
xml_string = ET.tostring(tcxdata, encoding='utf-8', method='xml').decode('utf-8') tcxfilename = 'media/{code}.tcx'.format(code=uuid4().hex[:16])
xml_string = ET.tostring(tcxdata, encoding='utf-8', method='xml').decode('utf-8')
with open(tcxfilename, 'w', encoding='utf-8') as xml_file:
xml_file.write(xml_string) with open(tcxfilename, 'w', encoding='utf-8') as xml_file:
xml_file.write(xml_string)
duration = totaltime_sec_to_string(total_duration) duration = totaltime_sec_to_string(total_duration)
startdatetime = dt.strptime(start_time_str, "%Y-%m-%dT%H:%M:%S%z") startdatetime = arrow.get(start_time_str)
startdate = startdatetime.date() #startdatetime = dt.strptime(start_time_str, "%Y-%m-%dT%H:%M:%S%z")
partofday = part_of_day(startdatetime.hour) startdate = startdatetime.date()
title = '{partofday} water'.format(partofday=partofday) partofday = part_of_day(startdatetime.hour)
title = '{partofday} water'.format(partofday=partofday)
w = Workout(user=request.user.rower,
date=startdate,
name=title,
duration=duration)
w.save()
w = Workout(user=request.user.rower, # need workouttype, duration
date=startdate,
name=title,
duration=duration)
w.save()
# need workouttype, duration uploadoptions = {
'secret': UPLOAD_SERVICE_SECRET,
uploadoptions = { 'user': request.user.id,
'secret': UPLOAD_SERVICE_SECRET, 'file': tcxfilename,
'user': request.user.id, 'id': w.id,
'file': tcxfilename, 'title': title,
'id': w.id, 'rpe': 0,
'title': title, 'workouttype': 'water',
'rpe': 0, 'boattype': '1x',
'workouttype': 'water', 'notes': '',
'boattype': '1x', 'offline': False,
'notes': '', }
'offline': False,
}
_ = myqueue(queuehigh, _ = myqueue(queuehigh,
handle_post_workout_api, handle_post_workout_api,
uploadoptions) uploadoptions)
workoutid = w.id workoutid = w.id
return JsonResponse(
{"workout public id": encoder.encode_hex(workoutid),
"workout id": workoutid,
"status": "success",
})
except Exception as e:
dologging('apilog.log','TCX API endpoint')
dologging('apilog.log',e)
return HttpResponse(status=500)
return JsonResponse(
{"workout public id": encoder.encode_hex(workoutid),
"workout id": workoutid,
"status": "success",
})