Private
Public Access
1
0

better more intuitive course update

This commit is contained in:
Sander Roosendaal
2020-07-11 17:05:21 +02:00
parent 7b552f8da6
commit 6372da689c
10 changed files with 570 additions and 54 deletions

View File

@@ -15,18 +15,18 @@ import uuid
from django.core.exceptions import ValidationError
def format_pace_tick(x,pos=None):
minu=int(x/60)
sec=int(x-minu*60.)
sec_str=str(sec).zfill(2)
template='%d:%s'
return template % (minu,sec_str)
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):
hour=int(x/3600)
min=int((x-hour*3600.)/60)
min_str=str(min).zfill(2)
template='%d:%s'
return template % (hour,min_str)
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):
if isinf(x) or isnan(x):
@@ -56,12 +56,12 @@ def format_time(x,pos=None):
return str1
def validate_image_extension(value):
import os
ext = os.path.splitext(value.name)[1].lower()
valid_extension = ['.jpg','.jpeg','.png','.gif']
import os
ext = os.path.splitext(value.name)[1].lower()
valid_extension = ['.jpg','.jpeg','.png','.gif']
if not ext in valid_extension:
raise ValidationError(u'File not supported')
if not ext in valid_extension:
raise ValidationError(u'File not supported')
def validate_file_extension(value):
import os
@@ -88,53 +88,53 @@ def validate_kml(value):
def handle_uploaded_image(i):
from io import StringIO, BytesIO
from PIL import Image, ImageOps, ExifTags
import os
from django.core.files import File
image_str = b''
for chunk in i.chunks():
image_str += chunk
from io import StringIO, BytesIO
from PIL import Image, ImageOps, ExifTags
import os
from django.core.files import File
image_str = b''
for chunk in i.chunks():
image_str += chunk
imagefile = BytesIO(image_str)
imagefile = BytesIO(image_str)
image = Image.open(i)
image = Image.open(i)
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(image._getexif().items())
exif=dict(image._getexif().items())
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
exif = {'orientation':0}
except (AttributeError, KeyError, IndexError):
# cases: image don't have getexif
exif = {'orientation':0}
if image.mode not in ("L", "RGB"):
image = image.convert("RGB")
if image.mode not in ("L", "RGB"):
image = image.convert("RGB")
basewidth = 600
wpercent = (basewidth/float(image.size[0]))
hsize = int((float(image.size[1])*float(wpercent)))
image = image.resize((basewidth,hsize), Image.ANTIALIAS)
basewidth = 600
wpercent = (basewidth/float(image.size[0]))
hsize = int((float(image.size[1])*float(wpercent)))
image = image.resize((basewidth,hsize), Image.ANTIALIAS)
try:
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
elif exif[orientation] == 6:
image=image.rotate(270, expand=True)
elif exif[orientation] == 8:
image=image.rotate(90, expand=True)
except KeyError:
pass
try:
if exif[orientation] == 3:
mage=image.rotate(180, expand=True)
elif exif[orientation] == 6:
image=image.rotate(270, expand=True)
elif exif[orientation] == 8:
image=image.rotate(90, expand=True)
except KeyError:
pass
filename = hashlib.md5(imagefile.getvalue()).hexdigest()+'.jpg'
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):