Merge branch 'develop' into feature/restapi
This commit is contained in:
@@ -19,6 +19,9 @@ from rowingdata import summarydata,get_file_type
|
|||||||
|
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
|
|
||||||
|
import zipfile
|
||||||
|
import os
|
||||||
|
|
||||||
def send_confirm(u,name,link):
|
def send_confirm(u,name,link):
|
||||||
fullemail = u.email
|
fullemail = u.email
|
||||||
subject = 'Workout added: '+name
|
subject = 'Workout added: '+name
|
||||||
@@ -71,7 +74,7 @@ def processattachments():
|
|||||||
wid = [make_new_workout_from_email(rr,a.document,name)]
|
wid = [make_new_workout_from_email(rr,a.document,name)]
|
||||||
res += wid
|
res += wid
|
||||||
print wid
|
print wid
|
||||||
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
||||||
dd = send_confirm(u,name,link)
|
dd = send_confirm(u,name,link)
|
||||||
except:
|
except:
|
||||||
# replace with code to process error
|
# replace with code to process error
|
||||||
@@ -95,7 +98,53 @@ def processattachments():
|
|||||||
m.delete()
|
m.delete()
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def processattachments_debug():
|
||||||
|
res = []
|
||||||
|
attachments = MessageAttachment.objects.all()
|
||||||
|
for a in attachments:
|
||||||
|
donotdelete = 1
|
||||||
|
m = Message.objects.get(id=a.message_id)
|
||||||
|
from_address = m.from_address[0]
|
||||||
|
name = m.subject
|
||||||
|
|
||||||
|
# get a list of users
|
||||||
|
theusers = User.objects.filter(email=from_address)
|
||||||
|
print theusers
|
||||||
|
for u in theusers:
|
||||||
|
try:
|
||||||
|
rr = Rower.objects.get(user=u.id)
|
||||||
|
doorgaan = 1
|
||||||
|
except:
|
||||||
|
doorgaan = 0
|
||||||
|
if doorgaan:
|
||||||
|
# move attachment and make workout
|
||||||
|
print a.document
|
||||||
|
print name
|
||||||
|
wid = [make_new_workout_from_email(rr,a.document,name)]
|
||||||
|
res += wid
|
||||||
|
print wid
|
||||||
|
link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
|
||||||
|
dd = send_confirm(u,name,link)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# remove attachment
|
||||||
|
if donotdelete == 0:
|
||||||
|
a.delete()
|
||||||
|
|
||||||
|
if m.attachments.exists()==False:
|
||||||
|
# no attachments, so can be deleted
|
||||||
|
m.delete()
|
||||||
|
|
||||||
|
mm = Message.objects.all()
|
||||||
|
for m in mm:
|
||||||
|
if m.attachments.exists()==False:
|
||||||
|
m.delete()
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def make_new_workout_from_email(rr,f2,name,cntr=0):
|
def make_new_workout_from_email(rr,f2,name,cntr=0):
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
f2 = f2.name
|
f2 = f2.name
|
||||||
@@ -103,10 +152,10 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
|
|||||||
|
|
||||||
if len(fileformat)==3 and fileformat[0]=='zip':
|
if len(fileformat)==3 and fileformat[0]=='zip':
|
||||||
f_to_be_deleted = f2
|
f_to_be_deleted = f2
|
||||||
with zipfile.ZipFile(f2) as z:
|
with zipfile.ZipFile('media/'+f2) as z:
|
||||||
f2 = z.extract(z.namelist()[0],path='media/')
|
f2 = z.extract(z.namelist()[0],path='media/')[6:]
|
||||||
fileformat = fileformat[2]
|
fileformat = fileformat[2]
|
||||||
os.remove(f_to_be_deleted)
|
print f2
|
||||||
|
|
||||||
if fileformat == 'unknown':
|
if fileformat == 'unknown':
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|||||||
@@ -834,26 +834,42 @@ def list_c2_upload_view(request,id=0):
|
|||||||
@login_required()
|
@login_required()
|
||||||
def workout_tcxemail_view(request,id=0):
|
def workout_tcxemail_view(request,id=0):
|
||||||
message = ""
|
message = ""
|
||||||
|
successmessage = ""
|
||||||
r = Rower.objects.get(user=request.user)
|
r = Rower.objects.get(user=request.user)
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
if (checkworkoutuser(request.user,w)):
|
if (checkworkoutuser(request.user,w)):
|
||||||
tcxfile = stravastuff.createstravaworkoutdata(w)
|
try:
|
||||||
if settings.DEBUG:
|
tcxfile = stravastuff.createstravaworkoutdata(w)
|
||||||
res = handle_sendemailtcx.delay(r.user.first_name,
|
if settings.DEBUG:
|
||||||
r.user.last_name,
|
res = handle_sendemailtcx.delay(r.user.first_name,
|
||||||
r.user.email,tcxfile)
|
r.user.last_name,
|
||||||
|
r.user.email,tcxfile)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name,
|
res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name,
|
||||||
r.user.last_name,
|
r.user.last_name,
|
||||||
r.user.email,tcxfile)
|
r.user.email,tcxfile)
|
||||||
|
|
||||||
successmessage = "The TCX file was sent to you per email"
|
successmessage = "The TCX file was sent to you per email"
|
||||||
url = reverse(workout_export_view,
|
url = reverse(workout_export_view,
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'id':str(w.id),
|
'id':str(w.id),
|
||||||
'successmessage':successmessage,
|
'successmessage':successmessage,
|
||||||
})
|
})
|
||||||
|
except:
|
||||||
|
successmessage = ""
|
||||||
|
message = "Something went wrong (strava export) "+str(sys.exc_info()[0])
|
||||||
|
with open("media/c2errors.log","a") as errorlog:
|
||||||
|
errorstring = str(sys.exc_info()[0])
|
||||||
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
errorlog.write(timestr+errorstring+"\r\n")
|
||||||
|
|
||||||
|
url = reverse(workout_export_view,
|
||||||
|
kwargs = {
|
||||||
|
'id':str(w.id),
|
||||||
|
'message':message,
|
||||||
|
})
|
||||||
|
|
||||||
response = HttpResponseRedirect(url)
|
response = HttpResponseRedirect(url)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -982,7 +998,9 @@ def workout_c2_upload_view(request,id=0):
|
|||||||
except:
|
except:
|
||||||
message = "Unexpected Error: "+str(sys.exc_info()[0])
|
message = "Unexpected Error: "+str(sys.exc_info()[0])
|
||||||
with open("media/c2errors.log","a") as errorlog:
|
with open("media/c2errors.log","a") as errorlog:
|
||||||
errorlog.write("Unexpected Error: "+str(sys.exc_info()[0]))
|
errorstring = str(sys.exc_info()[0])
|
||||||
|
timestr = time.strftime("%Y%m%d-%H%M%S")
|
||||||
|
errorlog.write(timestr+errorstring+"\n")
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
if (response.status_code == 409 ):
|
if (response.status_code == 409 ):
|
||||||
@@ -1000,13 +1018,18 @@ def workout_c2_upload_view(request,id=0):
|
|||||||
except:
|
except:
|
||||||
message = "Something went wrong in workout_c2_upload_view. Response code 200/201 but C2 sync failed: "+response.text
|
message = "Something went wrong in workout_c2_upload_view. Response code 200/201 but C2 sync failed: "+response.text
|
||||||
with open("media/c2errors.log","a") as errorlog:
|
with open("media/c2errors.log","a") as errorlog:
|
||||||
errorlog.write("Unexpected Error: "+str(sys.exc_info()[0]))
|
errorstring = str(sys.exc_info()[0])
|
||||||
|
timestr = time.strftime("%Y%m%d-%H%M%S")
|
||||||
|
errorlog.write(timestr+errorstring+"\n")
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
s = response
|
s = response
|
||||||
message = "Something went wrong in workout_c2_upload_view. C2 sync failed."
|
message = "Something went wrong in workout_c2_upload_view. C2 sync failed."
|
||||||
with open("media/c2errors.log","a") as errorlog:
|
with open("media/c2errors.log","a") as errorlog:
|
||||||
errorlog.write("Unexpected Error: "+response.text())
|
errorstring = str(sys.exc_info()[0])
|
||||||
|
timestr = time.strftime("%Y%m%d-%H%M%S")
|
||||||
|
errorlog.write(timestr+errorstring+"\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message = "You are not authorized to upload this workout"
|
message = "You are not authorized to upload this workout"
|
||||||
|
|||||||
Reference in New Issue
Block a user