Skip to content

Commit

Permalink
Merge pull request #89 from plone/readability-cleanup
Browse files Browse the repository at this point in the history
Readability cleanup
  • Loading branch information
rnixx committed Apr 23, 2016
2 parents 0a6716e + 34d7d07 commit ec7c82e
Show file tree
Hide file tree
Showing 60 changed files with 360 additions and 307 deletions.
8 changes: 2 additions & 6 deletions plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
7 changes: 1 addition & 6 deletions plone/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
__import__('pkg_resources').declare_namespace(__name__)
2 changes: 1 addition & 1 deletion plone/app/layout/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
# -*- coding: utf-8 -*-
2 changes: 1 addition & 1 deletion plone/app/layout/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
# -*- coding: utf-8 -*-
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 -*-
1 change: 1 addition & 0 deletions plone/app/layout/analytics/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from plone.app.testing.bbb import PloneTestCase


Expand Down
8 changes: 5 additions & 3 deletions plone/app/layout/analytics/tests/test_doctests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
import doctest
# -*- coding: utf-8 -*-
from plone.app.layout.analytics.tests import base
from Testing import ZopeTestCase as ztc

from plone.app.layout.analytics.tests import base
import doctest
import unittest


OPTIONFLAGS = (doctest.REPORT_ONLY_FIRST_FAILURE |
doctest.ELLIPSIS |
Expand Down
18 changes: 9 additions & 9 deletions plone/app/layout/analytics/view.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from Products.CMFPlone.interfaces import ISiteSchema
# -*- coding: utf-8 -*-
from plone.registry.interfaces import IRegistry

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

from Products.Five.browser import BrowserView


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

def __init__(self, context, request, view, manager):
super(AnalyticsViewlet, self).__init__(context, request)
Expand All @@ -25,10 +24,11 @@ def update(self):
def render(self):
"""render the webstats snippet"""
registry = getUtility(IRegistry)
site_settings = registry.forInterface(ISiteSchema, prefix="plone", check=False)
site_settings = registry.forInterface(
ISiteSchema, prefix="plone", check=False)
try:
if site_settings.webstats_js:
return site_settings.webstats_js
return ''
except AttributeError:
return ''
pass
return ''
2 changes: 1 addition & 1 deletion plone/app/layout/dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
# -*- coding: utf-8 -*-
37 changes: 18 additions & 19 deletions plone/app/layout/dashboard/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
from zope.component import getUtility
from zope import interface

# -*- coding: utf-8 -*-
from AccessControl import getSecurityManager
from Products.Five.browser import BrowserView

from plone.portlets.interfaces import IPortletManager
from plone.portlets.constants import USER_CATEGORY, GROUP_CATEGORY

from plone.memoize.instance import memoize

from plone.portlets.constants import GROUP_CATEGORY
from plone.portlets.constants import USER_CATEGORY
from plone.portlets.interfaces import IPortletManager
from plone.protect.authenticator import createToken
from Products.CMFCore.utils import getToolByName
from Products.statusmessages.interfaces import IStatusMessage
from Products.CMFPlone import PloneMessageFactory as _
from plone.protect.authenticator import createToken
from Products.Five.browser import BrowserView
from Products.statusmessages.interfaces import IStatusMessage
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)
self.request.set('disable_plone.leftcolumn',1)
self.request.set('disable_plone.rightcolumn',1)
self.request.set('disable_border', 1)
self.request.set('disable_plone.leftcolumn', 1)
self.request.set('disable_plone.rightcolumn', 1)
if self.can_edit() and self.empty():
message = _(u"info_empty_dashboard",
default=u"Your dashboard is currently empty. Click the"
" <em>edit</em> tab to assign some personal"
" portlets.")
default=u"Your dashboard is currently empty. Click the"
" <em>edit</em> tab to assign some personal"
" portlets.")
IStatusMessage(self.request).add(message)
return self.index()

Expand Down
7 changes: 5 additions & 2 deletions plone/app/layout/dashboard/user_actions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from Products.Five.browser import BrowserView
from zope.component import getMultiAdapter

Expand All @@ -7,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
1 change: 1 addition & 0 deletions plone/app/layout/globals/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
40 changes: 20 additions & 20 deletions plone/app/layout/globals/context.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
from zope.interface import implements
from zope.component import getMultiAdapter
from zope.component import queryAdapter
from zope.component import queryMultiAdapter
from zope.component import getUtility
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition import aq_parent
from interfaces import IContextState
from plone.memoize.view import memoize

from Acquisition import aq_base, aq_inner, aq_parent
from Products.Five.browser import BrowserView

from Products.CMFCore.interfaces import ISiteRoot, IDynamicType
from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault
from Products.CMFPlone.interfaces import INonStructuralFolder

from plone.portlets.interfaces import ILocalPortletAssignable
from plone.registry.interfaces import IRegistry
from Products.CMFCore.interfaces import IDynamicType
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault
from Products.CMFPlone import utils
from plone.registry.interfaces import IRegistry

from interfaces import IContextState
from Products.CMFPlone.interfaces import INonStructuralFolder
from Products.Five.browser import BrowserView
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component import queryAdapter
from zope.component import queryMultiAdapter
from zope.interface import implementer

from plone.portlets.interfaces import ILocalPortletAssignable

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 Expand Up @@ -73,7 +72,8 @@ def view_url(self):
view_url = self.object_url()
portal_type = getattr(aq_base(self.context), 'portal_type', None)
registry = getUtility(IRegistry)
use_view_action = registry.get('plone.types_use_view_action_in_listings', [])
use_view_action = registry.get(
'plone.types_use_view_action_in_listings', [])
if portal_type in use_view_action:
view_url = view_url + '/view'
return view_url
Expand Down
8 changes: 5 additions & 3 deletions plone/app/layout/globals/interface.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Products.Five.browser import BrowserView
from interfaces import IInterfaceInformation
from plone.memoize.view import memoize
from Products.Five.browser import BrowserView
from zope.dottedname.resolve import resolve
from zope.interface import Interface, implements, providedBy
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 @@ -47,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
36 changes: 19 additions & 17 deletions plone/app/layout/globals/layout.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import json

from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces.controlpanel import ILinkSchema
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
from Products.Five.browser.metaconfigure import ViewMixinForTemplates
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
# -*- coding: utf-8 -*-
from plone.app.layout.globals.interfaces import ILayoutPolicy
from plone.app.layout.globals.interfaces import IViewView
from plone.app.layout.icons.interfaces import IContentIcon
Expand All @@ -13,24 +7,28 @@
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletManagerRenderer
from plone.registry.interfaces import IRegistry
from zope.browserpage.viewpagetemplatefile import (
ViewPageTemplateFile as ZopeViewPageTemplateFile
)
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces.controlpanel import ILinkSchema
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 # 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 Expand Up @@ -88,7 +86,8 @@ def icons_visible(self):
anon = membership.isAnonymousUser()

registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix="plone", check=False)
settings = registry.forInterface(
ISiteSchema, prefix="plone", check=False)
icon_visibility = settings.icon_visibility

if icon_visibility == 'enabled':
Expand All @@ -106,7 +105,8 @@ def thumb_visible(self):
membership = getToolByName(context, "portal_membership")
anon = membership.isAnonymousUser()
registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix="plone", check=False)
settings = registry.forInterface(
ISiteSchema, prefix="plone", check=False)
thumb_visibility = settings.thumb_visibility

if thumb_visibility == 'enabled':
Expand Down Expand Up @@ -223,10 +223,12 @@ def bodyClass(self, template, view):
else:
user = membership.getAuthenticatedMember()
for role in user.getRolesInContext(self.context):
body_classes.append('userrole-' + role.lower().replace(' ', '-'))
body_classes.append(
'userrole-' + role.lower().replace(' ', '-'))

registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix='plone', check=False)
settings = registry.forInterface(
ISiteSchema, prefix='plone', check=False)

# toolbar classes
try:
Expand Down
1 change: 1 addition & 0 deletions plone/app/layout/globals/patterns_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from zope.deferredimport import deprecated


deprecated(
"Import from Products.CMFPlone.patterns.view instead",
PatternSettings='Products.CMFPlone.patterns.view.PatternSettingsView'
Expand Down
31 changes: 15 additions & 16 deletions plone/app/layout/globals/portal.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
from zope.interface import implements
from zope.component import getUtility
from zope.component import providedBy
from zope.component.hooks import getSite
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from interfaces import IPortalState
from plone.app.layout.navigation.root import getNavigationRoot
from plone.app.layout.navigation.root import getNavigationRootObject
from plone.memoize.view import memoize
from plone.memoize.view import memoize_contextless
from plone.registry.interfaces import IRegistry
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFPlone.interfaces import ISiteSchema
from plone.memoize.view import memoize_contextless
from plone.memoize.view import memoize

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import ILanguageSchema
from Products.CMFPlone.interfaces import ISearchSchema
from Products.CMFPlone.interfaces import ISiteSchema
from Products.Five.browser import BrowserView
from zope.component import getUtility
from zope.component import providedBy
from zope.component.hooks import getSite
from zope.interface import implementer

from plone.app.layout.navigation.root import getNavigationRoot
from plone.app.layout.navigation.root import getNavigationRootObject


from interfaces import IPortalState

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 All @@ -40,7 +38,8 @@ def portal(self):
@memoize_contextless
def portal_title(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix="plone", check=False)
settings = registry.forInterface(
ISiteSchema, prefix="plone", check=False)
return settings.site_title

@memoize_contextless
Expand Down
1 change: 1 addition & 0 deletions plone/app/layout/globals/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
Loading

0 comments on commit ec7c82e

Please sign in to comment.