Private
Public Access
1
0

v1 using basic auth

This commit is contained in:
2024-11-26 08:37:36 +01:00
parent a8973b80b1
commit b94197a74b
4 changed files with 158 additions and 2 deletions

View File

@@ -21,6 +21,8 @@ import rowingdata.tcxtools as tcxtools
from rowingdata import TCXParser, rowingdata
import arrow
import base64
class XMLParser(BaseParser):
media_type = "application/xml"
@@ -422,6 +424,52 @@ def get_crewnerd_liked(request):
# Stroke data views
@csrf_exempt
@logged_in_or_basicauth()
def strokedata_rowingdata(request):
"""
Upload a .csv file (rowingdata standard) through API, using Basic Auth
"""
r = getrower(request.user)
if r.rowerplan == 'freecoach':
return HttpResponseNotAllowed("This endpoint is for users, not for free coach accounts")
if request.method == 'POST':
form = DocumentsForm(request.POST, request.FILES)
if not form.is_valid():
return HttpResponseBadRequest(json.dumps(form.errors))
f = form.cleaned_data['file']
if f is None:
return HttpResponseBadRequest("Missing file")
filename, completefilename = handle_uploaded_file(f)
uploadoptions = {
'secret': settings.UPLOAD_SERVICE_SECRET,
'user': r.user.id,
'file': completefilename,
'workouttype': form.cleaned_data['workouttype'],
'boattype': form.cleaned_data['boattype'],
'title': form.cleaned_data['title'],
'rpe': form.cleaned_data['rpe'],
'notes': form.cleaned_data['notes']
}
url = settings.UPLOAD_SERVICE_URL
_ = myqueue(queuehigh,
handle_request_post,
url,
uploadoptions)
return JsonResponse(
{
"status": "success",
}
)
@csrf_exempt
#@login_required()
@api_view(["POST"])