Fix: change photo
This commit is contained in:
parent
4aa073beb3
commit
2b967ba34e
@ -43,6 +43,7 @@ Les images sont servies par ScoDoc, via la méthode getphotofile?etudid=xxx
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
@ -51,7 +52,6 @@ import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse
|
|||||||
import traceback
|
import traceback
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
|
|
||||||
from io import StringIO
|
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
@ -238,7 +238,7 @@ def photo_pathname(context, etud, size="orig"):
|
|||||||
def store_photo(context, etud, data, REQUEST=None):
|
def store_photo(context, etud, data, REQUEST=None):
|
||||||
"""Store image for this etud.
|
"""Store image for this etud.
|
||||||
If there is an existing photo, it is erased and replaced.
|
If there is an existing photo, it is erased and replaced.
|
||||||
data is a string with image raw data.
|
data is a bytes string with image raw data.
|
||||||
|
|
||||||
Update database to store filename.
|
Update database to store filename.
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ def save_image(context, etudid, data):
|
|||||||
Save image in JPEG in 2 sizes (original and h90).
|
Save image in JPEG in 2 sizes (original and h90).
|
||||||
Returns filename (relative to PHOTO_DIR), without extension
|
Returns filename (relative to PHOTO_DIR), without extension
|
||||||
"""
|
"""
|
||||||
data_file = StringIO()
|
data_file = io.BytesIO()
|
||||||
data_file.write(data)
|
data_file.write(data)
|
||||||
data_file.seek(0)
|
data_file.seek(0)
|
||||||
img = PILImage.open(data_file)
|
img = PILImage.open(data_file)
|
||||||
|
@ -791,7 +791,7 @@ def formChangePhoto(context, etudid=None, REQUEST=None):
|
|||||||
elif tf[0] == -1:
|
elif tf[0] == -1:
|
||||||
return REQUEST.RESPONSE.redirect(dest_url)
|
return REQUEST.RESPONSE.redirect(dest_url)
|
||||||
else:
|
else:
|
||||||
data = tf[2]["photofile"][0].read()
|
data = tf[2]["photofile"].read()
|
||||||
status, diag = sco_photos.store_photo(context, etud, data, REQUEST=REQUEST)
|
status, diag = sco_photos.store_photo(context, etud, data, REQUEST=REQUEST)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
return REQUEST.RESPONSE.redirect(dest_url)
|
return REQUEST.RESPONSE.redirect(dest_url)
|
||||||
|
Loading…
Reference in New Issue
Block a user