Private
Public Access
1
0

first attempt multi zip

This commit is contained in:
Sander Roosendaal
2017-02-13 17:42:03 +01:00
parent 083c7e5916
commit bac131917d

View File

@@ -7,6 +7,8 @@ sys.path.append('$path_to_root_of_project$/$project_name$')
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
import zipfile
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
#from rowers.mailprocessing import processattachments
@@ -45,6 +47,7 @@ class Command(BaseCommand):
attachments = MessageAttachment.objects.all()
cntr = 0
for a in attachments:
extension = a.document[-3:].lower()
donotdelete = 0
m = Message.objects.get(id=a.message_id)
from_address = m.from_address[0]
@@ -55,20 +58,40 @@ class Command(BaseCommand):
for u in theusers:
try:
rr = Rower.objects.get(user=u.id)
if extension == 'zip':
z = zipfile.ZipFile(a.document)
for f in z.namelist():
f2 = z.extract(f)
try:
wid = [
make_new_workout_from_email(rr,f2,name)
]
res += wid
link = 'http://rowsandall.com/rowers/workout/'+str(wid)+'/edit'
dd = send_confirm(u,name,link)
except:
res += ['fail: '+f]
donotdelete = 1
os.remove(f2)
else:
# move attachment and make workout
try:
wid = [make_new_workout_from_email(rr,a.document,name)]
res += wid
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
try:
wid = [
make_new_workout_from_email(rr,
a.document,
name)
]
res += wid
link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
except:
# replace with code to process error
res += ['fail: '+name]
donotdelete = 1
try:
dd = send_confirm(u,name,link)
except:
pass
except:
# replace with code to process error
res += ['fail: '+name]
donotdelete = 1
try:
dd = send_confirm(u,name,link)
except:
pass
except Rower.DoesNotExist:
pass