Skip to content

Commit

Permalink
Cleanup of PLIP #1734
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Jun 12, 2017
1 parent 9049e6c commit 08d8542
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 142 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Breaking changes:
New features:

- navigation-, news-, recent-,review-portlets: add options to supress icons,
read thumbsize from registry plus option to override thumbsize individually
read thumb_scale from registry plus option to override thumb_scale individually
or suppress thumbs.
Replace paper clip (fontello icon) with mimetype icon
from mimetype registry for files
Expand Down
98 changes: 59 additions & 39 deletions plone/app/portlets/portlets/navigation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner, aq_base, aq_parent
from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition import aq_parent
from ComputedAttribute import ComputedAttribute
from plone.app.layout.navigation.interfaces import INavigationQueryBuilder
from plone.app.layout.navigation.interfaces import INavigationRoot
Expand Down Expand Up @@ -28,11 +30,16 @@
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 adapts
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.interface import implementer, Interface
from zope.component import queryUtility
from zope.interface import implementer
from zope.interface import Interface

import os


class INavigationPortlet(IPortletDataProvider):
"""A portlet which can render the navigation tree
"""
Expand Down Expand Up @@ -99,29 +106,31 @@ class INavigationPortlet(IPortletDataProvider):
required=False)

no_icons = schema.Bool(
title=_(u"Suppress Icons "),
title=_(u"Suppress Icons"),
description=_(
u"If enabled, the portlet will not show document type icons"),
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>"),
thumb_scale = schema.TextLine(
title=_(u"Override thumb scale"),
description=_(
u"Enter a valid scale name"
u" (see 'Image Handling' control panel) to override"
u" (e.g. icon, tile, thumb, mini, preview, ... )."
u" Leave empty to use default (see 'Site' control panel)."
),
required=False,
default=u'')

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


@implementer(INavigationPortlet)
class Assignment(base.Assignment):

Expand All @@ -133,21 +142,30 @@ class Assignment(base.Assignment):
topLevel = 1
bottomLevel = 0
no_icons = False
ov_thumbsize = ''
thumb_scale = None
no_thumbs = False

def __init__(self, name="", root_uid=None,
currentFolderOnly=False, 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,
no_icons=False,
thumb_scale=None,
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
self.thumb_scale = thumb_scale
self.no_thumbs = no_thumbs

@property
def title(self):
Expand Down Expand Up @@ -310,39 +328,40 @@ def getNavTree(self, _marker=None):
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 > ' ':
def thumb_scale(self):
"""Use override value or read thumb_scale 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, 'thumb_scale', None)
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
thumb_scale_portlet = settings.thumb_scale_portlet
return thumb_scale_portlet

def getMimeTypeIcon(self,node):
def getMimeTypeIcon(self, node):
try:
if not node['normalized_portal_type'] == 'file':
return None
fileo = node['item'].getObject().file
portal_url = getNavigationRoot(self.context)
mtt = getToolByName(self.context,'mimetypes_registry')
mtt = getToolByName(self.context, 'mimetypes_registry')
if fileo.contentType:
ctype = mtt.lookup(fileo.contentType)
return os.path.join(portal_url,
guess_icon_path(ctype[0])
)
except (AttributeError):
return None
return os.path.join(
portal_url,
guess_icon_path(ctype[0])
)
except AttributeError:
return None
return None

def update(self):
Expand All @@ -351,6 +370,7 @@ def update(self):
def render(self):
return self._template()


class AddForm(base.AddForm):
schema = INavigationPortlet
label = _(u"Add Navigation Portlet")
Expand Down
8 changes: 4 additions & 4 deletions plone/app/portlets/portlets/navigation_recurse.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bottomLevel options/bottomLevel | nothing;
supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
thumb_size python:view.thumb_size();"
thumb_scale view/thumb_scale"
i18n:domain="plone">

<metal:main define-macro="nav_main"
Expand Down Expand Up @@ -39,8 +39,8 @@
tal:attributes="href node/getURL;
src python:view.getMimeTypeIcon(node);">

<img tal:condition="python:has_thumb and ( thumb_size !='none' )"
tal:replace="structure python:image_scale.tag(item, 'image', scale=thumb_size, css_class='pull-right image-'+thumb_size)">
<img tal:condition="python:has_thumb and thumb_scale"
tal:replace="structure python:image_scale.tag(item, 'image', scale=thumb_scale, css_class='pull-right image-'+thumb_scale)">

<span tal:replace="node/Title">Selected Item Title</span>
</a>
Expand All @@ -55,4 +55,4 @@
</li>
</tal:navitem>
</metal:main>
</tal:master>
</tal:master>
12 changes: 6 additions & 6 deletions plone/app/portlets/portlets/news.pt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
i18n:translate="box_news">News</a>
</header>
<div
tal:define="thumb_size python:view.thumb_size();
supress_thumb view/data/no_thumbs;"
tal:define="thumb_scale view/thumb_scale;
supress_thumb view/data/no_thumbs;"
class="portletContent">
<ul>
<tal:newsitems tal:define="toLocalizedTime nocall:context/@@plone/toLocalizedTime;
plone_layout context/@@plone_layout;
portal context/@@plone_portal_state/portal;
image_scale portal/@@image_scale;
thumb_size view/thumb_size;"
thumb_scale view/thumb_scale"
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'">
Expand All @@ -31,8 +31,8 @@
class="tile"
tal:attributes="href obj/getURL;
title obj/Description">
<img tal:condition="python: obj.getIcon and (view.thumb_size()!='none')"
tal:replace="structure python:image_scale.tag(obj, 'image', scale=thumb_size, css_class='pull-right image-'+thumb_size)" />
<img tal:condition="python:obj.getIcon and thumb_scale"
tal:replace="structure python:image_scale.tag(obj, 'image', scale=thumb_scale, css_class='pull-right image-'+thumb_scale)" />

<span tal:replace="obj/pretty_title_or_id">
Plone 5.1 announced!
Expand All @@ -56,4 +56,4 @@
<footer class="portletFooter" tal:condition="not:view/all_news_link">
</footer>
</aside>
</html>
</html>
51 changes: 28 additions & 23 deletions plone/app/portlets/portlets/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ 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>"),
thumb_scale = schema.TextLine(
title=_(u"Override thumb scale"),
description=_(
u"Enter a valid scale name"
u" (see 'Image Handling' control panel) to override"
u" (e.g. icon, tile, thumb, mini, preview, ... )."
u" Leave empty to use default (see 'Site' control panel)."
),
required=False,
default=u'')

no_thumbs = schema.Bool(
title=_(u"Suppress thumbs "),
title=_(u"Suppress thumbs"),
description=_(
u"If enabled, the portlet will not show thumbs"),
required=True,
Expand All @@ -59,12 +60,16 @@ class INewsPortlet(IPortletDataProvider):
@implementer(INewsPortlet)
class Assignment(base.Assignment):

thumb_scale = None
no_thumbs = False

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

@property
def title(self):
return _(u"News")
Expand Down Expand Up @@ -113,24 +118,24 @@ def _data(self):
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 > ' ':
def thumb_scale(self):
"""Use override value or read thumb_scale 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, 'thumb_scale', '')
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
return None
thumb_scale_portlet = settings.thumb_scale_portlet
return thumb_scale_portlet


class AddForm(base.AddForm):
Expand Down
13 changes: 6 additions & 7 deletions plone/app/portlets/portlets/recent.pt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
tal:define="plone_layout context/@@plone_layout;
portal context/@@plone_portal_state/portal;
image_scale portal/@@image_scale;
supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
thumb_size python:view.thumb_size();">
supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
thumb_scale view/thumb_scale">
<ul>
<tal:items tal:define="plone_view context/@@plone;
normalizeString nocall:plone_view/normalizeString;
Expand All @@ -40,9 +40,8 @@
tal:attributes="href obj/getURL;
src python:view.getMimeTypeIcon(obj);">

<img tal:define="thumb_size view/thumb_size;"
tal:condition="python: obj.getIcon and (view.thumb_size()!='none'and not supress_thumb and image_scale is not None)"
tal:replace="structure python:image_scale.tag(obj, 'image', scale=thumb_size, css_class='pull-right image-'+thumb_size)" />
<img tal:condition="python:obj.getIcon and thumb_scale and not supress_thumb and image_scale"
tal:replace="structure python:image_scale.tag(obj, 'image', scale=thumb_scale, css_class='pull-right image-'+thumb_scale)" />

<span tal:content="obj/pretty_title_or_id">
Title
Expand Down Expand Up @@ -72,4 +71,4 @@
</footer>

</aside>
</html>
</html>
Loading

0 comments on commit 08d8542

Please sign in to comment.