zip file now with enumerated workout title
This commit is contained in:
@@ -8,6 +8,8 @@ from rowingdata import rowingdata as rrdata
|
|||||||
|
|
||||||
from rowingdata import rower as rrower
|
from rowingdata import rower as rrower
|
||||||
|
|
||||||
|
from shutil import copyfile
|
||||||
|
|
||||||
from rowingdata import get_file_type, get_empower_rigging
|
from rowingdata import get_file_type, get_empower_rigging
|
||||||
|
|
||||||
from rowers.tasks import handle_sendemail_unrecognized
|
from rowers.tasks import handle_sendemail_unrecognized
|
||||||
@@ -17,6 +19,7 @@ from pandas import DataFrame, Series
|
|||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.timezone import get_current_timezone
|
from django.utils.timezone import get_current_timezone
|
||||||
|
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
||||||
|
|
||||||
from time import strftime
|
from time import strftime
|
||||||
import arrow
|
import arrow
|
||||||
@@ -975,14 +978,24 @@ def new_workout_from_file(r, f2,
|
|||||||
inboard = 0.88
|
inboard = 0.88
|
||||||
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
|
||||||
title = os.path.basename(f2)
|
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
||||||
res = myqueue(
|
msg = Message(mailbox=workoutsbox,
|
||||||
queuelow,
|
from_header=r.user.email,
|
||||||
handle_zip_file,
|
subject = title)
|
||||||
r.user.email,
|
msg.save()
|
||||||
title,
|
f3 = 'media/mailbox_attachments/'+f2[6:]
|
||||||
f2
|
copyfile(f2,f3)
|
||||||
)
|
f3 = f3[6:]
|
||||||
|
a = MessageAttachment(message=msg,document=f3)
|
||||||
|
a.save()
|
||||||
|
|
||||||
|
# res = myqueue(
|
||||||
|
# queuelow,
|
||||||
|
# handle_zip_file,
|
||||||
|
# r.user.email,
|
||||||
|
# title,
|
||||||
|
# f2
|
||||||
|
# )
|
||||||
|
|
||||||
return -1, message, f2
|
return -1, message, f2
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,15 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
return workoutid
|
return workoutid
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
'--testing',
|
||||||
|
action='store_true',
|
||||||
|
dest='testing',
|
||||||
|
default=False,
|
||||||
|
help="Run in testing mode, don't send emails",
|
||||||
|
)
|
||||||
|
|
||||||
"""Run the Email processing command """
|
"""Run the Email processing command """
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
attachments = MessageAttachment.objects.all()
|
attachments = MessageAttachment.objects.all()
|
||||||
@@ -119,9 +128,9 @@ class Command(BaseCommand):
|
|||||||
for rower in rowers:
|
for rower in rowers:
|
||||||
if extension == 'zip':
|
if extension == 'zip':
|
||||||
zip_file = zipfile.ZipFile(attachment.document)
|
zip_file = zipfile.ZipFile(attachment.document)
|
||||||
for filename in zip_file.namelist():
|
for id,filename in enumerate(zip_file.namelist()):
|
||||||
datafile = zip_file.extract(filename, path='media/')
|
datafile = zip_file.extract(filename, path='media/')
|
||||||
title = os.path.basename(datafile)
|
title = name+' ('+str(id)+')'
|
||||||
workoutid = processattachment(
|
workoutid = processattachment(
|
||||||
rower, datafile, title, uploadoptions,
|
rower, datafile, title, uploadoptions,
|
||||||
testing=testing
|
testing=testing
|
||||||
|
|||||||
BIN
rowers/testdata/emails/testdata.ZIP
vendored
Normal file
BIN
rowers/testdata/emails/testdata.ZIP
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user