Skip to content

Commit

Permalink
provide Mimetype icon path for file types in contentlisting object
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrcon committed Apr 5, 2017
1 parent 5743a10 commit 0d39e69
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- provide Mimetype icon path for file types in contentlisting object
https://github.com/plone/Products.CMFPlone/issues/1734 [fgrcon]

Bug fixes:

Expand Down
17 changes: 17 additions & 0 deletions plone/app/contentlisting/contentlisting.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# -*- coding: utf-8 -*-

from plone import api
from plone.app.contentlisting.interfaces import IContentListing
from plone.app.contentlisting.interfaces import IContentListingObject
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.registry.interfaces import IRegistry
from Products.CMFPlone.interfaces import INavigationSchema
from Products.MimetypesRegistry.MimeTypeItem import guess_icon_path
from zope.component import getUtility
from zope.component import queryUtility
from zope.interface import implementer

import os


@implementer(IContentListing)
class ContentListing(object):
Expand Down Expand Up @@ -141,3 +146,15 @@ def isVisibleInNav(self):
return False

return True

def MimeTypeIcon(self):
if not self.PortalType() == 'File':
return None
portal_url = api.portal.get().absolute_url()
mtt = api.portal.get_tool(name='mimetypes_registry')
if self.getObject().file.contentType:
ctype = mtt.lookup(self.getObject().file.contentType)
return os.path.join(portal_url,
guess_icon_path(ctype[0])
)
return None
5 changes: 5 additions & 0 deletions plone/app/contentlisting/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ def ContentTypeClass():
"""The contenttype suitable as a css class name, matching Plone
conventions.
"""

def MimeTypeIcon():
""" return mimetype icon from mimetype registry if contenttype is
File else None
"""

0 comments on commit 0d39e69

Please sign in to comment.