Skip to content

Commit

Permalink
Cleanup and rework: contenttype-icons and
Browse files Browse the repository at this point in the history
 showing thumbnails for images/leadimages in listings ...
plone/Products.CMFPlone#1226
plone/Products.CMFPlone#1185
  • Loading branch information
fgrcon committed Nov 6, 2015
1 parent e27ee98 commit 3cfc044
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 94 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Fixes:
[pbauer]

- Fixed full_view when content is not IUUIDAware (like the portal).

- Cleanup and rework: contenttype-icons
and showing thumbnails for images/leadimages in listings ...
https://github.com/plone/Products.CMFPlone/issues/1226
[fgrcon]

- Fix full_view when content is not IUUIDAware (like the portal).
Fixes https://github.com/plone/Products.CMFPlone/issues/1109.
[pbauer]

Expand Down
6 changes: 0 additions & 6 deletions plone/app/contenttypes/browser/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ def tabular_fielddata(self, item, fieldname):
'value': value
}

def has_image(self, obj):
if getattr(obj, 'getObject', False):
obj = obj.getObject()
img = getattr(aq_base(obj), 'image', None)
return True if img else False

def is_event(self, obj):
if getattr(obj, 'getObject', False):
obj = obj.getObject()
Expand Down
22 changes: 12 additions & 10 deletions plone/app/contenttypes/browser/templates/listing.pt
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@
item_type item/PortalType;
item_modified item/ModificationDate;
item_created item/CreationDate;
item_icon item/getIcon;
item_type_class python:'contenttype-' + view.normalizeString(item_type);
item_wf_state item/review_state;
item_wf_state_class python:'state-' + view.normalizeString(item_wf_state);
item_creator item/Creator;
item_link python:item_type in view.use_view_action and item_url+'/view' or item_url;
item_has_image python:view.has_image(obj);
item_is_event python:view.is_event(obj)">
item_link python:item_type in view.use_view_action and item_url+'/view' or item_url;
item_is_event python:view.is_event(obj);
item_has_image python:item.getIcon">
<metal:block define-slot="entry">
<article class="entry">
<header metal:define-macro="listitem" tal:attributes="class python:'vevent' if item_is_event else None">
<span class="summary">
<a tal:attributes="href item_link;
class string:$item_type_class $item_wf_state_class url;
title item_type"
tal:content="item_title">
Item Title
<span class="summary" tal:attributes="title item_type">
<a tal:attributes="href item_link">
<img class="image-tile"
tal:define="getIcon python:item.getURL()+'/@@images/image/tile'"
tal:condition="item_has_image"
tal:attributes="src string:$getIcon">
<span tal:attributes="class string:$item_type_class $item_wf_state_class url;"
tal:content="item_title">
Item Title</span>
</a>
</span>

Expand Down
6 changes: 6 additions & 0 deletions plone/app/contenttypes/browser/templates/listing_tabular.pt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<tal:block tal:replace="field_data/value" />
</td>
<td tal:condition="python:field == 'Title'">
<img
tal:define="getIcon python:item.getURL()+'/@@images/image/icon'"
tal:condition="python: item.getIcon"
tal:attributes="href item/getURL;
src string:$getIcon"
/>
<a href="#"
tal:attributes="href item_link;
class string:$item_wf_state_class $item_type_class;
Expand Down
61 changes: 15 additions & 46 deletions plone/app/contenttypes/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from Products.CMFPlone.utils import safe_unicode
from ZODB.POSException import ConflictError
from logging import getLogger
from plone.app.contenttypes.behaviors.richtext import IRichText
from plone.dexterity.interfaces import IDexterityContent
from plone.app.contenttypes.interfaces import IDocument
from plone.app.contenttypes.interfaces import IFile
from plone.app.contenttypes.interfaces import IFolder
Expand Down Expand Up @@ -139,48 +139,17 @@ def getObjSize_file(obj):
return obj.getObjSize(None, primary_field_info.value.size)


@indexer(IFile)
def getIcon_file(obj):
"""icon of the given mimetype,
parts of this this code are borrowed from atct.
"""
mtr = getToolByName(obj, 'mimetypes_registry', None)
if mtr is None:
return None

try:
primary_field_info = IPrimaryFieldInfo(obj, None)
except TypeError:
logger.warn(u'Lookup of PrimaryField failed for %s '
u'If renaming or importing please reindex!' %
obj.absolute_url())
return
if not primary_field_info.value:
# There is no file so we should show a generic icon
# TODO : find a better icon for generic
return 'png.png'
# return None

contenttype = None
if hasattr(primary_field_info.value, "contentType"):
contenttype = primary_field_info.value.contentType
if not contenttype:
contenttype = FALLBACK_CONTENTTYPE

mimetypeitem = None
try:
mimetypeitem = mtr.lookup(contenttype)
except Exception, msg:
logger.warn('mimetype lookup failed for %s. Error: %s' %
(obj.absolute_url(), str(msg)))

if not mimetypeitem:
mimetypeitem = mtr.lookup(FALLBACK_CONTENTTYPE)

return mimetypeitem[0].icon_path


@indexer(IImage)
def getIcon_image(obj):
return getIcon_file(obj)
@indexer(IDexterityContent)
def getIcon(obj):
'''
geticon redefined in Plone > 5.0
see https://github.com/plone/Products.CMFPlone/issues/1226
reuse of metadata field,
now used for showing thumbs in content listings etc.
when obj is an image or has a lead image
or has an image field with name 'image': true else false
'''
if obj.image:
return True
return False
3 changes: 1 addition & 2 deletions plone/app/contenttypes/indexers.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<adapter name="getRemoteUrl" factory=".indexers.getRemoteUrl" />
<adapter name="getObjSize" factory=".indexers.getObjSize_image" />
<adapter name="getObjSize" factory=".indexers.getObjSize_file" />
<adapter name="getIcon" factory=".indexers.getIcon_image" />
<adapter name="getIcon" factory=".indexers.getIcon_file" />
<adapter name="getIcon" factory=".indexers.getIcon" />

</configure>
30 changes: 0 additions & 30 deletions plone/app/contenttypes/tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,33 +298,3 @@ def test_getobjsize_file(self):
self.portal.getObjSize(None, primary_field_info.value.size),
brains[0].getObjSize,
)

def test_geticon_image(self):
from .test_image import dummy_image

primary_field_info = IPrimaryFieldInfo(self.image)
primary_field_info.field.set(self.image, dummy_image())
self.image.reindexObject()

brains = self.catalog.searchResults(dict(
path="/plone/folder/image",
))

self.assertEqual('image.png', brains[0].getIcon)

def test_geticon_file(self):
from plone.namedfile.file import NamedBlobFile

filename = os.path.join(os.path.dirname(__file__), u'file.pdf')
test_file = NamedBlobFile(data=open(filename, 'r').read(),
filename=filename)

primary_field_info = IPrimaryFieldInfo(self.file)
primary_field_info.field.set(self.file, test_file)
self.file.reindexObject()

brains = self.catalog.searchResults(dict(
path="/plone/folder/file",
))

self.assertEqual('pdf.png', brains[0].getIcon)

0 comments on commit 3cfc044

Please sign in to comment.