Email processing now uses new API
This commit is contained in:
@@ -10,6 +10,9 @@ import re
|
||||
import time
|
||||
from time import strftime
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
import io
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
@@ -56,6 +59,7 @@ def rdata(file_obj, rower=rrower()):
|
||||
def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
try:
|
||||
filename = fileobj.name
|
||||
# filename = os.path.abspath(fileobj.name)
|
||||
except AttributeError:
|
||||
filename = fileobj[6:]
|
||||
if testing:
|
||||
@@ -85,9 +89,19 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
therower = rower
|
||||
|
||||
|
||||
workoutid = [
|
||||
make_new_workout_from_email(therower, filename, title,testing=testing)
|
||||
]
|
||||
uploadoptions['secret'] = settings.UPLOAD_SERVICE_SECRET
|
||||
uploadoptions['user'] = therower.user.id
|
||||
uploadoptions['file'] = 'media/'+filename
|
||||
uploadoptions['title'] = title
|
||||
|
||||
|
||||
url = "http://localhost:8000/rowers/workout/api/upload/"
|
||||
response = requests.post(url,data=uploadoptions)
|
||||
if response.status_code == 200:
|
||||
response_json = response.json()
|
||||
workoutid = [int(response_json['id'])]
|
||||
else:
|
||||
workoutid = [0]
|
||||
|
||||
|
||||
if 'raceid' in uploadoptions and workoutid[0] and rower.user.is_staff:
|
||||
@@ -114,41 +128,12 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
}
|
||||
)
|
||||
|
||||
if uploadoptions and not 'error' in uploadoptions:
|
||||
workout = Workout.objects.get(id=workoutid[0])
|
||||
uploads.make_private(workout, uploadoptions)
|
||||
uploads.set_workouttype(workout, uploadoptions)
|
||||
uploads.do_sync(workout, uploadoptions)
|
||||
if 'make_plot' in uploadoptions:
|
||||
plottype = uploadoptions['plottype']
|
||||
workoutcsvfilename = workout.csvfilename[6:-4]
|
||||
timestr = strftime("%Y%m%d-%H%M%S")
|
||||
imagename = workoutcsvfilename + timestr + '.png'
|
||||
result,jobid = uploads.make_plot(
|
||||
workout.user, workout, workoutcsvfilename,
|
||||
workout.csvfilename,
|
||||
plottype, title,
|
||||
imagename=imagename
|
||||
)
|
||||
try:
|
||||
if workoutid and not testing:
|
||||
if therower.getemailnotifications and not therower.emailbounced:
|
||||
email_sent = send_confirm(
|
||||
therower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
time.sleep(10)
|
||||
except:
|
||||
try:
|
||||
time.sleep(10)
|
||||
if workoutid:
|
||||
if therower.getemailnotifications and not therower.emailbounced:
|
||||
email_sent = send_confirm(
|
||||
therower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
except:
|
||||
pass
|
||||
if not testing:
|
||||
if therower.getemailnotifications and not therower.emailbounced:
|
||||
email_sent = send_confirm(
|
||||
therower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
|
||||
return workoutid
|
||||
|
||||
|
||||
@@ -4418,11 +4418,12 @@ def workout_upload_api(request):
|
||||
except KeyError:
|
||||
message = {'status':'false','message':'no filename given'}
|
||||
return JSONResponse(status=400,data=message)
|
||||
except FileNotFoundError:
|
||||
message = {'status':'false','message':'could not find file'}
|
||||
return JSONResponse(status=400,data=message)
|
||||
|
||||
if form.is_valid():
|
||||
t = form.cleaned_data['title']
|
||||
offline = True
|
||||
offline = form.cleaned_data['offline']
|
||||
boattype = form.cleaned_data['boattype']
|
||||
workouttype = form.cleaned_data['workouttype']
|
||||
if rowerform.is_valid():
|
||||
|
||||
Reference in New Issue
Block a user