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'),
('ergstick' , 'ErgStick CSV'),
('painsleddesktop' , 'Painsled Desktop CSV'),
('zip','Zipped file'),
)
title = forms.CharField(required=False)
file = forms.FileField(required=True,

View File

@@ -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,

View File

@@ -1,4 +1,5 @@
import time
import zipfile
import operator
from django.views.generic.base import TemplateView
from django.db.models import Q
@@ -829,26 +830,42 @@ def list_c2_upload_view(request,id=0):
@login_required()
def workout_tcxemail_view(request,id=0):
message = ""
successmessage = ""
r = Rower.objects.get(user=request.user)
w = Workout.objects.get(id=id)
if (checkworkoutuser(request.user,w)):
tcxfile = stravastuff.createstravaworkoutdata(w)
if settings.DEBUG:
res = handle_sendemailtcx.delay(r.user.first_name,
r.user.last_name,
r.user.email,tcxfile)
try:
tcxfile = stravastuff.createstravaworkoutdata(w)
if settings.DEBUG:
res = handle_sendemailtcx.delay(r.user.first_name,
r.user.last_name,
r.user.email,tcxfile)
else:
res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name,
r.user.last_name,
r.user.email,tcxfile)
else:
res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name,
r.user.last_name,
r.user.email,tcxfile)
successmessage = "The TCX file was sent to you per email"
url = reverse(workout_export_view,
kwargs = {
'id':str(w.id),
'successmessage':successmessage,
successmessage = "The TCX file was sent to you per email"
url = reverse(workout_export_view,
kwargs = {
'id':str(w.id),
'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)
else:
@@ -977,7 +994,9 @@ def workout_c2_upload_view(request,id=0):
except:
message = "Unexpected Error: "+str(sys.exc_info()[0])
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
if (response.status_code == 409 ):
@@ -995,13 +1014,18 @@ def workout_c2_upload_view(request,id=0):
except:
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:
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:
s = response
message = "Something went wrong in workout_c2_upload_view. C2 sync failed."
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:
message = "You are not authorized to upload this workout"
@@ -3694,6 +3718,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"

View File

@@ -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!')