Skip to content

Commit

Permalink
Merge pull request #19 from plone/plip1734thumbs
Browse files Browse the repository at this point in the history
Plip1734thumbs
  • Loading branch information
ebrehault committed Jun 1, 2017
2 parents ababbb3 + 17a8deb commit f0b255d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Expand Up @@ -10,7 +10,9 @@ 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
9 changes: 4 additions & 5 deletions README.rst
Expand Up @@ -156,11 +156,6 @@ uuid() -
point of it is to be unique. It can for example look like this
`b0e80776-d41d-4f48-bf9e-7cb1aebabad5`.

getIcon() -
Icon for the object. Returns an icon object from plone.app.layout.
If printed as a string, it will produce an HTML tag for the icon. Check
plone.app.layout for more info.

getSize() -
Size in bytes for example `24`.

Expand Down Expand Up @@ -254,3 +249,7 @@ Rights() -

isVisibleInNav() -
Return whether this object will be visible in a navigation view.

MimeTypeIcon():
Return mimetype icon from mimetype registry if contenttype is
File else None.
22 changes: 22 additions & 0 deletions plone/app/contentlisting/contentlisting.py
@@ -1,13 +1,20 @@
# -*- coding: utf-8 -*-

from Acquisition import aq_base
from plone.app.contentlisting.interfaces import IContentListing
from plone.app.contentlisting.interfaces import IContentListingObject
from plone.app.layout.navigation.root import getNavigationRoot
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
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 +148,18 @@ def isVisibleInNav(self):
return False

return True

def MimeTypeIcon(self):
mimeicon = None
navroot = getNavigationRoot(self._brain)
contenttype = aq_base(
getattr(self._brain, 'mime_type', None))
if contenttype:
mtt = getToolByName(
self._brain, 'mimetypes_registry')
ctype = mtt.lookup(contenttype)
mimeicon = os.path.join(
navroot,
guess_icon_path(ctype[0]))

return mimeicon
5 changes: 5 additions & 0 deletions plone/app/contentlisting/interfaces.py
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 f0b255d

Please sign in to comment.