def __call__(self): # TODO: Security check on form view/widget if self.context.ignoreContext: raise NotFound("Cannot get the data file from a widget with no context") if self.context.form is not None: content = aq_inner(self.context.form.getContent()) else: content = aq_inner(self.context.context) field = aq_inner(self.context.field) dm = getMultiAdapter((content, field), IDataManager) file_ = dm.get() if isinstance(file_, basestring) and IASCII.providedBy(field): """Encoded data. """ filename, data = b64decode_file(file_) if INamedImageWidget.providedBy(self.context): file_ = NamedImage(data=data, filename=filename) else: file_ = NamedFile(data=data, filename=filename) if file_ is None: raise NotFound(self, self.filename, self.request) if not self.filename: self.filename = getattr(file_, "filename", None) set_headers(file_, self.request.response, filename=self.filename) return stream_data(file_)
def _make_namedfile(value, field, widget): """Return a NamedImage or NamedFile instance, if it isn't already one - e.g. when it's base64 encoded data. """ if isinstance(value, basestring) and IASCII.providedBy(field): filename, data = b64decode_file(value) if INamedImageWidget.providedBy(widget): value = NamedImage(data=data, filename=filename) else: value = NamedFile(data=data, filename=filename) return value
def __call__(self): # TODO: Security check on form view/widget if self.context.ignoreContext: raise NotFound( "Cannot get the data file from a widget with no context") if self.context.form is not None: content = aq_inner(self.context.form.getContent()) else: content = aq_inner(self.context.context) field = aq_inner(self.context.field) dm = getMultiAdapter(( content, field, ), IDataManager) file_ = dm.get() if isinstance(file_, basestring) and IASCII.providedBy(field): """Encoded data. """ filename, data = b64decode_file(file_) if INamedImageWidget.providedBy(self.context): file_ = NamedImage(data=data, filename=filename) else: file_ = NamedFile(data=data, filename=filename) if file_ is None: raise NotFound(self, self.filename, self.request) if not self.filename: self.filename = getattr(file_, 'filename', None) set_headers(file_, self.request.response, filename=self.filename) return stream_data(file_)