Changeset 6035 for main/waeup.sirp
- Timestamp:
- 10 May 2011, 22:24:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/image/browser/widget.py
r5693 r6035 22 22 """Image file widgets. 23 23 """ 24 from hurry.file import HurryFile24 from waeup.sirp.image import WAeUPImageFile 25 25 from hurry.file.browser.widget import ( 26 26 FileWidgetBase, EncodingFileWidget, DownloadWidget, … … 28 28 from zope.app.form.browser.textwidgets import escape 29 29 from zope.app.form.browser.widget import renderElement 30 from zope.app.form.interfaces import ConversionError 31 30 32 31 33 class EncodingImageFileWidget(EncodingFileWidget): 32 34 """A hurry.file widget that stores images. 35 36 This is an upload widget suitable for edit forms and the like. 33 37 """ 34 38 #: We can set a basename for the image to be rendered. 35 39 #: This will result in <img> links like <img src='.../<basename>.jpg' /> 36 40 image_basename = None 37 41 42 def _toFieldValue(self, (input, file_id)): 43 # we got no file upload input 44 if not input: 45 # if we got a file_id, then retrieve file and return it 46 if file_id: 47 return self._retrieveFile(file_id) 48 # no file upload input nor file id, so return missing value 49 return self.context.missing_value 50 # read in file from input 51 try: 52 seek = input.seek 53 read = input.read 54 except AttributeError, e: 55 raise ConversionError('Form input is not a file object', e) 56 57 seek(0) 58 data = read() 59 60 if data: 61 return WAeUPImageFile(input.filename, data) 62 else: 63 return self.context.missing_value 64 38 65 def __call__(self): 39 66 # The base widget renders the actual image as filename. We … … 52 79 # Append the rendering as delivered from the base widget. 53 80 result += super(EncodingImageFileWidget, self).__call__() 54 #import pdb; pdb.set_trace()55 81 return result 56 82 … … 61 87 return data.encode('base64')[:-1] 62 88 89 def _retrieveFile(self, file_id): 90 data = file_id.decode('base64') 91 filename, filedata = data.split('\n', 1) 92 return WAeUPImageFile(filename, filedata) 93 63 94 class ThumbnailWidget(DownloadWidget): 64 95 """An image file widget that displays the data as thumbnail. 96 97 XXX: give some reason to name this a _thumbnail_ widget. 65 98 """ 66 99 … … 79 112 src=filename, 80 113 contents=None) 81
Note: See TracChangeset for help on using the changeset viewer.