From fc6dd7e347b9ad800b634061f45ac4b9e4d3a4e9 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 18 Feb 2020 20:54:43 +0100 Subject: [PATCH] fixing zip - without uploadoptions --- rowers/dataprep.py | 3 ++- rowers/management/commands/processemail.py | 22 ++-------------------- rowers/uploads.py | 5 ++++- rowers/views/workoutviews.py | 10 ++++++++-- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 3843d4ec..763d4d4e 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -1470,7 +1470,7 @@ def new_workout_from_file(r, f2, boattype='1x', makeprivate=False, notes=''): - message = None + message = "" impeller = False try: fileformat = get_file_type(f2) @@ -1495,6 +1495,7 @@ def new_workout_from_file(r, f2, f3 = f3[6:] a = MessageAttachment(message=msg,document=f3) a.save() + message = "Zip file was stored for offline processing" return -1, message, f2 diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 0ff3a4c4..53d34009 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -94,15 +94,11 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False): uploadoptions['file'] = 'media/'+filename uploadoptions['title'] = title - try: - print("Stravaid ",uploadoptions['stravaid']) - except KeyError: - pass - url = settings.UPLOAD_SERVICE_URL if not testing: response = requests.post(url,data=uploadoptions) + # print("Upload response status code",response.status_code, response.json()) if response.status_code == 200: response_json = response.json() workoutid = [int(response_json['id'])] @@ -137,21 +133,6 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False): if testing: print('Workout id = {workoutid}'.format(workoutid=workoutid)) - # if workoutid[0]: - # link = settings.SITE_URL+reverse( - # therower.defaultlandingpage, - # kwargs = { - # 'id':encoder.encode_hex(workoutid[0]), - # } - # ) - # - # if not testing: - # if therower.getemailnotifications and not therower.emailbounced: - # email_sent = send_confirm( - # therower.user, title, link, - # uploadoptions - # ) - return workoutid def get_from_address(message): @@ -272,6 +253,7 @@ class Command(BaseCommand): rower, datafile, title, uploadoptions, testing=testing ) + print(workoutid) except: print("Bad ZIP file") print(attachment.document.name) diff --git a/rowers/uploads.py b/rowers/uploads.py index b0676914..650b678e 100644 --- a/rowers/uploads.py +++ b/rowers/uploads.py @@ -352,7 +352,10 @@ def getboolean(uploadoptions,value,key): return uploadoptions def upload_options(body): - uploadoptions = {} + uploadoptions = { + 'boattype':'1x', + 'workouttype': 'rower', + } body = cleanbody(body) try: yml = (yaml.safe_load(body)) diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 60926281..f1bbf442 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -4493,9 +4493,15 @@ def workout_upload_api(request): notes=notes, ) - if id <= 0: - message = {'status':'false','message':'unable to process file'+message} + if id == 0: + if message is not None: + message = {'status':'false','message':'unable to process file'+message} + else: + message = {'status': 'false', 'message': 'unable to process file'} return JSONResponse(status=400,data=message) + if id == -1: + message = {'status': 'true', 'message':message} + return JSONResponse(status=200,data=message) w = Workout.objects.get(id=id) if len(stravaid)>0: