Beispiel #1
0
    def render(self):
        """

        """
        content = self.context.aq_inner

        # Read portlet assignment pointers from the GET query
        name = self.request.form.get("portletName")
        manager = self.request.form.get("portletManager")
        imageId = self.request.form.get("image")
        key = self.request.form.get("portletKey", None)

        if not key:
            # This is probably a bot trying to fetch the image
            # and clearing the query string
            return "Bad query string - no image available"

        portlet = self.getPortletById(content, manager, key, name)
        if not portlet:
            raise InternalError("Portlet not found: %s %s" % (key, name))

        image = getattr(portlet, imageId, None)
        if not image:
            # Ohops?
            raise InternalError("Image was empty: %s" % imageId)

        # Set content type and length headers
        set_headers(image, self.request.response)

        # Push data to the downstream clients
        return stream_data(image)
    def monkeypatch_plone_formwidget_namedfile_widget_download__call__(self):
        """ Patches to plone.formwidget.namedfile.widget.Download.__call__
        """
        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 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)
        if IBlobby.providedBy(file):
            zodb_blob = file_._blob
        else:
            zodb_blob = file_
        if set_xsendfile_header(self.request, self.request.response, zodb_blob):
            return 'collective.xsendfile - proxy missing?'
        else:
            return stream_data(file_)
Beispiel #3
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_)
Beispiel #4
0
    def __call__(self):
        version_id = self.request.get('version_id', None)
        if not version_id:
            raise ValueError(u'Missing parameter on the request: version_id')

        field_id = self.request.get('field_id', IPrimaryFieldInfo(self.context).fieldname)
        filename = self.request.get('filename')
        do_not_stream = self.request.get('do_not_stream')

        repository = getToolByName(self.context, 'portal_repository')
        old_obj = repository.retrieve(self.context, version_id).object

        # Will only work if the file is stored as an attribute with the same
        # name of the field.
        file_ = getattr(old_obj, field_id, None)

        if file_ is None:
            raise NotFound(self, filename, self.request)

        set_headers(file_, self.request.response, filename=filename)

        if do_not_stream:
            return file_.data

        return stream_data(file_)
Beispiel #5
0
    def __call__(self):
        file = self._getFile()

        if not self.filename:
            self.filename = getattr(file, 'filename', self.fieldname)
        set_headers(file, self.request.response, filename=self.filename)
        return stream_data(file)
    def __call__(self):
        context = self.context
        annotations = IAnnotations(context)
        status = annotations.get(STATUS_STORAGE_KEY, None)
        named_file = annotations.get(DATA_STORAGE_KEY, None)
        if status == TASK_SUCCEEDED:
            set_headers(named_file,
                        self.request.response,
                        filename=named_file.filename)
            return stream_data(named_file)

        if status == TASK_IN_PROGRESS:
            IStatusMessage(self.request).add(
                _(u"Document generation in progress, please retry later..."),
                type='warning')
        elif status == TASK_FAILED:
            IStatusMessage(self.request).add(_(
                u"Document generation failed, please retry document generation or contact your administrator..."
            ),
                                             type='error')
        elif not status or not named_file:
            IStatusMessage(self.request).add(_(u"No document generated here"),
                                             type='error')

        self.request.response.redirect(self.context.absolute_url() + '/view')
    def monkeypatch_plone_formwidget_namedfile_widget_download__call__(self):
        """ Patches to plone.formwidget.namedfile.widget.Download.__call__
        """
        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 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)
        if IBlobby.providedBy(file):
            zodb_blob = file_._blob
        else:
            zodb_blob = file_
        if set_xsendfile_header(self.request, self.request.response,
                                zodb_blob):
            return 'collective.xsendfile - proxy missing?'
        else:
            return stream_data(file_)
Beispiel #8
0
def stream_avatar_data(profile, size, request):
    """Generate avatar at the specified size and stream it

    This is a utility method used by the browser views below.
    """
    imaging = plone_api.content.get_view(
        request=request,
        context=profile,
        name='images')

    if size not in AVATAR_SIZES:
        return None

    width = height = AVATAR_SIZES.get(size)

    try:
        scale = imaging.scale(
            fieldname='portrait',
            width=width,
            height=height,
            direction='down',
        )
    except TypeError:
        # No image found
        return None

    if scale is not None:
        response = request.response
        data = scale.data
        from plone.namedfile.utils import set_headers, stream_data
        set_headers(data, response)
        return stream_data(data)
    else:
        return None
Beispiel #9
0
 def HEAD(self, REQUEST, RESPONSE=None):
     """ Obtain metainformation about the image implied by the request
         without transfer of the image itself
     """
     self.validate_access()
     set_headers(self.data, REQUEST.response)
     return ''
Beispiel #10
0
    def downloadField(self, fieldName):
        file = getattr(self.context, fieldName, None)
        if file is None:
            raise NotFound(self.context, fieldName, self.request)

        set_headers(file, self.request.response, filename=file.filename)
        return stream_data(file)
Beispiel #11
0
    def render(self):
        """

        """
        content = self.context.aq_inner

        # Read portlet assignment pointers from the GET query
        name = self.request.form.get("portletName")
        manager = self.request.form.get("portletManager")
        imageId = self.request.form.get("image")
        key = self.request.form.get("portletKey", None)

        if not key:
            # This is probably a bot trying to fetch the image
            # and clearing the query string
            return "Bad query string - no image available"

        portlet = self.getPortletById(content, manager, key, name)
        if not portlet:
            raise InternalError("Portlet not found: %s %s" % (key, name))

        image = getattr(portlet, imageId, None)
        if not image:
            # Ohops?
            raise InternalError("Image was empty: %s" % imageId)

        # Set content type and length headers
        set_headers(image, self.request.response)

        # Push data to the downstream clients
        return stream_data(image)
Beispiel #12
0
 def HEAD(self, REQUEST, RESPONSE=None):
     """ Obtain metainformation about the image implied by the request
         without transfer of the image itself
     """
     self.validate_access()
     set_headers(self.data, REQUEST.response)
     return ''
Beispiel #13
0
    def __call__(self):
        version_id = self.request.get('version_id', None)
        if not version_id:
            raise ValueError(u'Missing parameter on the request: version_id')

        field_id = self.request.get('field_id',
                                    IPrimaryFieldInfo(self.context).fieldname)
        filename = self.request.get('filename')
        do_not_stream = self.request.get('do_not_stream')

        repository = getToolByName(self.context, 'portal_repository')
        old_obj = repository.retrieve(self.context, version_id).object

        # Will only work if the file is stored as an attribute with the same
        # name of the field.
        file_ = getattr(old_obj, field_id, None)

        if file_ is None:
            raise NotFound(self, filename, self.request)

        set_headers(file_, self.request.response, filename=filename)

        if do_not_stream:
            return file_.data

        return stream_data(file_)
    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 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_)
Beispiel #15
0
 def index_html(self):
     """ download the image """
     # validate access
     fieldname = getattr(self.data, 'fieldname', getattr(self, 'fieldname', None))
     guarded_getattr(self.context, fieldname)
     set_headers(self.data, self.request.response)
     return stream_data(self.data)
Beispiel #16
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()
        file_ = _make_namedfile(file_, field, self.context)

        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_)
Beispiel #17
0
    def __call__(self):
        file_ = self.context.agreement

        if not file_:
            raise NotFound(self, 'smlouva.pdf', self.request)

        set_headers(file_, self.request.response, filename="smlouva.pdf")
        return stream_data(file_)
Beispiel #18
0
    def __call__(self):
        file_ = self.context.agreement

        if not file_:
            raise NotFound(self, 'smlouva.pdf', self.request)

        set_headers(file_, self.request.response, filename="smlouva.pdf")
        return stream_data(file_)
Beispiel #19
0
 def render(self):
     file_etiquetas = NamedFile(open(
         '/tmp/%s.pdf' % self.request.SESSION.id, 'r'),
                                filename=u'etiquetas.pdf')
     cd = 'inline; filename="etiquetas.pdf"'
     self.request.response.setHeader('Content-Disposition', cd)
     set_headers(file_etiquetas, self.request.response)
     return stream_data(file_etiquetas)
Beispiel #20
0
    def __call__(self):
        file_ = self.context.voucher

        if not file_:
            raise NotFound(self, 'ohlasovaci-listek.pdf', self.request)

        set_headers(file_, self.request.response, filename="ohlasovaci-listek.pdf")
        return stream_data(file_)
Beispiel #21
0
def patched_index_html(self):
    """ download the image """
    self.validate_access()
    if getattr(self, 'google_url', None) is not None:  #patched line
        response = self.request.response  #patched line
        response.redirect(getattr(self, 'google_url'),
                          lock=True)  #patched line
        return ''  #patched line
    set_headers(self.data, self.request.response)
    return stream_data(self.data)
Beispiel #22
0
 def render(self):
     session = Session()
     anexo = session.query(db.Anexo).get(self.request.id)
     p = anexo.protocolo
     path_anexo = os.path.join(PATH_ANEXOS, ScopeID(), str(p.ano), str(p.id), str(anexo.id))
     file_anexo = NamedFile(open(path_anexo, 'r'), filename=anexo.arquivo)
     cd = 'inline; filename="%s"' % anexo.arquivo.encode('utf-8')
     self.request.response.setHeader('Content-Disposition', cd)
     set_headers(file_anexo, self.request.response)
     return stream_data(file_anexo)
Beispiel #23
0
 def render(self):
     session = Session()
     anexo = session.query(db.Anexo).get(self.request.id)
     p = anexo.protocolo
     path_anexo = os.path.join(PATH_ANEXOS, ScopeID(), str(p.ano), str(p.id), str(anexo.id))
     file_anexo = NamedFile(open(path_anexo, "r"), filename=anexo.arquivo)
     cd = 'inline; filename="%s"' % anexo.arquivo.encode("utf-8")
     self.request.response.setHeader("Content-Disposition", cd)
     set_headers(file_anexo, self.request.response)
     return stream_data(file_anexo)
Beispiel #24
0
    def __call__(self):
        """Render the file to the browser."""
        files = self.context.data.get('files', ())

        try:
            file_ = files[int(self.index)]
        except KeyError:
            raise NotFound(self, self.index, self.request)
        set_headers(file_, self.request.response, filename=file_.filename)
        return stream_data(file_)
    def __call__(self):
        """Render the file to the browser."""
        files = self.context.data.get('files', ())

        try:
            file_ = files[int(self.index)]
        except KeyError:
            raise NotFound(self, self.index, self.request)
        set_headers(file_, self.request.response,
                    filename=file_.filename)
        return stream_data(file_)
Beispiel #26
0
    def __call__(self):
        if not self.context.has_sip_package():
            msg = _('msg_no_sip_package_generated',
                    default=u'No SIP Package generated for this disposition.')
            api.portal.show_message(msg, request=self.request, type='error')
            return self.request.RESPONSE.redirect(self.context.absolute_url())

        sip_package = self.context.get_sip_package()
        filename = self.context.get_sip_filename()
        set_headers(sip_package, self.request.response, filename)
        return stream_data(sip_package)
 def _getFile(self):
     if not self.fieldname:
         raise NotFound(self, '', self.request)
     else:
         data = self.context.data[self.fieldname]
         if data:
             filename = self.filename and self.filename or 'Download'
             set_headers(data, self.request.response, filename)
         else:
             raise NotFound(self, None, self.request)
     return data
 def _getFile(self):
     if not self.fieldname:
         raise NotFound(self, '', self.request)
     else:
         data = self.context.data[self.fieldname]
         if data:
             filename = self.filename and self.filename or 'Download'
             set_headers(data, self.request.response, filename)
         else:
             raise NotFound(self, None, self.request)
     return data
    def render(self, version_id, field_id, filename):
        repository = getToolByName(self.context, 'portal_repository')
        old_obj = repository.retrieve(self.context, version_id).object
        file_ = getattr(old_obj, field_id)

        if file_ is None:
            raise NotFound(self, filename, self.request)
        
        set_headers(file_, self.request.response, filename=filename)

        return stream_data(file_)
 def __call__(self):
     if self.tileId:
         tile_data = self.get_tile_data()
         if tile_data:
             field = tile_data.get(self.fieldName)
             if field:
                 set_headers(field,
                             self.request.response,
                             filename=field.filename)
             else:
                 raise NotFound(self.context, self.tileId, self.request)
             return stream_data(field)
Beispiel #31
0
def patched_HEAD(self, REQUEST, RESPONSE=None):
    """ Obtain metainformation about the image implied by the request
    without transfer of the image itself
    """
    self.validate_access()
    if getattr(self, 'google_url', None) is not None:  #patched line
        response = self.request.response  #patched line
        response.redirect(getattr(self, 'google_url'),
                          lock=True)  #patched line
        return ''  #patched line

    set_headers(self.data, REQUEST.response)
    return ''
    def __call__(self):
        version_id = self.request.version_id
        field_id = self.request.field_id
        filename = self.request.filename
        repository = getToolByName(self.context, 'portal_repository')
        old_obj = repository.retrieve(self.context, version_id).object
        file_ = getattr(old_obj, field_id)

        if file_ is None:
            raise NotFound(self, filename, self.request)

        set_headers(file_, self.request.response, filename=filename)

        return stream_data(file_)
    def __call__(self):
        version_id = self.request.version_id
        field_id = self.request.field_id
        filename = self.request.filename
        repository = getToolByName(self.context, "portal_repository")
        old_obj = repository.retrieve(self.context, version_id).object
        file_ = getattr(old_obj, field_id)

        if file_ is None:
            raise NotFound(self, filename, self.request)

        set_headers(file_, self.request.response, filename=filename)

        return stream_data(file_)
Beispiel #34
0
    def __call__(self):
        pm = api.portal.get_tool(name='portal_membership')
        portrait = pm.getPersonalPortrait(self.username)

        if isinstance(portrait, Image):
            # Return the user's portrait cache at will
            self.request.response.addHeader('Content-Type', portrait.content_type)
            self.request.response.addHeader('X-Theme-Disabled', '1')
            set_headers(portrait, self.request.response, filename=self.username)
            return stream_data(portrait)
        else:
            # Return default image, no caching
            self.request.response.addHeader('Content-Type', portrait.getContentType())
            self.request.response.addHeader('Cache-Control', 'must-revalidate, max-age=0, no-cache, no-store')
            return portrait._readFile(portrait)
Beispiel #35
0
    def __call__(self):
        pm = getToolByName(self, 'portal_membership')
        portrait = pm.getPersonalPortrait(self.username)

        if isinstance(portrait, Image):
            # Return the user's portrait cache at will
            self.request.response.addHeader('Content-Type', portrait.content_type)
            self.request.response.addHeader('X-Theme-Disabled', '1')
            set_headers(portrait, self.request.response, filename=self.username)
            return stream_data(portrait)
        else:
            # Return default image, no caching
            self.request.response.addHeader('Content-Type', portrait.getContentType())
            self.request.response.addHeader('Cache-Control', 'must-revalidate, max-age=0, no-cache, no-store')
            return portrait._readFile(portrait)
Beispiel #36
0
    def downloadField(self, fieldName):
        file = getattr(self.context, fieldName, None)
        if file is None:
            raise NotFound(self.context, fieldName, self.request)

        if getattr(file, 'filename', False):
            fileName = file.filename
        else:
            fileName = ''.join([
                self.context.id, '-', fieldName,
                mimetypes.guess_extension(file.contentType) or '.dat',
            ])

        set_headers(file, self.request.response, filename=fileName if self.forceDownload else None)
        return stream_data(file)
    def traverse(self, name, ignore):
        annotations = dict(self.context.__annotations__)
        image = annotations['pdfpeek']['image_thumbnails'][name]

        # Try determine blob name and default to "context_id_download."
        # This is only visible if the user tried to save the file to local
        # computer.
        filename = getattr(image, 'filename', name)

        # Sets Content-Type and Content-Length
        set_headers(image, self.request.response)

        # Set Content-Disposition
        self.request.response.setHeader(
            'Content-Disposition', 'inline; filename={0}'.format(filename))
        return stream_data(image)
    def __call__(self):
        uids, pathes = self.request.get('uids', ''), self.request.get('pathes', '')
        if pathes and len(pathes) != 2 or uids and len(uids) != 2:
            raise ValueError("You have to compare two documents")

        if uids:
            file1, file2 = [api.content.get(UID=uids[0]),
                            api.content.get(UID=uids[1])],
        elif pathes:
            file1, file2 = [api.content.get(path=pathes[0]),
                            api.content.get(path=pathes[1])],

        filev1, filev2 = sorted([file1, file2], key=lambda x: x.modified())
        named_file_diff = get_files_comparison(filev2.file, filev1.file)
        set_headers(named_file_diff,
                    self.request.response, filename=named_file_diff.filename)
        return stream_data(named_file_diff)
    def __call__(self):
        version_id = self.request.version_id
        field_id = self.request.field_id
        filename = self.request.filename
        repository = getToolByName(self.context, 'portal_repository')
        old_obj = repository.retrieve(self.context, version_id).object

        # Will only work if the file is stored as an attribute with the same
        # name of the field.
        file_ = getattr(old_obj, field_id, None)

        if file_ is None:
            raise NotFound(self, filename, self.request)

        set_headers(file_, self.request.response, filename=filename)

        return stream_data(file_)
    def __call__(self):
        version_id = self.request.version_id
        field_id = self.request.field_id
        filename = self.request.filename
        repository = getToolByName(self.context, 'portal_repository')
        old_obj = repository.retrieve(self.context, version_id).object

        # Will only work if the file is stored as an attribute with the same
        # name of the field.
        file_ = getattr(old_obj, field_id, None)

        if file_ is None:
            raise NotFound(self, filename, self.request)

        set_headers(file_, self.request.response, filename=filename)

        return stream_data(file_)
Beispiel #41
0
    def __call__(self):

        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_list = dm.get()
        try:
            file_ = file_list[self.file_index]
        except (IndexError, TypeError):
            raise NotFound(self, self.file_index, self.request)

        filename = getattr(file_, 'filename', '')

        set_headers(file_, self.request.response, filename=filename)

        if 'OriginalFiles' in self.context.id:
            #  Original Files only visible by validated users...
            #  Add permissions to "download file"
            if api.user.is_anonymous():
                # is anon
                raise Unauthorized('You have no permissions to download this file.')
            else:
                # Is a validated user...
                username = api.user.get_current().getProperty('id')
                # get username

                roles = api.user.get_roles(username=username, obj=self.context)
                # And check roles
                if 'Reader' or 'Manager' in roles:
                    return stream_data(file_)
                else:
                    raise Unauthorized("You have no permissions to download this file")
        else:
            return stream_data(file_)
    def __call__(self):
        context = self.context
        annotations = IAnnotations(context)
        status = annotations.get(STATUS_STORAGE_KEY, None)
        named_file = annotations.get(DATA_STORAGE_KEY, None)
        if status == TASK_SUCCEEDED or not named_file:
            set_headers(named_file,
                        self.request.response, filename=named_file.filename)
            return stream_data(named_file)

        if status == TASK_IN_PROGRESS:
            IStatusMessage(self.request).add(_(u"Document generation in progress, please retry later..."),
                                             type='warning')
        elif status == TASK_FAILED:
            IStatusMessage(self.request).add(_(u"Document generation failed, please retry document generation or contact your administrator..."),
                                             type='error')
        elif not status:
            IStatusMessage(self.request).add(_(u"No document generated here"),
                                             type='error')

        self.request.response.redirect(self.context.absolute_url()+'/view')
    def plone_namedfile_scaling_ImageScale_index_html(self):
        """ download the image """
        self.validate_access()
        set_headers(self.data, self.request.response)
        if IBlobby.providedBy(self.data):
            zodb_blob = self.data._blob
        else:
            zodb_blob = self.data

        try:
            # The very first time a scale is requested, it is created, so a
            # blob will not exist. So do not serve it with xsendfile until the
            # transaction is commited.
            zodb_blob.committed()
        except BlobError:
            return stream_data(self.data)

        if set_xsendfile_header(self.request, self.request.response, zodb_blob):
            return 'collective.xsendfile - proxy missing?'
        else:
            return stream_data(self.data)
Beispiel #44
0
def stream_avatar_data(profile, size, request):
    """Generate avatar at the specified size and stream it

    This is a utility method used by the browser views below.
    """
    response = request.response

    if not profile:
        return default_avatar(response)
    imaging = plone_api.content.get_view(
        request=request,
        context=profile,
        name='images')

    if size not in AVATAR_SIZES:
        return default_avatar(response)

    width = height = AVATAR_SIZES.get(size)

    try:
        scale = imaging.scale(
            fieldname='portrait',
            width=width,
            height=height,
            direction='down',
        )
    except TypeError:
        # No image found
        return default_avatar(response)

    if scale is not None:
        data = scale.data
        mtime = rfc1123_date(profile._p_mtime)
        response.setHeader('Last-Modified', mtime)
        from plone.namedfile.utils import set_headers, stream_data
        set_headers(data, response)
        return stream_data(data)
    else:
        return default_avatar(response)
    def plone_namedfile_scaling_ImageScale_index_html(self):
        """ download the image """
        self.validate_access()
        set_headers(self.data, self.request.response)
        if IBlobby.providedBy(self.data):
            zodb_blob = self.data._blob
        else:
            zodb_blob = self.data

        try:
            # The very first time a scale is requested, it is created, so a
            # blob will not exist. So do not serve it with xsendfile until the
            # transaction is commited.
            zodb_blob.committed()
        except BlobError:
            return stream_data(self.data)

        if set_xsendfile_header(self.request, self.request.response,
                                zodb_blob):
            return 'collective.xsendfile - proxy missing?'
        else:
            return stream_data(self.data)
    def __call__(self):

        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_list = dm.get()
        try:
            file_ = file_list[self.file_index]
        except (IndexError, TypeError):
            raise NotFound(self, self.file_index, self.request)

        filename = getattr(file_, 'filename', '')

        set_headers(file_, self.request.response, filename=filename)
        return stream_data(file_)
    def __call__(self):
        """Stream BLOB of context ``file`` field to the browser.

        @param file: Blob object
        """
        blob = self.context.datei
        if blob is None:
            raise NotFound('No file present')
        # Try determine blob name and default to "context_id_download."
        # This is only visible if the user tried to save the file to local
        # computer.
        filename = getattr(blob, 'filename', self.context.id + '_download')

        # Sets Content-Type and Content-Length
        set_headers(blob, self.request.response)

        # Set Content-Disposition
        self.request.response.setHeader(
            'Content-Disposition',
            'inline; filename={0}'.format(filename)
        )
        return stream_data(blob)
Beispiel #48
0
    def __call__(self):
        uids, pathes = self.request.get('uids',
                                        ''), self.request.get('pathes', '')
        if pathes and len(pathes) != 2 or uids and len(uids) != 2:
            raise ValueError("You have to compare two documents")

        if uids:
            file1, file2 = [
                api.content.get(UID=uids[0]),
                api.content.get(UID=uids[1])
            ],
        elif pathes:
            file1, file2 = [
                api.content.get(path=pathes[0]),
                api.content.get(path=pathes[1])
            ],

        filev1, filev2 = sorted([file1, file2], key=lambda x: x.modified())
        named_file_diff = get_files_comparison(filev2.file, filev1.file)
        set_headers(named_file_diff,
                    self.request.response,
                    filename=named_file_diff.filename)
        return stream_data(named_file_diff)
Beispiel #49
0
    def __call__(self):

        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 = queryMultiAdapter((content, field,), IDataManager)
        file_list = dm.query()
        if file_list == NO_VALUE:
            return None
        file_ = None
        if not isinstance(file_list, list):
            file_list = [file_list]
        for curr_file in file_list:
            if curr_file.filename == self.filename:
                file_ = curr_file
        filename = getattr(file_, 'filename', '')
        if not file_:
            return None
        set_headers(file_, self.request.response, filename=filename)
        return stream_data(file_)
Beispiel #50
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_)
Beispiel #51
0
 def stream_file(self):
     item = self.target_item
     is_file = getattr(item, 'attachment', None)
     if is_file:
         file_obj = item.attachment
         filename = item.attachment.filename
         set_headers(file_obj, self.request.response, filename)
         return stream_data(file_obj)
     else:
         info = IPrimaryFieldInfo(item, None)
         if info is None:
             file_obj = item.image
             filename = (item.image.filename).decode('utf-8')
             set_headers(file_obj, self.request.response, filename)
             return stream_data(file_obj)
         field_name = info.fieldname
         file = info.value
         item_filename = getattr(file, 'filename', field_name)
         try:
             str(item_filename)
         except UnicodeEncodeError:
             item_filename = (item_filename).encode('utf-8')
         set_headers(file, self.request.response, item_filename)
         return stream_data(file)
Beispiel #52
0
 def set_headers(self, file):
     set_headers(file, self.request.response)
Beispiel #53
0
 def index_html(self):
     """ download the image """
     # validate access
     set_headers(self.data, self.request.response)
     return stream_data(self.data)
Beispiel #54
0
 def set_headers(self, file):
     if not self.filename:
         self.filename = getattr(file, 'filename', self.fieldname)
     set_headers(file, self.request.response, filename=self.filename)
Beispiel #55
0
 def render(self):
     file_etiquetas = NamedFile(open("/tmp/%s.pdf" % self.request.SESSION.id, "r"), filename=u"etiquetas.pdf")
     cd = 'inline; filename="etiquetas.pdf"'
     self.request.response.setHeader("Content-Disposition", cd)
     set_headers(file_etiquetas, self.request.response)
     return stream_data(file_etiquetas)
 def index_html(self):
     """ download the image """
     # validate access
     set_headers(self.data, self.request.response)
     return stream_data(self.data)
 def browserDefault(self, request):
     """Set the headers of the response to allow serving the image.
     """
     set_headers(self.context, request.response, filename=None)
     return (stream_data(self.context), ())
 def __call__(self):
     file = getFileOrgans(self)
     if not self.filename:
         self.filename = getattr(file, 'filename', self.fieldname)
     set_headers(file, self.request.response, filename=self.filename)
     return stream_data(file)
Beispiel #59
0
 def browserDefault(self, request):
     """Set the headers of the response to allow serving the image.
     """
     set_headers(self.context, request.response, filename=None)
     return (stream_data(self.context), ())
 def __call__(self):
     file = getFileOrgans(self)
     set_headers(file, self.request.response)
     return stream_data(file)