Skip to content

Commit

Permalink
option to override thumb /icon behavior individually for portlet (sup…
Browse files Browse the repository at this point in the history
…press thumbs, thumb size, suppress icons)

plone/Products.CMFPlone#1734 (PLIP) [fgrcon]
  • Loading branch information
fgrcon committed Sep 1, 2016
1 parent 456b860 commit 84c967e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Breaking changes:

New features:

- *add item here*
- option to override thumb /icon behavior individually for portlet (suppress thumbs, thumb size, suppress icons) https://github.com/plone/Products.CMFPlone/issues/1734 (PLIP) [fgrcon]

Bug fixes:

Expand Down
8 changes: 5 additions & 3 deletions plone/portlet/collection/collection.pt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
item_wf_state obj/review_state;
item_wf_state_class python:'state-' + plone_view.normalizeString(item_wf_state);
item_type obj/portal_type;
item_type_class python:'contenttype-' + plone_view.normalizeString(item_type);"
supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
item_type_class python:('contenttype-' + plone_view.normalizeString(item_type)) if not supress_icon else ''"
tal:attributes="class python:oddrow and 'portletItem even' or 'portletItem odd'">
<a href="#"
tal:attributes="href itemUrl;
class string:tile $item_type_class $item_wf_state_class;
title obj/Description">
<img class="image-icon"
tal:define="thumb python:obj.getURL()+'/@@images/image/icon'"
tal:condition=" obj/getIcon"
tal:condition="python:obj.getIcon and (view.thumb_size()!='none') and (not supress_thumb)"
tal:define="thumb python:obj.getURL()+'/@@images/image/' + view.thumb_size()"
tal:attributes="href obj/getURL;
src string:$thumb;">
<span tal:replace="obj/Title">
Expand Down
50 changes: 46 additions & 4 deletions plone/portlet/collection/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from plone.memoize.instance import memoize
from plone.portlet.collection import PloneMessageFactory as _
from plone.portlets.interfaces import IPortletDataProvider
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zExceptions import NotFound
from zope import schema
Expand Down Expand Up @@ -83,6 +85,27 @@ class ICollectionPortlet(IPortletDataProvider):
required=True,
default=True)

no_icons = schema.Bool(
title=_(u"Suppress Icons "),
description=_(
u"If enabled, the portlet will not show document type icons"),
required=True,
default=False)

ov_thumbsize = schema.TextLine(
title=_(u"Override thumb size "),
description=_(u"<br><ul><li> Enter a valid scale name (see 'Image Handling' control panel) to override"
u" e.g. icon, tile, thumb, mini, preview, ... , </li>"
u"<li>leave empty to use default (see 'Site' control panel)</li></ul>"),
required=False,
default=u'')

no_thumbs = schema.Bool(
title=_(u"Suppress thumbs "),
description=_(
u"If enabled, the portlet will not show thumbs"),
required=True,
default=False)

@implementer(ICollectionPortlet)
class Assignment(base.Assignment):
Expand All @@ -91,27 +114,32 @@ class Assignment(base.Assignment):
This is what is actually managed through the portlets UI and associated
with columns.
"""

header = u""
limit = None
random = False
show_more = True
show_dates = False
exclude_context = False

no_icons = False
no_thumbs = False
ov_thumbsize = ''
# bbb
target_collection = None

def __init__(self, header=u"", uid=None, limit=None,
random=False, show_more=True, show_dates=False,
exclude_context=True):
exclude_context=True, no_icons = False, no_thumbs = False,
ov_thumbsize = ''):
self.header = header
self.uid = uid
self.limit = limit
self.random = random
self.show_more = show_more
self.show_dates = show_dates
self.exclude_context = exclude_context
self.no_icons = no_icons
self.no_thumbs = no_thumbs
self.ov_thumbsize = ov_thumbsize

@property
def title(self):
Expand All @@ -135,7 +163,6 @@ def _uid(self):


class Renderer(base.Renderer):

_template = ViewPageTemplateFile('collection.pt')
render = _template

Expand Down Expand Up @@ -224,6 +251,21 @@ def include_empty_footer(self):
"""
return True

@memoize
def thumb_size(self):
''' use overrride value or read thumb_size from registry
image sizes must fit to value in allowed image sizes
none will suppress thumb!
'''
if self.data.ov_thumbsize > ' ':
return self.data.ov_thumbsize
registry = getUtility(IRegistry)
settings = registry.forInterface(
ISiteSchema, prefix="plone", check=False)
if settings.no_thumbs_portlet:
return 'none'
thumb_size_portlet = settings.thumb_size_portlet
return thumb_size_portlet

class AddForm(formhelper.AddForm):
schema = ICollectionPortlet
Expand Down

0 comments on commit 84c967e

Please sign in to comment.