Private
Public Access
1
0

Merge branch 'release/zips'

This commit is contained in:
Sander Roosendaal
2016-12-19 17:58:21 +01:00
4 changed files with 57 additions and 18 deletions

View File

@@ -42,6 +42,7 @@ class DocumentsForm(forms.Form):
('ergdata' , 'ErgData CSV'), ('ergdata' , 'ErgData CSV'),
('ergstick' , 'ErgStick CSV'), ('ergstick' , 'ErgStick CSV'),
('painsleddesktop' , 'Painsled Desktop CSV'), ('painsleddesktop' , 'Painsled Desktop CSV'),
('zip','Zipped file'),
) )
title = forms.CharField(required=False) title = forms.CharField(required=False)
file = forms.FileField(required=True, file = forms.FileField(required=True,

View File

@@ -100,6 +100,14 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
workouttype = 'rower' workouttype = 'rower'
f2 = f2.name f2 = f2.name
fileformat = get_file_type('media/'+f2) 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 fileformat == 'unknown':
if settings.DEBUG: if settings.DEBUG:
res = handle_sendemail_unrecognized.delay(f2, res = handle_sendemail_unrecognized.delay(f2,

View File

@@ -1,4 +1,5 @@
import time import time
import zipfile
import operator import operator
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.db.models import Q from django.db.models import Q
@@ -829,9 +830,11 @@ def list_c2_upload_view(request,id=0):
@login_required() @login_required()
def workout_tcxemail_view(request,id=0): def workout_tcxemail_view(request,id=0):
message = "" message = ""
successmessage = ""
r = Rower.objects.get(user=request.user) r = Rower.objects.get(user=request.user)
w = Workout.objects.get(id=id) w = Workout.objects.get(id=id)
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
try:
tcxfile = stravastuff.createstravaworkoutdata(w) tcxfile = stravastuff.createstravaworkoutdata(w)
if settings.DEBUG: if settings.DEBUG:
res = handle_sendemailtcx.delay(r.user.first_name, res = handle_sendemailtcx.delay(r.user.first_name,
@@ -849,6 +852,20 @@ def workout_tcxemail_view(request,id=0):
'id':str(w.id), 'id':str(w.id),
'successmessage':successmessage, 'successmessage':successmessage,
}) })
except:
successmessage = ""
message = "Something went wrong (strava export) "+str(sys.exc_info()[0])
with open("media/c2errors.log","a") as errorlog:
errorstring = str(sys.exc_info()[0])
timestr = strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\r\n")
url = reverse(workout_export_view,
kwargs = {
'id':str(w.id),
'message':message,
})
response = HttpResponseRedirect(url) response = HttpResponseRedirect(url)
else: else:
@@ -977,7 +994,9 @@ def workout_c2_upload_view(request,id=0):
except: except:
message = "Unexpected Error: "+str(sys.exc_info()[0]) message = "Unexpected Error: "+str(sys.exc_info()[0])
with open("media/c2errors.log","a") as errorlog: with open("media/c2errors.log","a") as errorlog:
errorlog.write("Unexpected Error: "+str(sys.exc_info()[0])) errorstring = str(sys.exc_info()[0])
timestr = time.strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\n")
# check for duplicate error first # check for duplicate error first
if (response.status_code == 409 ): if (response.status_code == 409 ):
@@ -995,13 +1014,18 @@ def workout_c2_upload_view(request,id=0):
except: except:
message = "Something went wrong in workout_c2_upload_view. Response code 200/201 but C2 sync failed: "+response.text message = "Something went wrong in workout_c2_upload_view. Response code 200/201 but C2 sync failed: "+response.text
with open("media/c2errors.log","a") as errorlog: with open("media/c2errors.log","a") as errorlog:
errorlog.write("Unexpected Error: "+str(sys.exc_info()[0])) errorstring = str(sys.exc_info()[0])
timestr = time.strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\n")
else: else:
s = response s = response
message = "Something went wrong in workout_c2_upload_view. C2 sync failed." message = "Something went wrong in workout_c2_upload_view. C2 sync failed."
with open("media/c2errors.log","a") as errorlog: with open("media/c2errors.log","a") as errorlog:
errorlog.write("Unexpected Error: "+response.text()) errorstring = str(sys.exc_info()[0])
timestr = time.strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\n")
else: else:
message = "You are not authorized to upload this workout" message = "You are not authorized to upload this workout"
@@ -3694,6 +3718,12 @@ def workout_upload_view(request,message=""):
# new # new
fileformat = get_file_type(f2) 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': if fileformat == 'unknown':
message = "We couldn't recognize the file type" message = "We couldn't recognize the file type"

View File

@@ -48,7 +48,7 @@ def format_time(x,pos=None):
def validate_file_extension(value): def validate_file_extension(value):
import os import os
ext = os.path.splitext(value.name)[1] 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: if not ext in valid_extensions:
raise ValidationError(u'File not supported!') raise ValidationError(u'File not supported!')