almost passing tests
This commit is contained in:
@@ -42,7 +42,9 @@ from pyarrow.lib import ArrowInvalid
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.timezone import get_current_timezone
|
||||
#from django_mailbox.models import Message,Mailbox,MessageAttachment
|
||||
from django.urls import reverse
|
||||
import requests
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from time import strftime
|
||||
@@ -2102,21 +2104,26 @@ def new_workout_from_file(r, f2,
|
||||
|
||||
# Save zip files to email box for further processing
|
||||
if len(fileformat) == 3 and fileformat[0] == 'zip': # pragma: no cover
|
||||
uploadoptions['fromuploadform'] = True
|
||||
bodyyaml = yaml.safe_dump(uploadoptions,default_flow_style=False)
|
||||
f_to_be_deleted = f2
|
||||
uploadoptions['secret'] = settings.UPLOAD_SERVICE_SECRET
|
||||
uploadoptions['user'] = r.user.id
|
||||
uploadoptions['title'] = title
|
||||
try:
|
||||
zip_file = zipfile.ZipFile(f2)
|
||||
for id,filename in enumerate(zip_file.namelist()):
|
||||
datafile = zip_file.extract(filename, path='media/')
|
||||
if id>0:
|
||||
uploadoptions['title'] = title+' ('+str(id+1)+')'
|
||||
else:
|
||||
uploadoptions['title'] = title
|
||||
|
||||
uploadoptions['file'] = datafile
|
||||
url = settings.UPLOAD_SERVICE_URL
|
||||
|
||||
response = requests.post(url,uploadoptions)
|
||||
|
||||
except BadZipFile: # pragma: no cover
|
||||
pass
|
||||
|
||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
||||
msg = Message(mailbox=workoutsbox,
|
||||
from_header=r.user.email,
|
||||
subject = title,body=bodyyaml)
|
||||
msg.save()
|
||||
f3 = 'media/mailbox_attachments/'+f2[6:]
|
||||
copyfile(f2,f3)
|
||||
f3 = f3[6:]
|
||||
a = MessageAttachment(message=msg,document=f3)
|
||||
a.save()
|
||||
message = "Zip file was stored for offline processing"
|
||||
|
||||
return -1, message, f2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user