Skip to content

Commit

Permalink
navigation-, news-, recent-,review-portlets: add options to supress i…
Browse files Browse the repository at this point in the history
…cons, read thumbsize from registry plus option to override thumbsize individually / or suppress thumbs.

://github.com/plone/Products.CMFPlone/issues/1734
  • Loading branch information
fgrcon committed Oct 3, 2016
1 parent 3b77a09 commit afc5e39
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 53 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ Breaking changes:

New features:

- *add item here*
- navigation-, news-, recent-,review-portlets: add options to supress icons,
read thumbsize from registry plus option to override thumbsize individually
or suppress thumbs.
Replace paper clip (fontello icon) with mimetype icon
from mimetype registry for files
https://github.com/plone/Products.CMFPlone/issues/1734 [fgrcon]

Bug fixes:

Expand Down
1 change: 1 addition & 0 deletions plone/app/portlets/portlets/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
assignment=".review.Assignment"
renderer=".review.Renderer"
addview=".review.AddForm"
editview=".review.EditForm"
/>

<plone:portlet
Expand Down
83 changes: 75 additions & 8 deletions plone/app/portlets/portlets/navigation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Acquisition import aq_inner, aq_base, aq_parent
from ComputedAttribute import ComputedAttribute
from plone import api
from plone.app.layout.navigation.interfaces import INavigationQueryBuilder
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.layout.navigation.interfaces import INavtreeStrategy
Expand All @@ -22,13 +23,15 @@
from Products.CMFPlone.defaultpage import is_default_page
from Products.CMFPlone.interfaces import INavigationSchema
from Products.CMFPlone.interfaces import INonStructuralFolder
from Products.CMFPlone.interfaces import ISiteSchema
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.MimetypesRegistry.MimeTypeItem import guess_icon_path
from zExceptions import NotFound
from zope import schema
from zope.component import adapts, getMultiAdapter, queryUtility
from zope.component import getUtility
from zope.interface import implementer, Interface

import os

class INavigationPortlet(IPortletDataProvider):
"""A portlet which can render the navigation tree
Expand Down Expand Up @@ -95,6 +98,29 @@ class INavigationPortlet(IPortletDataProvider):
default=0,
required=False)

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"
u"(see 'Image Handling' control panel) to override"
u" e.g. icon, tile, thumb, mini, preview, ... ) </li>"
u"<li>leave empty to use default "
u"(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(INavigationPortlet)
class Assignment(base.Assignment):
Expand All @@ -106,15 +132,23 @@ class Assignment(base.Assignment):
includeTop = False
topLevel = 1
bottomLevel = 0
no_icons = False
ov_thumbsize = ''
no_thumbs = False

def __init__(self, name="", root_uid=None, currentFolderOnly=False, includeTop=False, topLevel=1, bottomLevel=0):
def __init__(self, name="", root_uid=None,
currentFolderOnly=False, includeTop=False, topLevel=1, bottomLevel=0,
no_icons = False, ov_thumbsize = '', no_thumbs = False):
self.name = name
self.root_uid = root_uid
self.currentFolderOnly = currentFolderOnly
self.includeTop = includeTop
self.topLevel = topLevel
self.bottomLevel = bottomLevel

self.no_icons = no_icons
self.ov_thumbsize = ov_thumbsize
self.ov_thumbsize = ov_thumbsize

@property
def title(self):
"""
Expand Down Expand Up @@ -278,16 +312,49 @@ def getNavTree(self, _marker=None):

return buildFolderTree(context, obj=context, query=queryBuilder(), strategy=strategy)

def update(self):
pass

def render(self):
return self._template()

_template = ViewPageTemplateFile('navigation.pt')
recurse = ViewPageTemplateFile('navigation_recurse.pt')

@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 getattr(self.data,'no_thumbs',False):
#individual setting overrides ...
return 'none'
thsize=getattr(self.data,'ov_thumbsize','')
if thsize > ' ':
return thsize
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

def getMimeTypeIcon(self,node):
if not node['normalized_portal_type'] == 'file':
return None
fileo = node['item'].getObject().file
portal_url = api.portal.get().absolute_url()
mtt = api.portal.get_tool(name='mimetypes_registry')
if fileo.contentType:
ctype = mtt.lookup(fileo.contentType)
return os.path.join(portal_url,
guess_icon_path(ctype[0])
)
return None

def update(self):
pass

def render(self):
return self._template()

class AddForm(base.AddForm):
schema = INavigationPortlet
label = _(u"Add Navigation Portlet")
Expand Down
23 changes: 16 additions & 7 deletions plone/app/portlets/portlets/navigation_recurse.pt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<tal:master define="level options/level | python:0;
children options/children | nothing;
bottomLevel options/bottomLevel | nothing"
bottomLevel options/bottomLevel | nothing;
supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
thumb_size python:view.thumb_size();
thumb_class python:'pull-right image-'+thumb_size "
i18n:domain="plone">

<metal:main define-macro="nav_main">
Expand All @@ -12,27 +16,32 @@
use_remote_url node/useRemoteUrl | nothing;
item_type node/portal_type;
has_thumb node/item/getIcon;
thumb_url string:${node/item/getURL}/@@images/image/icon;
thumb_url string:${node/item/getURL}/@@images/image/${view/thumb_size};
is_current node/currentItem;
is_in_path node/currentParent;
li_class python:' navTreeCurrentNode' if is_current else '';
li_extr_class python:' navTreeItemInPath' if is_in_path else '';
li_folder_class python:' navTreeFolderish' if show_children else '';
normalizeString nocall: context/plone_utils/normalizeString"
normalizeString nocall: context/plone_utils/normalizeString;"
tal:condition="python:bottomLevel &lt;= 0 or level &lt;= bottomLevel"
tal:attributes="class string:navTreeItem visualNoMarker${li_class}${li_extr_class}${li_folder_class} section-${node/normalized_id}">

<tal:level define="item_class string:state-${node/normalized_review_state};
item_type_class python:'contenttype-%s' % normalizeString(item_type);
item_type_class python:'contenttype-%s' % normalizeString(item_type) if not supress_icon else '';
item_class python:'%s navTreeCurrentItem' % item_class if is_current else item_class">

<a tal:attributes="href python:item_remote_url if use_remote_url else item_url;
title node/Description;
class string:${item_class}${li_class}${li_extr_class}${li_folder_class} ${item_type_class}">
<img class="image-icon"
tal:condition="has_thumb"

<img tal:condition="python:item_type =='File' and not supress_icon"
tal:attributes="href node/getURL;
src python:view.getMimeTypeIcon(node);">
<img
tal:condition="python:has_thumb and ( thumb_size !='none' )"
tal:attributes="src thumb_url;
alt node/Description">
alt node/Description;
class thumb_class">
<span tal:replace="node/Title">Selected Item Title</span>
</a>

Expand Down
19 changes: 12 additions & 7 deletions plone/app/portlets/portlets/news.pt
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@
tal:attributes="href all_news_link"
i18n:translate="box_news">News</a>
</header>
<div class="portletContent">
<div
tal:define="thumb_size python:view.thumb_size();
supress_thumb view/data/no_thumbs;"
class="portletContent">
<ul>
<tal:newsitems tal:define="toLocalizedTime nocall:context/@@plone/toLocalizedTime;
plone_layout context/@@plone_layout"
plone_layout context/@@plone_layout;
"
tal:repeat="obj view/published_news_items">
<li tal:define="oddrow repeat/obj/odd;"
tal:attributes="class python:oddrow and 'portletItem even' or 'portletItem odd'">

<a href=""
class="tile"
tal:attributes="href obj/getURL;
title obj/Description">
<img class="image-icon"
tal:define="getIcon python:obj.getURL()+'/@@images/image/icon'"
tal:condition="python: obj.getIcon"
<img
tal:define="thumb_url string:${obj/getURL}/@@images/image/${view/thumb_size};
"
tal:condition="python:obj.getIcon and (view.thumb_size()!='none')"
tal:attributes="href obj/getURL;
src string:$getIcon">
src string:$thumb_url;
class python:'image-'+thumb_size + ' pull-right'">
<span tal:replace="obj/pretty_title_or_id">
Plone 5.1 announced!
</span>
Expand Down
47 changes: 43 additions & 4 deletions plone/app/portlets/portlets/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
from plone.memoize import ram
from plone.memoize.instance import memoize
from plone.portlets.interfaces import IPortletDataProvider
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import ISiteSchema
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope import schema
from zope.interface import implementer

Expand All @@ -34,14 +37,32 @@ class INewsPortlet(IPortletDataProvider):
vocabulary="plone.app.vocabularies.WorkflowStates")
)


ov_thumbsize = schema.TextLine(
title=_(u"Override thumb size "),
description=_(u"<br><ul><li> Enter a valid scale name"
u"(see 'Image Handling' control panel) to override"
u" e.g. icon, tile, thumb, mini, preview, ... ) </li>"
u"<li>leave empty to use default "
u"(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(INewsPortlet)
class Assignment(base.Assignment):

def __init__(self, count=5, state=('published', )):
def __init__(self, count=5, state=('published',),
ov_thumbsize = '', no_thumbs = False):
self.count = count
self.state = state

self.ov_thumbsize = ov_thumbsize
self.no_thumbs = no_thumbs
@property
def title(self):
return _(u"News")
Expand Down Expand Up @@ -89,7 +110,25 @@ def _data(self):
sort_on='Date',
sort_order='reverse',
sort_limit=limit)[:limit]


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 getattr(self.data,'no_thumbs',False):
#individual setting overrides ...
return 'none'
thsize=getattr(self.data,'ov_thumbsize','')
if thsize > ' ':
return thsize
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(base.AddForm):
schema = INewsPortlet
Expand Down
20 changes: 14 additions & 6 deletions plone/app/portlets/portlets/recent.pt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
tal:content="view/title" />
</header>
<div class="portletContent"
tal:condition="view/recent_items">
tal:condition="view/recent_items"
tal:define="supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
thumb_size python:view.thumb_size();
thumb_class python:'pull-right image-'+thumb_size ">
<ul>
<tal:items tal:define="plone_view context/@@plone;
normalizeString nocall:plone_view/normalizeString;
Expand All @@ -21,19 +25,23 @@

<li class="portletItem"
tal:define="oddrow repeat/obj/odd;
item_type obj/portal_type;
item_wf_state obj/review_state;
item_wf_state_class python:'state-' + normalizeString(item_wf_state);
item_class python:'contenttype-' + normalizeString(obj.portal_type);"
item_class python:'contenttype-' + normalizeString(obj.portal_type) if not supress_icon else '';"
tal:attributes="class python:oddrow and 'portletItem even' or 'portletItem odd'">
<a href=""
tal:attributes="href string:${obj/getURL}/view;
title obj/Description;
class string:$item_wf_state_class tile $item_class">
<img class="image-icon"
tal:define="getIcon python:obj.getURL()+'/@@images/image/icon'"
tal:condition="python: obj.getIcon"
<img tal:condition="python:item_type =='File' and not supress_icon"
tal:attributes="href obj/getURL;
src python:view.getMimeTypeIcon(obj);">
<img tal:define="thumb_url python:obj.getURL()+'/@@images/image/' + thumb_size"
tal:condition="python:obj.getIcon and (thumb_size !='none' )"
tal:attributes="href obj/getURL;
src string:$getIcon">
src thumb_url;
class thumb_class">
<span tal:content="obj/pretty_title_or_id">
Title
</span>
Expand Down
Loading

0 comments on commit afc5e39

Please sign in to comment.