added multi file zip support
This commit is contained in:
@@ -166,6 +166,8 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
|
|||||||
except IOError:
|
except IOError:
|
||||||
f2 = f2.name+'.gz'
|
f2 = f2.name+'.gz'
|
||||||
fileformat = get_file_type('media/'+f2)
|
fileformat = get_file_type('media/'+f2)
|
||||||
|
except AttributeError:
|
||||||
|
fileformat = get_file_type('media/'+f2)
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class Command(BaseCommand):
|
|||||||
attachments = MessageAttachment.objects.all()
|
attachments = MessageAttachment.objects.all()
|
||||||
cntr = 0
|
cntr = 0
|
||||||
for a in attachments:
|
for a in attachments:
|
||||||
extension = a.document[-3:].lower()
|
extension = a.document.name[-3:].lower()
|
||||||
|
print "aap ",extension
|
||||||
donotdelete = 0
|
donotdelete = 0
|
||||||
m = Message.objects.get(id=a.message_id)
|
m = Message.objects.get(id=a.message_id)
|
||||||
from_address = m.from_address[0]
|
from_address = m.from_address[0]
|
||||||
@@ -61,18 +62,16 @@ class Command(BaseCommand):
|
|||||||
if extension == 'zip':
|
if extension == 'zip':
|
||||||
z = zipfile.ZipFile(a.document)
|
z = zipfile.ZipFile(a.document)
|
||||||
for f in z.namelist():
|
for f in z.namelist():
|
||||||
f2 = z.extract(f)
|
f2 = z.extract(f,path='media/')
|
||||||
try:
|
try:
|
||||||
wid = [
|
wid = [
|
||||||
make_new_workout_from_email(rr,f2,name)
|
make_new_workout_from_email(rr,f2[6:],name)
|
||||||
]
|
]
|
||||||
res += wid
|
res += wid
|
||||||
link = 'http://rowsandall.com/rowers/workout/'+str(wid)+'/edit'
|
link = 'http://rowsandall.com/rowers/workout/'+str(wid)+'/edit'
|
||||||
dd = send_confirm(u,name,link)
|
dd = send_confirm(u,name,link)
|
||||||
except:
|
except:
|
||||||
res += ['fail: '+f]
|
pass
|
||||||
donotdelete = 1
|
|
||||||
os.remove(f2)
|
|
||||||
else:
|
else:
|
||||||
# move attachment and make workout
|
# move attachment and make workout
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user