forms: show uploaded images as thumbnails in form and validation pages (#8675)
This commit is contained in:
parent
7088b86772
commit
39a88562d9
|
@ -9,7 +9,7 @@ X-Python-Version: 2.7
|
||||||
|
|
||||||
Package: wcs
|
Package: wcs
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${python:Depends}, python-quixote, python-scgi, graphviz, python-feedparser
|
Depends: ${python:Depends}, python-quixote, python-scgi, graphviz, python-feedparser, python-imaging
|
||||||
Recommends: python-dns, python-m2crypto, python-xlwt, python-qrcode, libjs-leaflet
|
Recommends: python-dns, python-m2crypto, python-xlwt, python-qrcode, libjs-leaflet
|
||||||
Suggests: libapache2-mod-scgi | libapache-mod-scgi, python-libxml2, python-lasso, python-psycopg2
|
Suggests: libapache2-mod-scgi | libapache-mod-scgi, python-libxml2, python-lasso, python-psycopg2
|
||||||
Description: web application to design and set up online forms
|
Description: web application to design and set up online forms
|
||||||
|
|
|
@ -20,6 +20,11 @@ from StringIO import StringIO
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
except ImportError:
|
||||||
|
Image = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import qrcode
|
import qrcode
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -908,7 +913,15 @@ class FormPage(Directory):
|
||||||
if tempfile['charset']:
|
if tempfile['charset']:
|
||||||
response.set_charset(tempfile['charset'])
|
response.set_charset(tempfile['charset'])
|
||||||
|
|
||||||
return get_session().get_tempfile_content(t).get_file_pointer().read()
|
file_pointer = get_session().get_tempfile_content(t).get_file_pointer()
|
||||||
|
if Image is not None and get_request().form.get('thumbnail') == '1':
|
||||||
|
image = Image.open(file_pointer)
|
||||||
|
image.thumbnail((500, 300))
|
||||||
|
image_thumb_fp = StringIO()
|
||||||
|
image.save(image_thumb_fp, "PNG")
|
||||||
|
return image_thumb_fp.getvalue()
|
||||||
|
else:
|
||||||
|
return file_pointer.read()
|
||||||
|
|
||||||
def validating(self, data):
|
def validating(self, data):
|
||||||
self.html_top(self.formdef.name)
|
self.html_top(self.formdef.name)
|
||||||
|
|
|
@ -599,9 +599,8 @@ class FileWithPreviewWidget(CompositeWidget):
|
||||||
elif temp:
|
elif temp:
|
||||||
filetype = mimetypes.guess_type(temp.get('orig_filename', ''))
|
filetype = mimetypes.guess_type(temp.get('orig_filename', ''))
|
||||||
if filetype and filetype[0] and filetype[0].startswith('image'):
|
if filetype and filetype[0] and filetype[0].startswith('image'):
|
||||||
r += htmltext('<img alt="%s" src="tempfile?t=%s" />' % \
|
r += htmltext('<img alt="" src="tempfile?t=%s&thumbnail=1" />' % \
|
||||||
(temp.get('orig_filename', ''),
|
self.get('token'))
|
||||||
self.get('token')))
|
|
||||||
|
|
||||||
r += htmltext('</div>')
|
r += htmltext('</div>')
|
||||||
return r.getvalue()
|
return r.getvalue()
|
||||||
|
|
Loading…
Reference in New Issue