Private
Public Access
1
0

Merge tag 'zipfix2' into develop

zipfix2
This commit is contained in:
Sander Roosendaal
2016-12-19 19:17:09 +01:00

View File

@@ -20,6 +20,7 @@ from rowingdata import summarydata,get_file_type
from scipy.signal import savgol_filter
import zipfile
import os
def send_confirm(u,name,link):
fullemail = u.email
@@ -97,7 +98,53 @@ def processattachments():
m.delete()
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 = 'http://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):
workouttype = 'rower'
f2 = f2.name
@@ -105,10 +152,10 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
if len(fileformat)==3 and fileformat[0]=='zip':
f_to_be_deleted = f2
with zipfile.ZipFile(f2) as z:
f2 = z.extract(z.namelist()[0],path='media/')
with zipfile.ZipFile('media/'+f2) as z:
f2 = z.extract(z.namelist()[0],path='media/')[6:]
fileformat = fileformat[2]
os.remove(f_to_be_deleted)
print f2
if fileformat == 'unknown':
if settings.DEBUG: