Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-15 08:05:12 +01:00
parent 5b3d7fcf2c
commit 8af7ac8af4
71 changed files with 19992 additions and 19476 deletions

View File

@@ -14,36 +14,39 @@ import uuid
from django.core.exceptions import ValidationError
def format_pace_tick(x,pos=None): # pragma: no cover
minu=int(x/60)
sec=int(x-minu*60.)
sec_str=str(sec).zfill(2)
template='%d:%s'
return template % (minu,sec_str)
def format_time_tick(x,pos=None): # pragma: no cover
hour=int(x/3600)
min=int((x-hour*3600.)/60)
min_str=str(min).zfill(2)
template='%d:%s'
return template % (hour,min_str)
def format_pace_tick(x, pos=None): # pragma: no cover
minu = int(x/60)
sec = int(x-minu*60.)
sec_str = str(sec).zfill(2)
template = '%d:%s'
return template % (minu, sec_str)
def format_pace(x,pos=None): # pragma: no cover
def format_time_tick(x, pos=None): # pragma: no cover
hour = int(x/3600)
min = int((x-hour*3600.)/60)
min_str = str(min).zfill(2)
template = '%d:%s'
return template % (hour, min_str)
def format_pace(x, pos=None): # pragma: no cover
if isinf(x) or isnan(x):
x=0
x = 0
min=int(x/60)
sec=(x-min*60.)
min = int(x/60)
sec = (x-min*60.)
str1 = "{min:0>2}:{sec:0>4.1f}".format(
min = min,
sec = sec
)
min=min,
sec=sec
)
return str1
def format_time(x,pos=None): # pragma: no cover
def format_time(x, pos=None): # pragma: no cover
min = int(x/60.)
sec = int(x-min*60)
@@ -51,44 +54,48 @@ def format_time(x,pos=None): # pragma: no cover
str1 = "{min:0>2}:{sec:0>4.1f}".format(
min=min,
sec=sec,
)
)
return str1
def validate_image_extension(value):
import os
ext = os.path.splitext(value.name)[1].lower()
valid_extension = ['.jpg','.jpeg','.png','.gif']
valid_extension = ['.jpg', '.jpeg', '.png', '.gif']
if not ext in valid_extension: # pragma: no cover
if not ext in valid_extension: # pragma: no cover
raise ValidationError(u'File not supported')
def validate_file_extension(value):
import os
ext = os.path.splitext(value.name)[1]
valid_extensions = ['.tcx','.csv','.TCX','.gpx','.GPX',
'.CSV','.fit','.FIT','.zip','.ZIP',
'.gz','.GZ','.xls',
'.jpg','.jpeg','.tiff','.png','.gif','.bmp']
if not ext in valid_extensions: # pragma: no cover
raise ValidationError(u'File not supported!')
import os
ext = os.path.splitext(value.name)[1]
valid_extensions = ['.tcx', '.csv', '.TCX', '.gpx', '.GPX',
'.CSV', '.fit', '.FIT', '.zip', '.ZIP',
'.gz', '.GZ', '.xls',
'.jpg', '.jpeg', '.tiff', '.png', '.gif', '.bmp']
if not ext in valid_extensions: # pragma: no cover
raise ValidationError(u'File not supported!')
def must_be_csv(value):
import os
ext = os.path.splitext(value.name)[1]
valid_extensions = ['.csv','.CSV']
if not ext in valid_extensions: # pragma: no cover
valid_extensions = ['.csv', '.CSV']
if not ext in valid_extensions: # pragma: no cover
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: # pragma: no cover
valid_extensions = ['.kml', '.KML']
if not ext in valid_extensions: # pragma: no cover
raise ValidationError(u'File not supported!')
def handle_uploaded_image(i): # pragma: no cover
def handle_uploaded_image(i): # pragma: no cover
from io import StringIO, BytesIO
from PIL import Image, ImageOps, ExifTags
import os
@@ -99,18 +106,17 @@ def handle_uploaded_image(i): # pragma: no cover
imagefile = BytesIO(image_str)
image = Image.open(i)
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(image._getexif().items())
if ExifTags.TAGS[orientation] == 'Orientation':
break
exif = dict(image._getexif().items())
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
exif = {'orientation':0}
exif = {'orientation': 0}
if image.mode not in ("L", "RGB"):
image = image.convert("RGB")
@@ -118,35 +124,35 @@ def handle_uploaded_image(i): # pragma: no cover
basewidth = 600
wpercent = (basewidth/float(image.size[0]))
hsize = int((float(image.size[1])*float(wpercent)))
image = image.resize((basewidth,hsize), Image.ANTIALIAS)
image = image.resize((basewidth, hsize), Image.ANTIALIAS)
try:
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
image = image.rotate(180, expand=True)
elif exif[orientation] == 6:
image=image.rotate(270, expand=True)
image = image.rotate(270, expand=True)
elif exif[orientation] == 8:
image=image.rotate(90, expand=True)
image = image.rotate(90, expand=True)
except KeyError:
pass
filename = hashlib.md5(imagefile.getvalue()).hexdigest()+'.jpg'
filename2 = os.path.join('static/plots/',filename)
image.save(filename2,'JPEG')
filename2 = os.path.join('static/plots/', filename)
image.save(filename2, 'JPEG')
return filename,filename2
return filename, filename2
def handle_uploaded_file(f):
fname = f.name
ext = fname.split('.')[-1]
fname = '%s.%s' % (uuid.uuid4(),ext)
fname = '%s.%s' % (uuid.uuid4(), ext)
#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:
with open(fname2, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
return fname,fname2
return fname, fname2