Skip to content

Commit

Permalink
usage of zca decorators and manual readability tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Apr 23, 2016
1 parent dffd910 commit 34d7d07
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 68 deletions.
1 change: 1 addition & 0 deletions plone/app/layout/analytics/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
8 changes: 4 additions & 4 deletions plone/app/layout/analytics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from Products.CMFPlone.interfaces import ISiteSchema
from Products.Five.browser import BrowserView
from zope.component import getUtility
from zope.interface import implements
from zope.interface import implementer
from zope.viewlet.interfaces import IViewlet


@implementer(IViewlet)
class AnalyticsViewlet(BrowserView):
implements(IViewlet)

def __init__(self, context, request, view, manager):
super(AnalyticsViewlet, self).__init__(context, request)
Expand All @@ -29,6 +29,6 @@ def render(self):
try:
if site_settings.webstats_js:
return site_settings.webstats_js
return ''
except AttributeError:
return ''
pass
return ''
7 changes: 4 additions & 3 deletions plone/app/layout/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
from Products.CMFPlone import PloneMessageFactory as _
from Products.Five.browser import BrowserView
from Products.statusmessages.interfaces import IStatusMessage
from zope import interface
from zope.component import getUtility
from zope.interface import implementer
from zope.interface import Interface


class IDashboard(interface.Interface):
class IDashboard(Interface):
"""the dashboard display columns of portlet to the loggedin user"""


@implementer(IDashboard)
class DashboardView(BrowserView):
"""Power the dashboard
"""
interface.implements(IDashboard)

def __call__(self):
self.request.set('disable_border', 1)
Expand Down
6 changes: 4 additions & 2 deletions plone/app/layout/dashboard/user_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class UserActionsView(BrowserView):
"""

def user_actions(self):
context_state = getMultiAdapter((self.context, self.request),
name=u'plone_context_state')
context_state = getMultiAdapter(
(self.context, self.request),
name=u'plone_context_state'
)

actions = context_state.actions('user')
return actions
5 changes: 2 additions & 3 deletions plone/app/layout/globals/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
from zope.component import getUtility
from zope.component import queryAdapter
from zope.component import queryMultiAdapter
from zope.interface import implements
from zope.interface import implementer


BLACKLISTED_PROVIDERS = ('portal_workflow', )
BLACKLISTED_CATEGORIES = ('folder_buttons', 'object_buttons', )


@implementer(IContextState)
class ContextState(BrowserView):
"""Information about the state of the current context
"""

implements(IContextState)

@memoize
def current_page_url(self):
url = self.current_base_url()
Expand Down
4 changes: 2 additions & 2 deletions plone/app/layout/globals/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plone.memoize.view import memoize
from Products.Five.browser import BrowserView
from zope.dottedname.resolve import resolve
from zope.interface import implements
from zope.interface import implementer
from zope.interface import Interface
from zope.interface import providedBy
from zope.interface.interfaces import IMethod
Expand Down Expand Up @@ -49,8 +49,8 @@ def visitBaseInterfaces(iface, lst):
visitBaseInterfaces(iface, lst)


@implementer(IInterfaceInformation)
class InterfaceInformation(BrowserView):
implements(IInterfaceInformation)

@memoize
def provides(self, dotted_name):
Expand Down
7 changes: 3 additions & 4 deletions plone/app/layout/globals/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
from Products.Five.browser.metaconfigure import ViewMixinForTemplates
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile as ZopeViewPageTemplateFile
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile as ZopeViewPageTemplateFile # noqa
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component import queryMultiAdapter
from zope.component import queryUtility
from zope.interface import alsoProvides
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.browser import BrowserView

import json


@implementer(ILayoutPolicy)
class LayoutPolicy(BrowserView):
"""A view that gives access to various layout related functions.
"""

implements(ILayoutPolicy)

def mark_view(self, view):
"""Adds a marker interface to the view if it is "the" view for the
context May only be called from a template.
Expand Down
4 changes: 2 additions & 2 deletions plone/app/layout/globals/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
from zope.component import getUtility
from zope.component import providedBy
from zope.component.hooks import getSite
from zope.interface import implements
from zope.interface import implementer


RIGHT_TO_LEFT = ['ar', 'fa', 'he', 'ps']


@implementer(IPortalState)
class PortalState(BrowserView):
"""Information about the state of the portal
"""
implements(IPortalState)

@memoize_contextless
def portal(self):
Expand Down
5 changes: 2 additions & 3 deletions plone/app/layout/globals/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from plone.memoize.view import memoize_contextless
from Products.CMFCore.utils import getToolByName
from Products.Five.browser import BrowserView
from zope.interface import implements
from zope.interface import implementer


@implementer(ITools)
class Tools(BrowserView):
"""Common tools
"""

implements(ITools)

@memoize_contextless
def actions(self):
return getToolByName(self.context, 'portal_actions')
Expand Down
12 changes: 6 additions & 6 deletions plone/app/layout/icons/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from zope.i18n import translate
from zope.interface import implements
from zope.interface import implementer


class BaseIcon(object):
Expand Down Expand Up @@ -36,8 +36,8 @@ def html_tag(self):
return tag


@implementer(IContentIcon)
class CatalogBrainContentIcon(BaseIcon):
implements(IContentIcon)

def __init__(self, context, request, brain):
self.context = context
Expand Down Expand Up @@ -100,8 +100,8 @@ def extensions_mimetype(self):
return extensions


@implementer(IContentIcon)
class CMFContentIcon(BaseIcon):
implements(IContentIcon)

def __init__(self, context, request, obj):
self.context = context
Expand Down Expand Up @@ -132,8 +132,8 @@ def description(self):
return self.obj.portal_type


@implementer(IContentIcon)
class FTIContentIcon(BaseIcon):
implements(IContentIcon)

def __init__(self, context, request, obj):
self.context = context
Expand Down Expand Up @@ -162,8 +162,8 @@ def description(self):
return self.obj.Title()


@implementer(IContentIcon)
class PloneSiteContentIcon(BaseIcon):
implements(IContentIcon)

def __init__(self, context, request, obj):
self.context = context
Expand All @@ -189,8 +189,8 @@ def description(self):
return self.obj.Title()


@implementer(IContentIcon)
class DefaultContentIcon(BaseIcon):
implements(IContentIcon)

def __init__(self, context, request, obj):
self.context = context
Expand Down
5 changes: 2 additions & 3 deletions plone/app/layout/navigation/navtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone import utils
from types import StringType
from zope.interface import implements
from zope.interface import implementer


@implementer(INavtreeStrategy)
class NavtreeStrategyBase(object):
"""Basic navigation tree strategy that does nothing.
"""

implements(INavtreeStrategy)

__allow_access_to_unprotected_subobjects__ = 1

rootPath = None
Expand Down
18 changes: 10 additions & 8 deletions plone/app/layout/sitemap/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def objects(self):
yield {
'loc': loc,
'lastmod': lastmod,
#'changefreq': 'always',
# hourly/daily/weekly/monthly/yearly/never
#'prioriy': 0.5, # 0.0 to 1.0
# 'changefreq': 'always',
# hourly/daily/weekly/monthly/yearly/never
# 'prioriy': 0.5, # 0.0 to 1.0
}

query['is_default_page'] = False
Expand All @@ -92,9 +92,9 @@ def objects(self):
yield {
'loc': loc,
'lastmod': lastmod,
#'changefreq': 'always',
# hourly/daily/weekly/monthly/yearly/never
#'prioriy': 0.5, # 0.0 to 1.0
# 'changefreq': 'always',
# hourly/daily/weekly/monthly/yearly/never
# 'prioriy': 0.5, # 0.0 to 1.0
}

@ram.cache(_render_cachekey)
Expand All @@ -116,6 +116,8 @@ def __call__(self):
if not settings.enable_sitemap:
raise NotFound(self.context, self.filename, self.request)

self.request.response.setHeader('Content-Type',
'application/octet-stream')
self.request.response.setHeader(
'Content-Type',
'application/octet-stream'
)
return self.generate()
1 change: 0 additions & 1 deletion plone/app/layout/testing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
Expand Down
22 changes: 13 additions & 9 deletions plone/app/layout/viewlets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
from zope.deprecation.deprecation import deprecate
from zope.i18n import translate
from zope.interface import alsoProvides
from zope.interface import implements
from zope.interface import implementer
from zope.viewlet.interfaces import IViewlet


@implementer(IViewlet)
class ViewletBase(BrowserView):
""" Base class with common functions for link viewlets.
"""
implements(IViewlet)

def __init__(self, context, request, view, manager=None):
super(ViewletBase, self).__init__(context, request)
Expand Down Expand Up @@ -258,7 +258,7 @@ def update(self):
'title': action['title'],
'href': action['url'],
'id': 'personaltools-{}'.format(action['id']),
'target': 'link_target' in action and action['link_target'] or None,
'target': action.get('link_target', None),
}
modal = action.get('modal')
if modal:
Expand Down Expand Up @@ -469,13 +469,15 @@ def render_footer_portlets(self):
You might ask, why is this necessary. Well, let me tell you a story...
plone.app.portlets, in order to provide @@manage-portlets on a context,
overrides the IPortletRenderer for the IManageContextualPortletsView view.
overrides the IPortletRenderer for the IManageContextualPortletsView
view.
See plone.portlets and plone.app.portlets
Seems fine right? Well, most of the time it is. Except, here. Previously,
we were just using the syntax like `provider:plone.footerportlets` to
render the footer portlets. Since this tal expression was inside
a viewlet, the view is no longer IManageContextualPortletsView when
Seems fine right? Well, most of the time it is. Except, here.
Previously, we were just using the syntax like
`provider:plone.footerportlets` to render the footer portlets.
Since this tal expression was inside a viewlet,
the view is no longer IManageContextualPortletsView when
visiting @@manage-portlets. Instead, it was IViewlet.
See zope.contentprovider
Expand All @@ -485,6 +487,8 @@ def render_footer_portlets(self):
See zope.contentprovider
"""
portlet_manager = getMultiAdapter(
(self.context, self.request, self.__parent__), name='plone.footerportlets')
(self.context, self.request, self.__parent__),
name='plone.footerportlets'
)
portlet_manager.update()
return portlet_manager.render()
Loading

0 comments on commit 34d7d07

Please sign in to comment.