Private
Public Access
1
0

further improvements

This commit is contained in:
Sander Roosendaal
2020-02-09 14:13:03 +01:00
parent 424178ac0e
commit 02a37e9657
5 changed files with 29 additions and 19 deletions

View File

@@ -3,7 +3,6 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
# All the data preparation, data cleaning and data mangling should
# be defined here
from __future__ import unicode_literals, absolute_import
@@ -1568,7 +1567,6 @@ def new_workout_from_file(r, f2,
if workoutsource is None:
workoutsource = fileformat
print(f2,'final name')
id, message = save_workout_database(
f2, r,
notes=notes,

View File

@@ -7,6 +7,11 @@ import time
import gzip
import shutil
import hashlib
import uuid
from django.core.exceptions import ValidationError
def format_pace_tick(x,pos=None):
@@ -26,7 +31,7 @@ def format_time_tick(x,pos=None):
def format_pace(x,pos=None):
if isinf(x) or isnan(x):
x=0
min=int(x/60)
sec=(x-min*60.)
@@ -73,14 +78,14 @@ def must_be_csv(value):
valid_extensions = ['.csv','.CSV']
if not ext in valid_extensions:
raise ValidationError(u'File not supported!')
def validate_kml(value):
import os
ext = os.path.splitext(value.name)[1]
valid_extensions = ['.kml','.KML']
if not ext in valid_extensions:
raise ValidationError(u'File not supported!')
def handle_uploaded_image(i):
from io import StringIO, BytesIO
@@ -92,8 +97,8 @@ def handle_uploaded_image(i):
image_str += chunk
imagefile = BytesIO(image_str)
image = Image.open(i)
try:
@@ -105,7 +110,7 @@ def handle_uploaded_image(i):
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
exif = {'orientation':0}
if image.mode not in ("L", "RGB"):
image = image.convert("RGB")
@@ -128,18 +133,17 @@ def handle_uploaded_image(i):
filename2 = os.path.join('static/plots/',filename)
image.save(filename2,'JPEG')
return filename,filename2
def handle_uploaded_file(f):
fname = f.name
timestr = time.strftime("%Y%m%d-%H%M%S")
timestr = uuid.uuid4().hex[:10]+'-'+time.strftime("%Y%m%d-%H%M%S")
fname = timestr+'-'+fname
fname2 = 'media/'+fname
with open(fname2,'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
return fname,fname2
return fname,fname2

View File

@@ -63,7 +63,7 @@ workout run
'upload_to_C2': False,
'plottype': 'timeplot',
'file': 'media/mailbox_attachments/colin3.csv',
'secret': 'potjandorie',
'secret': settings.UPLOAD_SERVICE_SECRET,
'user': 1,
}

View File

@@ -4391,15 +4391,20 @@ def workout_toggle_ranking(request,id=0):
@csrf_exempt
def workout_upload_api(request):
if request.method != 'POST':
raise PermissionDenied("This view cannot be accessed")
message = {'status':'false','message':'this view cannot be accessed through GET'}
return JSONResponse(status=403,data=message)
# only allow local host
print(request.get_host(),'get_host')
hostt = request.get_host().split(':')
if hostt[0] not in ['localhost','127.0.0.1']:
message = {'status':'false','message':'permission denied'}
return JSONResponse(status=403,data=message)
# check credentials here
secret = request.POST['secret']
if secret != 'potjandorie':
raise PermissionDenied("Invalid credentials")
if secret != settings.UPLOAD_SERVICE_SECRET:
message = {'status':'false','message':'invalid credentials'}
return JSONResponse(status=403,data=message)
form = DocumentsForm(request.POST)
optionsform = TeamUploadOptionsForm(request.POST)
@@ -4408,7 +4413,6 @@ def workout_upload_api(request):
try:
fstr = request.POST['file']
f1 = uuid.uuid4().hex[:10]+'-'+time.strftime("%Y%m%d-%H%M%S")+os.path.splitext(fstr)[1]
print(f1)
f2 = 'media/'+f1
copyfile(fstr,f2)
except KeyError: