def get_logo(self, disposition='inline', headers=True):
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        customstyles_util = CustomStylesUtility(portal)
        customstyles = customstyles_util.annotations.get(
            'customstyles', OOBTree(DEFAULT_STYLES))

        REQUEST = self.request
        RESPONSE = REQUEST.RESPONSE
        blob = LOGO_KEY in customstyles and customstyles[LOGO_RIGHT_KEY] or None
        if not blob:
            return ''
        length = blob.get_size()
        if headers:
            RESPONSE.setHeader('Last-Modified',
                               rfc1123_date(self.context._p_mtime))
            RESPONSE.setHeader('Content-Type', blob.getContentType())
            RESPONSE.setHeader('Accept-Ranges', 'bytes')

            if handleIfModifiedSince(self.context, REQUEST, RESPONSE):
                return ''
            RESPONSE.setHeader('Content-Length', length)
            filename = blob.getFilename()
            if filename is not None:
                filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
                    unicode(filename, self.context.getCharset()))
                header_value = contentDispositionHeader(
                    disposition=disposition, filename=filename)
                RESPONSE.setHeader("Content-disposition", header_value)

        range = handleRequestRange(self.context, length, REQUEST, RESPONSE)

        return blob.getIterator(**range)
    def get_logo(self, disposition='inline', headers=True):
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        customstyles_util = CustomStylesUtility(portal)
        customstyles = customstyles_util.annotations.get(
            'customstyles', OOBTree(DEFAULT_STYLES))

        REQUEST = self.request
        RESPONSE = REQUEST.RESPONSE
        blob = LOGO_KEY in customstyles and customstyles[LOGO_RIGHT_KEY] or None
        if not blob:
            return ''
        length = blob.get_size()
        if headers:
            RESPONSE.setHeader('Last-Modified',
                               rfc1123_date(self.context._p_mtime))
            RESPONSE.setHeader('Content-Type', blob.getContentType())
            RESPONSE.setHeader('Accept-Ranges', 'bytes')

            if handleIfModifiedSince(self.context, REQUEST, RESPONSE):
                return ''
            RESPONSE.setHeader('Content-Length', length)
            filename = blob.getFilename()
            if filename is not None:
                filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
                    unicode(filename, self.context.getCharset()))
                header_value = contentDispositionHeader(
                    disposition=disposition,
                    filename=filename)
                RESPONSE.setHeader("Content-disposition", header_value)

        range = handleRequestRange(self.context, length, REQUEST, RESPONSE)

        return blob.getIterator(**range)
Beispiel #3
0
    def index_html(self, REQUEST=None, RESPONSE=None, charset='utf-8', disposition='inline'):
        """ make it directly viewable when entering the objects URL """

        if REQUEST is None:
            REQUEST = self.REQUEST

        if RESPONSE is None:
            RESPONSE = REQUEST.RESPONSE

        RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
        RESPONSE.setHeader('Content-Type', self.getContentType())
        RESPONSE.setHeader('Accept-Ranges', 'bytes')

        if handleIfModifiedSince(self, REQUEST, RESPONSE):
            return ''

        length = self.get_size()
        RESPONSE.setHeader('Content-Length', length)

        filename = self.getFilename()
        if filename is not None:
            if not isinstance(filename, unicode):
                filename = unicode(filename, charset)
            filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
                filename)
            header_value = contentDispositionHeader(
                disposition=disposition,
                filename=filename)
            RESPONSE.setHeader("Content-disposition", header_value)

        request_range = handleRequestRange(self, length, REQUEST, RESPONSE)
        return self.getIterator(**request_range)
def index_html(self, instance, REQUEST=None, RESPONSE=None, disposition='inline'):
    """ make it directly viewable when entering the objects URL """
    if REQUEST is None:
        REQUEST = instance.REQUEST
    if RESPONSE is None:
        RESPONSE = REQUEST.RESPONSE
    blob = self.getUnwrapped(instance, raw=True)    # TODO: why 'raw'?
    RESPONSE.setHeader('Last-Modified', rfc1123_date(instance._p_mtime))
    RESPONSE.setHeader('Content-Type', self.getContentType(instance))
    # The only change is to comment out this header:
    #RESPONSE.setHeader('Accept-Ranges', 'bytes')
    if handleIfModifiedSince(instance, REQUEST, RESPONSE):
        return ''
    length = blob.get_size()
    RESPONSE.setHeader('Content-Length', length)
    filename = self.getFilename(instance)
    if filename is not None:
        filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
            unicode(filename, instance.getCharset()))
        header_value = contentDispositionHeader(
            disposition=disposition,
            filename=filename)
        RESPONSE.setHeader("Content-disposition", header_value)
    range = handleRequestRange(instance, length, REQUEST, RESPONSE)
    return blob.getIterator(**range)
def index_html(self,
               instance,
               REQUEST=None,
               RESPONSE=None,
               disposition='inline'):
    """ make it directly viewable when entering the objects URL """
    if REQUEST is None:
        REQUEST = instance.REQUEST
    if RESPONSE is None:
        RESPONSE = REQUEST.RESPONSE
    blob = self.getUnwrapped(instance, raw=True)  # TODO: why 'raw'?
    RESPONSE.setHeader('Last-Modified', rfc1123_date(instance._p_mtime))
    RESPONSE.setHeader('Content-Type', self.getContentType(instance))
    # The only change is to comment out this header:
    #RESPONSE.setHeader('Accept-Ranges', 'bytes')
    if handleIfModifiedSince(instance, REQUEST, RESPONSE):
        return ''
    length = blob.get_size()
    RESPONSE.setHeader('Content-Length', length)
    filename = self.getFilename(instance)
    if filename is not None:
        filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
            unicode(filename, instance.getCharset()))
        header_value = contentDispositionHeader(disposition=disposition,
                                                filename=filename)
        RESPONSE.setHeader("Content-disposition", header_value)
    range = handleRequestRange(instance, length, REQUEST, RESPONSE)
    return blob.getIterator(**range)
Beispiel #6
0
    def index_html(self, instance, REQUEST=None, RESPONSE=None,
                   charset='utf-8', disposition='inline'):
        """Kicks download.
        Writes data including file name and content type to RESPONSE
        """

        if REQUEST is None:
            REQUEST = instance.REQUEST

        if RESPONSE is None:
            RESPONSE = REQUEST.RESPONSE

        RESPONSE.setHeader('Last-Modified', rfc1123_date(instance._p_mtime))
        RESPONSE.setHeader('Content-Type', self.getContentType(instance))
        RESPONSE.setHeader('Accept-Ranges', 'bytes')

        if handleIfModifiedSince(instance, REQUEST, RESPONSE):
            return ''

        length = self.get_size(instance)
        RESPONSE.setHeader('Content-Length', length)

        filename = self.getFilename(instance)
        if filename is not None:
            if isinstance(filename, unicode):
                filename = filename.encode(charset, errors="ignore")

            # Create a user agent specific disposition header
            # IE needs an url quoted filename
            # Other browsers need an unquoted filename
            user_agent = REQUEST.get('HTTP_USER_AGENT', '')
            if 'MSIE' in user_agent:
                header_value = '%s; filename=%s' % (disposition,
                                                    quote(filename))
            else:
                header_value = '%s; filename="%s"' % (disposition, filename)
            RESPONSE.setHeader("Content-disposition", header_value)

        request_range = handleRequestRange(instance, length, REQUEST, RESPONSE)

        # Notify file downloads, but do not notify range requests
        if not ('start' in request_range and request_range['start'] > 0):
            portal_state = getMultiAdapter((instance, instance.REQUEST),
                                           name='plone_portal_state')
            if not portal_state.anonymous():
                registry = getUtility(IRegistry)
                user_ids = registry['ftw.file.filesettings.user_ids']
                if portal_state.member().id \
                        and not portal_state.member().id in user_ids:
                    notify(FileDownloadedEvent(instance, filename))

        return self.get(instance).getIterator(**request_range)
Beispiel #7
0
def index_html(self,
               REQUEST=None,
               RESPONSE=None,
               charset='utf-8',
               disposition='inline'):
    """ make it directly viewable when entering the objects URL """

    if REQUEST is None:
        REQUEST = self.REQUEST

    if RESPONSE is None:
        RESPONSE = REQUEST.RESPONSE

    RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
    RESPONSE.setHeader('Content-Type', self.getContentType())
    RESPONSE.setHeader('Accept-Ranges', 'bytes')

    if handleIfModifiedSince(self, REQUEST, RESPONSE):
        return ''

    length = self.get_size()
    RESPONSE.setHeader('Content-Length', length)

    filename = self.getFilename()
    if filename is not None:
        if REQUEST.HTTP_USER_AGENT.find('MSIE') != -1:
            if isinstance(filename, unicode):
                filename = filename.encode('gb18030')
            else:
                filename = unicode(filename, charset, errors="ignore")
                filename = filename.encode('gb18030')
            header_value = contentDispositionHeader(disposition,
                                                    'gb18030',
                                                    filename=filename)
        else:
            if not isinstance(filename, unicode):
                filename = unicode(filename, charset, errors="ignore")

#            filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
#                filename)
            header_value = contentDispositionHeader(disposition=disposition,
                                                    filename=filename)
        RESPONSE.setHeader("Content-disposition", header_value)

    request_range = handleRequestRange(self, length, REQUEST, RESPONSE)
    return self.getIterator(**request_range)
Beispiel #8
0
    def index_html(self, REQUEST=None, RESPONSE=None, charset='utf-8',
                   disposition='inline'):
        """ make it directly viewable when entering the objects URL """

        if REQUEST is None:
            REQUEST = self.REQUEST

        if RESPONSE is None:
            RESPONSE = REQUEST.RESPONSE

        RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
        RESPONSE.setHeader('Content-Type', self.getContentType())
        RESPONSE.setHeader('Accept-Ranges', 'bytes')

        if handleIfModifiedSince(self, REQUEST, RESPONSE):
            return ''

        length = self.get_size()
        RESPONSE.setHeader('Content-Length', length)

        filename = self.getFilename()
        if filename is not None:
            if not isinstance(filename, six.text_type):
                filename = six.text_type(filename, charset, errors='ignore')
            filename = IUserPreferredFileNameNormalizer(
                REQUEST,
            ).normalize(
                filename,
            )
            header_value = contentDispositionHeader(
                disposition=disposition,
                filename=filename,
            )
            # Add original filename in utf-8, ref to rfc2231
            RESPONSE.setHeader('Content-disposition', header_value)

        request_range = handleRequestRange(self, length, REQUEST, RESPONSE)
        return self.getIterator(**request_range)