Private
Public Access
1
0

Merge branch 'feature/multifilezip' into develop

This commit is contained in:
Sander Roosendaal
2017-02-13 19:25:37 +01:00
2 changed files with 36 additions and 12 deletions

View File

@@ -166,6 +166,8 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
except IOError:
f2 = f2.name+'.gz'
fileformat = get_file_type('media/'+f2)
except AttributeError:
fileformat = get_file_type('media/'+f2)
if len(fileformat)==3 and fileformat[0]=='zip':
f_to_be_deleted = f2

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,8 @@ class Command(BaseCommand):
attachments = MessageAttachment.objects.all()
cntr = 0
for a in attachments:
extension = a.document.name[-3:].lower()
print "aap ",extension
donotdelete = 0
m = Message.objects.get(id=a.message_id)
from_address = m.from_address[0].lower()
@@ -55,20 +59,38 @@ 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,path='media/')
try:
wid = [
make_new_workout_from_email(rr,f2[6:],name)
]
res += wid
link = 'http://rowsandall.com/rowers/workout/'+str(wid)+'/edit'
dd = send_confirm(u,name,link)
except:
pass
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