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 Jan 3, 2017
1 parent a6de379 commit 5b364b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
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
@@ -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
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
"""

1 comment on commit 5b364b8

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fgrcon Jenkins CI reporting about code analysis
See the full report here: http://jenkins.plone.org/job/package-plone.app.contentlisting/3/violations

plone/app/contentlisting/catalog.py:42:12: P002 found "hasattr", consider replacing it
plone/app/contentlisting/catalog.py:44:14: P002 found "hasattr", consider replacing it
plone/app/contentlisting/tests/base.py:19:9: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/contentlisting/tests/base.py:21:9: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/contentlisting/tests/base.py:24:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/contentlisting/tests/base.py:43:1: E305 expected 2 blank lines after class or function definition, found 1

Follow these instructions to reproduce it locally.

Please sign in to comment.