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

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