Esempio n. 1
0
    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_)
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
    def toWidgetValue(self, value):

        if not isinstance(value, basestring):
            return None

        filename, data = b64decode_file(value)

        if INamedImageWidget.providedBy(self.widget):
            value = NamedImage(data=data, filename=filename)
        else:
            value = NamedFile(data=data, filename=filename)
        return value
Esempio n. 5
0
    def toWidgetValue(self, value):

        if not isinstance(value, basestring):
            return None

        filename, data = b64decode_file(value)

        if INamedImageWidget.providedBy(self.widget):
            value = NamedImage(data=data, filename=filename)
        else:
            value = NamedFile(data=data, filename=filename)
        return value
    def toWidgetValue(self, value):

        if not isinstance(value, (six.text_type, six.binary_type)):
            return None

        filename, data = b64decode_file(value)

        if INamedImageWidget.providedBy(self.widget):
            value = NamedImage(data=data, filename=filename)
        else:
            value = NamedFile(data=data, filename=filename)
        return value
Esempio n. 7
0
    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_)