Email processing now uses new API
This commit is contained in:
@@ -10,6 +10,9 @@ import re
|
|||||||
import time
|
import time
|
||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
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):
|
def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||||
try:
|
try:
|
||||||
filename = fileobj.name
|
filename = fileobj.name
|
||||||
|
# filename = os.path.abspath(fileobj.name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
filename = fileobj[6:]
|
filename = fileobj[6:]
|
||||||
if testing:
|
if testing:
|
||||||
@@ -85,9 +89,19 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
therower = rower
|
therower = rower
|
||||||
|
|
||||||
|
|
||||||
workoutid = [
|
uploadoptions['secret'] = settings.UPLOAD_SERVICE_SECRET
|
||||||
make_new_workout_from_email(therower, filename, title,testing=testing)
|
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:
|
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:
|
if not testing:
|
||||||
workout = Workout.objects.get(id=workoutid[0])
|
if therower.getemailnotifications and not therower.emailbounced:
|
||||||
uploads.make_private(workout, uploadoptions)
|
email_sent = send_confirm(
|
||||||
uploads.set_workouttype(workout, uploadoptions)
|
therower.user, title, link,
|
||||||
uploads.do_sync(workout, uploadoptions)
|
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
|
|
||||||
|
|
||||||
return workoutid
|
return workoutid
|
||||||
|
|
||||||
|
|||||||
@@ -4418,11 +4418,12 @@ def workout_upload_api(request):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
message = {'status':'false','message':'no filename given'}
|
message = {'status':'false','message':'no filename given'}
|
||||||
return JSONResponse(status=400,data=message)
|
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():
|
if form.is_valid():
|
||||||
t = form.cleaned_data['title']
|
t = form.cleaned_data['title']
|
||||||
offline = True
|
|
||||||
offline = form.cleaned_data['offline']
|
|
||||||
boattype = form.cleaned_data['boattype']
|
boattype = form.cleaned_data['boattype']
|
||||||
workouttype = form.cleaned_data['workouttype']
|
workouttype = form.cleaned_data['workouttype']
|
||||||
if rowerform.is_valid():
|
if rowerform.is_valid():
|
||||||
|
|||||||
Reference in New Issue
Block a user