Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Apr 30, 2022
1 parent f1ea3bc commit 82c55fc
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 200 deletions.
2 changes: 1 addition & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
2 changes: 1 addition & 1 deletion plone/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
22 changes: 10 additions & 12 deletions plone/app/contentlisting/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,38 @@


class FolderListing(BrowserView):

def __call__(self, batch=False, b_size=20, b_start=0, orphan=0, **kw):
query = {}
query.update(kw)

query['path'] = {
'query': '/'.join(self.context.getPhysicalPath()),
'depth': 1,
query["path"] = {
"query": "/".join(self.context.getPhysicalPath()),
"depth": 1,
}

# if we don't have asked explicitly for other sorting, we'll want
# it by position in parent
if 'sort_on' not in query:
query['sort_on'] = 'getObjPositionInParent'
if "sort_on" not in query:
query["sort_on"] = "getObjPositionInParent"

# Provide batching hints to the catalog
if batch:
query['b_start'] = b_start
query['b_size'] = b_size + orphan
query["b_start"] = b_start
query["b_size"] = b_size + orphan

catalog = getToolByName(self.context, 'portal_catalog')
catalog = getToolByName(self.context, "portal_catalog")
results = catalog(query)
return IContentListing(results)


class ContentListingCollection(BrowserView):

def __call__(self, batch=False, b_size=20, b_start=0, **kw):

if 'orphan' in kw:
if "orphan" in kw:
# At the moment, orphan keyword is not supported by
# plone.app.contenttypes Collection behavior, nor by
# plone.app.querystring's querybuilder.
del kw['orphan']
del kw["orphan"]

res = self.context.results(
batch=batch,
Expand Down
34 changes: 18 additions & 16 deletions plone/app/contentlisting/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def __init__(self, brain):
self.request = getRequest()

def __repr__(self):
return '<plone.app.contentlisting.catalog.'\
'CatalogContentListingObject instance at {0}>'.format(
return (
"<plone.app.contentlisting.catalog."
"CatalogContentListingObject instance at {0}>".format(
self.getPath(),
)
)

__str__ = __repr__

Expand All @@ -40,7 +42,7 @@ def __getattr__(self, name):
underlying objects without knowing the names of all attributes.
"""

if name.startswith('_'):
if name.startswith("_"):
raise AttributeError(name)
brain_name = getattr(aq_base(self._brain), name, missing)
if brain_name is not missing:
Expand Down Expand Up @@ -82,7 +84,7 @@ def getURL(self, relative=False):

def uuid(self):
# content objects might have UID and might not.
brain_uid = getattr(aq_base(self._brain), 'UID', None)
brain_uid = getattr(aq_base(self._brain), "UID", None)
if brain_uid is not None:
return self._brain.UID
uuid = IUUID(self.getObject(), None)
Expand All @@ -106,8 +108,8 @@ def Description(self):

def CroppedDescription(self):
registry = queryUtility(IRegistry)
length = registry.get('plone.search_results_description_length')
plone_view = getMultiAdapter((self, self.request), name='plone')
length = registry.get("plone.search_results_description_length")
plone_view = getMultiAdapter((self, self.request), name="plone")
return plone_view.cropText(self.Description(), length)

def Type(self):
Expand All @@ -120,22 +122,22 @@ def listCreators(self):
return self._brain.listCreators

def getUserData(self, username):
_usercache = self.request.get('usercache', None)
_usercache = self.request.get("usercache", None)
if _usercache is None:
self.request.set('usercache', {})
self.request.set("usercache", {})
_usercache = {}
userdata = _usercache.get(username, None)
if userdata is None:
membershiptool = getToolByName(self._brain, 'portal_membership')
membershiptool = getToolByName(self._brain, "portal_membership")
userdata = membershiptool.getMemberInfo(self._brain.Creator)
if not userdata:
userdata = {
'username': username,
'description': '',
'language': '',
'home_page': '/HOMEPAGEURL',
'location': '',
'fullname': username,
"username": username,
"description": "",
"language": "",
"home_page": "/HOMEPAGEURL",
"location": "",
"fullname": username,
}
self.request.usercache[username] = userdata
return userdata
Expand Down Expand Up @@ -182,7 +184,7 @@ def Identifier(self):

def Language(self):
# The language of the content.
brain_language = getattr(aq_base(self._brain), 'Language', None)
brain_language = getattr(aq_base(self._brain), "Language", None)
if brain_language is not None:
return self._brain.Language
else:
Expand Down
32 changes: 16 additions & 16 deletions plone/app/contentlisting/contentlisting.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def __init__(self, sequence):
self._basesequence = sequence

def __getitem__(self, index):
"""`x.__getitem__(index)` <==> `x[index]`
"""
"""`x.__getitem__(index)` <==> `x[index]`"""
if isinstance(index, slice):
return IContentListing(
self._basesequence[index.start:index.stop:index.step])
self._basesequence[index.start : index.stop : index.step]
)
return IContentListingObject(self._basesequence[index])

def __len__(self):
Expand All @@ -40,7 +40,7 @@ def __len__(self):
@property
def actual_result_count(self):
bs = self._basesequence
return getattr(bs, 'actual_result_count', len(bs))
return getattr(bs, "actual_result_count", len(bs))

def __iter__(self):
"""Let the sequence be iterable and whenever we look at an object, it
Expand Down Expand Up @@ -123,39 +123,39 @@ def __hash__(self):
def ContentTypeClass(self):
# A normalised type name that identifies the object in listings.
# Used for CSS styling.
return 'contenttype-' + queryUtility(IIDNormalizer).normalize(
return "contenttype-" + queryUtility(IIDNormalizer).normalize(
self.PortalType(),
)

def ReviewStateClass(self):
# A normalised review state string for CSS styling use in listings.
return 'state-' + queryUtility(IIDNormalizer).normalize(
return "state-" + queryUtility(IIDNormalizer).normalize(
self.review_state(),
)

def appendViewAction(self):
# Decide whether to produce a string /view to append to links in
# results listings.
registry = getUtility(IRegistry)
types = registry.get('plone.types_use_view_action_in_listings', [])
types = registry.get("plone.types_use_view_action_in_listings", [])
if self.portal_type in types:
return '/view'
return ''
return "/view"
return ""

def isVisibleInNav(self):
# True, if this item should be visible in navigation trees.
exclude_from_nav_attr = getattr(self, 'exclude_from_nav', None)
exclude_from_nav_attr = getattr(self, "exclude_from_nav", None)
if exclude_from_nav_attr is not None and (
self.exclude_from_nav()
if callable(self.exclude_from_nav)
else self.exclude_from_nav
self.exclude_from_nav()
if callable(self.exclude_from_nav)
else self.exclude_from_nav
):
return False

registry = getUtility(IRegistry)
navigation_settings = registry.forInterface(
INavigationSchema,
prefix='plone',
prefix="plone",
)
if self.portal_type not in navigation_settings.displayed_types:
return False
Expand All @@ -166,12 +166,12 @@ def MimeTypeIcon(self):
mimeicon = None
navroot = getNavigationRoot(self._brain)
contenttype = aq_base(
getattr(self._brain, 'mime_type', None),
getattr(self._brain, "mime_type", None),
)
if contenttype:
mtt = getToolByName(
self._brain,
'mimetypes_registry',
"mimetypes_registry",
)
ctype = mtt.lookup(contenttype)
if ctype:
Expand Down
2 changes: 1 addition & 1 deletion plone/app/contentlisting/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ def ContentTypeClass():
"""

def MimeTypeIcon():
""" return mimetype icon from mimetype registry if contenttype is
"""return mimetype icon from mimetype registry if contenttype is
File else None
"""
31 changes: 16 additions & 15 deletions plone/app/contentlisting/realobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@

@implementer(IContentListingObject)
class RealContentListingObject(BaseContentListingObject):
"""A content object representation wrapping a real content object.
"""
"""A content object representation wrapping a real content object."""

def __init__(self, obj):
self._realobject = obj
self.request = aq_get(obj, 'REQUEST')
self.request = aq_get(obj, "REQUEST")

def __repr__(self):
return '<plone.app.contentlisting.realobject.'\
'RealContentListingObject instance at {0}>'.format(
return (
"<plone.app.contentlisting.realobject."
"RealContentListingObject instance at {0}>".format(
self.getPath(),
)
)

__str__ = __repr__

Expand All @@ -35,7 +36,7 @@ def __getattr__(self, name):
the real underlying objects without knowing the names of all
attributes.
"""
if name.startswith('_'):
if name.startswith("_"):
raise AttributeError(name)
obj = self.getObject()
obj_name = getattr(aq_base(obj), name, MARKER)
Expand All @@ -55,7 +56,7 @@ def getDataOrigin(self):

# a base set of elements that are needed but not defined in dublin core
def getPath(self):
return '/'.join(self.getObject().getPhysicalPath())
return "/".join(self.getObject().getPhysicalPath())

def getURL(self):
return self.getObject().absolute_url()
Expand All @@ -81,27 +82,27 @@ def getSize(self):
if primary_field_info is None or not primary_field_info.value:
size = 0
else:
size = getattr(primary_field_info.value, 'size', 0)
size = getattr(primary_field_info.value, "size", 0)
return human_readable_size(size)

def review_state(self):
obj = self.getObject()
wftool = getToolByName(obj, 'portal_workflow')
return wftool.getInfoFor(obj, 'review_state', default=None)
wftool = getToolByName(obj, "portal_workflow")
return wftool.getInfoFor(obj, "review_state", default=None)

def Type(self):
# Dublin Core element - Object type.
obj = self.getObject()
typestool = getToolByName(obj, 'portal_types')
typestool = getToolByName(obj, "portal_types")
ti = typestool.getTypeInfo(obj)
if ti is not None:
return ti.Title()
return obj.meta_type

# Needed: A method Type() that returns the same as is cataloged as Type.
# Currently Type() returns different values depending on the data source being
# a brain or a real object. Probably needed. Support for all the attributes
# from the indexablemetadata wrappers.
# Needed: A method Type() that returns the same as is cataloged as Type.
# Currently Type() returns different values depending on the data source being
# a brain or a real object. Probably needed. Support for all the attributes
# from the indexablemetadata wrappers.

def PortalType(self):
obj = self.getObject()
Expand Down
35 changes: 19 additions & 16 deletions plone/app/contentlisting/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

class ContentListingLayer(PloneSandboxLayer):

defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE, )
defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

def setUpZope(self, app, configurationContext):
import plone.app.layout

self.loadZCML(package=plone.app.layout)
import plone.app.contentlisting

self.loadZCML(package=plone.app.contentlisting)


Expand All @@ -24,29 +26,30 @@ def setUpZope(self, app, configurationContext):

class ContentListingIntegrationLayer(PloneSandboxLayer):

defaultBases = (CONTENTLISTING_FIXTURE, )
defaultBases = (CONTENTLISTING_FIXTURE,)

def setUpPloneSite(self, portal):
setRoles(portal, TEST_USER_ID, ['Manager'])
wftool = getToolByName(portal, 'portal_workflow')
wftool.setDefaultChain('simple_publication_workflow')

portal.invokeFactory('Folder', 'test-folder')
portal.invokeFactory('Document', 'front-page')
portal.invokeFactory('Folder', 'news')
wftool.doActionFor(portal.news, 'publish')
portal.news.invokeFactory('News Item', 'news1')
setRoles(portal, TEST_USER_ID, ['Member'])
setRoles(portal, TEST_USER_ID, ["Manager"])
wftool = getToolByName(portal, "portal_workflow")
wftool.setDefaultChain("simple_publication_workflow")

portal.invokeFactory("Folder", "test-folder")
portal.invokeFactory("Document", "front-page")
portal.invokeFactory("Folder", "news")
wftool.doActionFor(portal.news, "publish")
portal.news.invokeFactory("News Item", "news1")
setRoles(portal, TEST_USER_ID, ["Member"])
from Products.CMFCore.indexing import processQueue

processQueue()


CONTENTLISTING_INTEGRATION_FIXTURE = ContentListingIntegrationLayer()
CONTENTLISTING_INTEGRATION_TESTING = IntegrationTesting(
bases=(CONTENTLISTING_INTEGRATION_FIXTURE, ),
name='ContentListing:Integration',
bases=(CONTENTLISTING_INTEGRATION_FIXTURE,),
name="ContentListing:Integration",
)
CONTENTLISTING_FUNCTIONAL_TESTING = FunctionalTesting(
bases=(CONTENTLISTING_INTEGRATION_FIXTURE, ),
name='ContentListing:Functional',
bases=(CONTENTLISTING_INTEGRATION_FIXTURE,),
name="ContentListing:Functional",
)
10 changes: 6 additions & 4 deletions plone/app/contentlisting/tests/test_integration_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ def test_suite():
[
layered(
doctest.DocFileSuite(
'tests/integration.rst',
package='plone.app.contentlisting',
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS, # NOQA: E501
"tests/integration.rst",
package="plone.app.contentlisting",
optionflags=doctest.NORMALIZE_WHITESPACE
| doctest.ELLIPSIS, # NOQA: E501
),
layer=CONTENTLISTING_FUNCTIONAL_TESTING,
),
])
]
)
Loading

0 comments on commit 82c55fc

Please sign in to comment.