Merge branch 'release/v11.06'
This commit is contained in:
@@ -15,6 +15,7 @@ from rowingdata import rowingdata as rrdata
|
|||||||
|
|
||||||
from rowingdata import rower as rrower
|
from rowingdata import rower as rrower
|
||||||
|
|
||||||
|
import yaml
|
||||||
import shutil
|
import shutil
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
@@ -1469,8 +1470,9 @@ def new_workout_from_file(r, f2,
|
|||||||
title='Workout',
|
title='Workout',
|
||||||
boattype='1x',
|
boattype='1x',
|
||||||
makeprivate=False,
|
makeprivate=False,
|
||||||
notes=''):
|
notes='',
|
||||||
message = None
|
uploadoptions={'boattype':'1x','workouttype':'rower'}):
|
||||||
|
message = ""
|
||||||
impeller = False
|
impeller = False
|
||||||
try:
|
try:
|
||||||
fileformat = get_file_type(f2)
|
fileformat = get_file_type(f2)
|
||||||
@@ -1483,18 +1485,21 @@ def new_workout_from_file(r, f2,
|
|||||||
oarlength = 2.89
|
oarlength = 2.89
|
||||||
inboard = 0.88
|
inboard = 0.88
|
||||||
if len(fileformat) == 3 and fileformat[0] == 'zip':
|
if len(fileformat) == 3 and fileformat[0] == 'zip':
|
||||||
|
uploadoptions['fromuploadform'] = True
|
||||||
|
bodyyaml = yaml.safe_dump(uploadoptions,default_flow_style=False)
|
||||||
f_to_be_deleted = f2
|
f_to_be_deleted = f2
|
||||||
impeller = False
|
impeller = False
|
||||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
||||||
msg = Message(mailbox=workoutsbox,
|
msg = Message(mailbox=workoutsbox,
|
||||||
from_header=r.user.email,
|
from_header=r.user.email,
|
||||||
subject = title)
|
subject = title,body=bodyyaml)
|
||||||
msg.save()
|
msg.save()
|
||||||
f3 = 'media/mailbox_attachments/'+f2[6:]
|
f3 = 'media/mailbox_attachments/'+f2[6:]
|
||||||
copyfile(f2,f3)
|
copyfile(f2,f3)
|
||||||
f3 = f3[6:]
|
f3 = f3[6:]
|
||||||
a = MessageAttachment(message=msg,document=f3)
|
a = MessageAttachment(message=msg,document=f3)
|
||||||
a.save()
|
a.save()
|
||||||
|
message = "Zip file was stored for offline processing"
|
||||||
|
|
||||||
return -1, message, f2
|
return -1, message, f2
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
users = User.objects.filter(username=uploadoptions['username'])
|
users = User.objects.filter(username=uploadoptions['username'])
|
||||||
if len(users)==1:
|
if len(users)==1:
|
||||||
therower = users[0].rower
|
therower = users[0].rower
|
||||||
|
elif uploadoptions['username'] == '':
|
||||||
|
therower = rower
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
@@ -94,15 +96,10 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
uploadoptions['file'] = 'media/'+filename
|
uploadoptions['file'] = 'media/'+filename
|
||||||
uploadoptions['title'] = title
|
uploadoptions['title'] = title
|
||||||
|
|
||||||
try:
|
|
||||||
print("Stravaid ",uploadoptions['stravaid'])
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
url = settings.UPLOAD_SERVICE_URL
|
url = settings.UPLOAD_SERVICE_URL
|
||||||
if not testing:
|
if not testing:
|
||||||
response = requests.post(url,data=uploadoptions)
|
response = requests.post(url,data=uploadoptions)
|
||||||
|
# print("Upload response status code",response.status_code, response.json())
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
response_json = response.json()
|
response_json = response.json()
|
||||||
workoutid = [int(response_json['id'])]
|
workoutid = [int(response_json['id'])]
|
||||||
@@ -137,21 +134,6 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
if testing:
|
if testing:
|
||||||
print('Workout id = {workoutid}'.format(workoutid=workoutid))
|
print('Workout id = {workoutid}'.format(workoutid=workoutid))
|
||||||
|
|
||||||
# if workoutid[0]:
|
|
||||||
# link = settings.SITE_URL+reverse(
|
|
||||||
# therower.defaultlandingpage,
|
|
||||||
# kwargs = {
|
|
||||||
# 'id':encoder.encode_hex(workoutid[0]),
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# if not testing:
|
|
||||||
# if therower.getemailnotifications and not therower.emailbounced:
|
|
||||||
# email_sent = send_confirm(
|
|
||||||
# therower.user, title, link,
|
|
||||||
# uploadoptions
|
|
||||||
# )
|
|
||||||
|
|
||||||
return workoutid
|
return workoutid
|
||||||
|
|
||||||
def get_from_address(message):
|
def get_from_address(message):
|
||||||
@@ -258,7 +240,6 @@ class Command(BaseCommand):
|
|||||||
attachment.delete()
|
attachment.delete()
|
||||||
for rower in rowers:
|
for rower in rowers:
|
||||||
if 'zip' in extension:
|
if 'zip' in extension:
|
||||||
try:
|
|
||||||
zip_file = zipfile.ZipFile(attachment.document)
|
zip_file = zipfile.ZipFile(attachment.document)
|
||||||
for id,filename in enumerate(zip_file.namelist()):
|
for id,filename in enumerate(zip_file.namelist()):
|
||||||
datafile = zip_file.extract(
|
datafile = zip_file.extract(
|
||||||
@@ -267,14 +248,11 @@ class Command(BaseCommand):
|
|||||||
title = name+' ('+str(id+1)+')'
|
title = name+' ('+str(id+1)+')'
|
||||||
else:
|
else:
|
||||||
title = name
|
title = name
|
||||||
|
|
||||||
workoutid = processattachment(
|
workoutid = processattachment(
|
||||||
rower, datafile, title, uploadoptions,
|
rower, datafile, title, uploadoptions,
|
||||||
testing=testing
|
testing=testing
|
||||||
)
|
)
|
||||||
except:
|
|
||||||
print("Bad ZIP file")
|
|
||||||
print(attachment.document.name)
|
|
||||||
else:
|
else:
|
||||||
# move attachment and make workout
|
# move attachment and make workout
|
||||||
if testing:
|
if testing:
|
||||||
|
|||||||
@@ -352,7 +352,10 @@ def getboolean(uploadoptions,value,key):
|
|||||||
return uploadoptions
|
return uploadoptions
|
||||||
|
|
||||||
def upload_options(body):
|
def upload_options(body):
|
||||||
uploadoptions = {}
|
uploadoptions = {
|
||||||
|
'boattype':'1x',
|
||||||
|
'workouttype': 'rower',
|
||||||
|
}
|
||||||
body = cleanbody(body)
|
body = cleanbody(body)
|
||||||
try:
|
try:
|
||||||
yml = (yaml.safe_load(body))
|
yml = (yaml.safe_load(body))
|
||||||
@@ -506,7 +509,7 @@ def make_private(w,options):
|
|||||||
|
|
||||||
def do_sync(w,options):
|
def do_sync(w,options):
|
||||||
try:
|
try:
|
||||||
if options['stravaid'] != 0:
|
if options['stravaid'] != 0 and options['stravaid'] != '':
|
||||||
w.uploadedtostrava = options['stravaid']
|
w.uploadedtostrava = options['stravaid']
|
||||||
options['upload_to_Strava'] = False
|
options['upload_to_Strava'] = False
|
||||||
w.save()
|
w.save()
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ def strokedatajson(request,id):
|
|||||||
POST: Add Stroke data to workout
|
POST: Add Stroke data to workout
|
||||||
GET: Get stroke data of workout
|
GET: Get stroke data of workout
|
||||||
"""
|
"""
|
||||||
row = get_workout_permitted(request.user,id)
|
row = get_object_or_404(Workout,pk=id)
|
||||||
|
if row.user != request.user.rower:
|
||||||
|
raise PermissionDenied("You have no access to this workout")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
id = int(id)
|
id = int(id)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ def workout_strava_upload_view(request,id=0):
|
|||||||
return HttpResponseRedirect("/rowers/me/stravaauthorize/")
|
return HttpResponseRedirect("/rowers/me/stravaauthorize/")
|
||||||
else:
|
else:
|
||||||
# ready to upload. Hurray
|
# ready to upload. Hurray
|
||||||
w = get_workout_permitted(request.user,id)
|
w = get_workout_by_opaqueid(request,id)
|
||||||
r = w.user
|
r = w.user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4406,7 +4406,6 @@ def workout_upload_api(request):
|
|||||||
except (KeyError,JSONDecodeError):
|
except (KeyError,JSONDecodeError):
|
||||||
post_data = request.POST
|
post_data = request.POST
|
||||||
|
|
||||||
|
|
||||||
# only allow local host
|
# only allow local host
|
||||||
hostt = request.get_host().split(':')
|
hostt = request.get_host().split(':')
|
||||||
if hostt[0] not in ['localhost','127.0.0.1','dev.rowsandall.com','rowsandall.com']:
|
if hostt[0] not in ['localhost','127.0.0.1','dev.rowsandall.com','rowsandall.com']:
|
||||||
@@ -4491,11 +4490,18 @@ def workout_upload_api(request):
|
|||||||
makeprivate=makeprivate,
|
makeprivate=makeprivate,
|
||||||
title = t,
|
title = t,
|
||||||
notes=notes,
|
notes=notes,
|
||||||
|
uploadoptions=post_data,
|
||||||
)
|
)
|
||||||
|
|
||||||
if id <= 0:
|
if id == 0:
|
||||||
|
if message is not None:
|
||||||
message = {'status':'false','message':'unable to process file'+message}
|
message = {'status':'false','message':'unable to process file'+message}
|
||||||
|
else:
|
||||||
|
message = {'status': 'false', 'message': 'unable to process file'}
|
||||||
return JSONResponse(status=400,data=message)
|
return JSONResponse(status=400,data=message)
|
||||||
|
if id == -1:
|
||||||
|
message = {'status': 'true', 'message':message}
|
||||||
|
return JSONResponse(status=200,data=message)
|
||||||
|
|
||||||
w = Workout.objects.get(id=id)
|
w = Workout.objects.get(id=id)
|
||||||
if len(stravaid)>0:
|
if len(stravaid)>0:
|
||||||
|
|||||||
Reference in New Issue
Block a user