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

View File

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

View File

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

View File

@@ -4391,15 +4391,20 @@ def workout_toggle_ranking(request,id=0):
@csrf_exempt @csrf_exempt
def workout_upload_api(request): def workout_upload_api(request):
if request.method != 'POST': 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 # 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 # check credentials here
secret = request.POST['secret'] secret = request.POST['secret']
if secret != 'potjandorie': if secret != settings.UPLOAD_SERVICE_SECRET:
raise PermissionDenied("Invalid credentials") message = {'status':'false','message':'invalid credentials'}
return JSONResponse(status=403,data=message)
form = DocumentsForm(request.POST) form = DocumentsForm(request.POST)
optionsform = TeamUploadOptionsForm(request.POST) optionsform = TeamUploadOptionsForm(request.POST)
@@ -4408,7 +4413,6 @@ def workout_upload_api(request):
try: try:
fstr = request.POST['file'] fstr = request.POST['file']
f1 = uuid.uuid4().hex[:10]+'-'+time.strftime("%Y%m%d-%H%M%S")+os.path.splitext(fstr)[1] f1 = uuid.uuid4().hex[:10]+'-'+time.strftime("%Y%m%d-%H%M%S")+os.path.splitext(fstr)[1]
print(f1)
f2 = 'media/'+f1 f2 = 'media/'+f1
copyfile(fstr,f2) copyfile(fstr,f2)
except KeyError: except KeyError:

View File

@@ -247,6 +247,10 @@ LOGOUT_REDIRECT_URL = '/'
# Update Cache with task progress password # Update Cache with task progress password
PROGRESS_CACHE_SECRET = CFG['progress_cache_secret'] PROGRESS_CACHE_SECRET = CFG['progress_cache_secret']
try:
UPLOAD_SERVICE_SECRET = CFG['upload_service_secret']
except KeyError:
UPLOAD_SERVICE_SECRET = "FoYezZWLSyfAVimumpHEeYsJjsNCerxV"
# Concept 2 # Concept 2
C2_CLIENT_ID = CFG['c2_client_id'] C2_CLIENT_ID = CFG['c2_client_id']