Example #1
0
    def getIcon(self, relative_to_portal=0):
        """Calculate the icon using the mime type of the file
        """
        field = self.getField('file')
        if not field or not self.get_size():
            # field is empty
            return BaseContent.getIcon(self, relative_to_portal)

        contenttype       = field.getContentType(self)
        contenttype_major = contenttype and contenttype.split('/')[0] or ''

        mtr   = getToolByName(self, 'mimetypes_registry', None)
        utool = getToolByName( self, 'portal_url' )

        if ICONMAP.has_key(contenttype):
            icon = quote(ICONMAP[contenttype])
        elif ICONMAP.has_key(contenttype_major):
            icon = quote(ICONMAP[contenttype_major])
        else:
            mimetypeitem = None
            try:
                mimetypeitem = mtr.lookup(contenttype)
            except MimeTypeException, msg:
                LOG.error('MimeTypeException for %s. Error is: %s' % (self.absolute_url(), str(msg)))
            if not mimetypeitem:
                return BaseContent.getIcon(self, relative_to_portal)
            icon = mimetypeitem[0].icon_path
Example #2
0
    def getIcon(self, relative_to_portal=0):
        """Calculate the icon using the mime type of the file
        """
        field = self.getFileContent()

        contenttype = self.Format()
        contenttype_major = contenttype and contenttype.split('/')[0] or ''

        if not field or not self.get_size():
            # field is empty
            return super(ReflectoFile, self).getIcon(relative_to_portal)

        mtr = getToolByName(self, 'mimetypes_registry', None)

        if ICONMAP.has_key(contenttype):
            icon = quote(ICONMAP[contenttype])
        elif ICONMAP.has_key(contenttype_major):
            icon = quote(ICONMAP[contenttype_major])
        else:
            mimetypeitem = None
            try:
                mimetypeitem = mtr.lookup(contenttype)
            except MimeTypeException, msg:
                LOG.error('MimeTypeException for %s. Error is: %s' %
                          (self.absolute_url(), str(msg)))
            if not mimetypeitem:
                return super(ReflectoFile, self).getIcon(relative_to_portal)
            icon = mimetypeitem[0].icon_path
Example #3
0
def quick_preview(item, value):
    portal_url = getToolByName(getSite(), 'portal_url')
    url_method = lambda: '#'
    #item = hasattr(item, 'aq_explicit') and item.aq_explicit or item
    if hasattr(item, 'getURL'):
        url_method = item.getURL
    elif hasattr(item, 'absolute_url'):
        url_method = item.absolute_url

    # Bug in Products.ATContenttypes
    # https://github.com/plone/Products.ATContentTypes/pull/4
    icon = item.getIcon
    if icon in ICONMAP.values():
        icon = icon.replace('gif', 'png')

    img = u'<img src="%s/%s"/>' % (portal_url(), item.getIcon)
    if not isinstance(value, unicode):
        value = value.decode('utf8')
    value = cgi.escape(value, quote=True)

    link = u'<a class="quick_preview" href="%s/quick_preview">%s%s</a>' % (
        url_method(), img, value)
    wrapper = u'<span class="linkWrapper">%s</span>' % link
    return wrapper
Example #4
0
def quick_preview(item, value):
    portal_url = getToolByName(getSite(), 'portal_url')
    url_method = lambda: '#'
    #item = hasattr(item, 'aq_explicit') and item.aq_explicit or item
    if hasattr(item, 'getURL'):
        url_method = item.getURL
    elif hasattr(item, 'absolute_url'):
        url_method = item.absolute_url

    # Bug in Products.ATContenttypes
    # https://github.com/plone/Products.ATContentTypes/pull/4
    icon = item.getIcon
    if icon in ICONMAP.values():
        icon = icon.replace('gif', 'png')

    img = u'<img src="%s/%s"/>' % (portal_url(), item.getIcon)
    if not isinstance(value, unicode):
        value = value.decode('utf8')
    value = cgi.escape(value, quote=True)

    link = u'<a class="quick_preview" href="%s/quick_preview">%s%s</a>' % (
        url_method(), img, value)
    wrapper = u'<span class="linkWrapper">%s</span>' % link
    return wrapper