Processing of zipped files
This commit is contained in:
@@ -42,6 +42,7 @@ class DocumentsForm(forms.Form):
|
||||
('ergdata' , 'ErgData CSV'),
|
||||
('ergstick' , 'ErgStick CSV'),
|
||||
('painsleddesktop' , 'Painsled Desktop CSV'),
|
||||
('zip','Zipped file'),
|
||||
)
|
||||
title = forms.CharField(required=False)
|
||||
file = forms.FileField(required=True,
|
||||
|
||||
@@ -100,6 +100,14 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
|
||||
workouttype = 'rower'
|
||||
f2 = f2.name
|
||||
fileformat = get_file_type('media/'+f2)
|
||||
|
||||
if len(fileformat)==3 and fileformat[0]=='zip':
|
||||
f_to_be_deleted = f2
|
||||
with zipfile.ZipFile(f2) as z:
|
||||
f2 = z.extract(z.namelist()[0],path='media/')
|
||||
fileformat = fileformat[2]
|
||||
os.remove(f_to_be_deleted)
|
||||
|
||||
if fileformat == 'unknown':
|
||||
if settings.DEBUG:
|
||||
res = handle_sendemail_unrecognized.delay(f2,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import time
|
||||
import zipfile
|
||||
import operator
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.db.models import Q
|
||||
@@ -3694,6 +3695,12 @@ def workout_upload_view(request,message=""):
|
||||
|
||||
# new
|
||||
fileformat = get_file_type(f2)
|
||||
if len(fileformat)==3 and fileformat[0]=='zip':
|
||||
f_to_be_deleted = f2
|
||||
with zipfile.ZipFile(f2) as z:
|
||||
f2 = z.extract(z.namelist()[0],path='media/')
|
||||
fileformat = fileformat[2]
|
||||
os.remove(f_to_be_deleted)
|
||||
|
||||
if fileformat == 'unknown':
|
||||
message = "We couldn't recognize the file type"
|
||||
|
||||
@@ -48,7 +48,7 @@ def format_time(x,pos=None):
|
||||
def validate_file_extension(value):
|
||||
import os
|
||||
ext = os.path.splitext(value.name)[1]
|
||||
valid_extensions = ['.tcx','.csv','.TCX','.CSV','.fit','.FIT']
|
||||
valid_extensions = ['.tcx','.csv','.TCX','.CSV','.fit','.FIT','.zip','.ZIP']
|
||||
if not ext in valid_extensions:
|
||||
raise ValidationError(u'File not supported!')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user