Skip to content

Commit

Permalink
chore: black
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 15, 2023
1 parent 4aaab78 commit 1431f69
Show file tree
Hide file tree
Showing 18 changed files with 631 additions and 644 deletions.
53 changes: 26 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from setuptools import setup


version = '3.1.1.dev0'
version = "3.1.1.dev0"

setup(
name='plone.folder',
name="plone.folder",
version=version,
description='BTree-based folder implementation with order support',
long_description=(open("README.rst").read() + "\n" +
open("CHANGES.rst").read()),
description="BTree-based folder implementation with order support",
long_description=(open("README.rst").read() + "\n" + open("CHANGES.rst").read()),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
Expand All @@ -29,33 +28,33 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
keywords='folder btree order',
author='Plone Foundation',
author_email='plone-developers@lists.sourceforge.net',
url='https://pypi.org/project/plone.folder',
license='GPL version 2',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['plone'],
keywords="folder btree order",
author="Plone Foundation",
author_email="plone-developers@lists.sourceforge.net",
url="https://pypi.org/project/plone.folder",
license="GPL version 2",
packages=find_packages("src"),
package_dir={"": "src"},
namespace_packages=["plone"],
include_package_data=True,
platforms='Any',
platforms="Any",
zip_safe=False,
install_requires=[
'plone.memoize',
'Products.BTreeFolder2',
'Products.CMFCore',
'Products.ZCatalog',
'setuptools',
'six',
'zope.annotation',
'zope.component',
'zope.container',
'zope.interface',
'Zope2',
"plone.memoize",
"Products.BTreeFolder2",
"Products.CMFCore",
"Products.ZCatalog",
"setuptools",
"six",
"zope.annotation",
"zope.component",
"zope.container",
"zope.interface",
"Zope2",
],
extras_require={
'test': [
'profilehooks',
"test": [
"profilehooks",
]
},
)
2 changes: 1 addition & 1 deletion src/plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
53 changes: 24 additions & 29 deletions src/plone/folder/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
@implementer(IExplicitOrdering)
@adapter(IOrderableFolder)
class DefaultOrdering:
""" This implementation uses annotations to store the order on the
object, and supports explicit ordering. """
"""This implementation uses annotations to store the order on the
object, and supports explicit ordering."""

ORDER_KEY = "plone.folder.ordered.order"
POS_KEY = "plone.folder.ordered.pos"
Expand All @@ -23,14 +23,14 @@ def __init__(self, context):
self.context = context

def notifyAdded(self, obj_id):
""" see interfaces.py """
"""see interfaces.py"""
order = self._order(True)
pos = self._pos(True)
order.append(obj_id)
pos[obj_id] = len(order) - 1

def notifyRemoved(self, obj_id):
""" see interfaces.py """
"""see interfaces.py"""
order = self._order()
pos = self._pos()
try:
Expand All @@ -43,14 +43,8 @@ def notifyRemoved(self, obj_id):
for count, obj_id in enumerate(order):
pos[obj_id] = count

def moveObjectsByDelta(
self,
ids,
delta,
subset_ids=None,
suppress_events=False
):
""" see interfaces.py """
def moveObjectsByDelta(self, ids, delta, subset_ids=None, suppress_events=False):
"""see interfaces.py"""
order = self._order()
pos = self._pos()
min_position = 0
Expand All @@ -60,7 +54,7 @@ def moveObjectsByDelta(
subset_ids = self.idsInOrder()
elif not isinstance(subset_ids, list):
subset_ids = list(subset_ids)
if delta > 0: # unify moving direction
if delta > 0: # unify moving direction
ids = reversed(ids)
subset_ids.reverse()
counter = 0
Expand Down Expand Up @@ -93,41 +87,37 @@ def moveObjectsByDelta(
pos[obj_id] = i
idx += 1
except KeyError:
raise ValueError(
f'No object with id "{obj_id:s}" exists.'
)
raise ValueError(f'No object with id "{obj_id:s}" exists.')
if not suppress_events:
notifyContainerModified(self.context)
return counter

def moveObjectsUp(self, ids, delta=1, subset_ids=None):
""" see interfaces.py """
"""see interfaces.py"""
return self.moveObjectsByDelta(ids, -delta, subset_ids)

def moveObjectsDown(self, ids, delta=1, subset_ids=None):
""" see interfaces.py """
"""see interfaces.py"""
return self.moveObjectsByDelta(ids, delta, subset_ids)

def moveObjectsToTop(self, ids, subset_ids=None):
""" see interfaces.py """
"""see interfaces.py"""
return self.moveObjectsByDelta(ids, -len(self._order()), subset_ids)

def moveObjectsToBottom(self, ids, subset_ids=None):
""" see interfaces.py """
"""see interfaces.py"""
return self.moveObjectsByDelta(ids, len(self._order()), subset_ids)

def moveObjectToPosition(self, obj_id, position, suppress_events=False):
""" see interfaces.py """
"""see interfaces.py"""
delta = position - self.getObjectPosition(obj_id)
if delta:
return self.moveObjectsByDelta(
obj_id,
delta,
suppress_events=suppress_events
obj_id, delta, suppress_events=suppress_events
)

def orderObjects(self, key=None, reverse=None):
""" see interfaces.py """
"""see interfaces.py"""
if key is None and not reverse:
return -1
order = self._order()
Expand All @@ -137,11 +127,13 @@ def orderObjects(self, key=None, reverse=None):
# Simply reverse the current ordering.
order.reverse()
else:

def keyfn(obj_id):
attr = getattr(self.context._getOb(obj_id), key)
if callable(attr):
return attr()
return attr

# order.sort(cmd=None, key=keyfn, reverse=bool(reverse))
order = sorted(order, key=keyfn, reverse=bool(reverse))
self._set_order(order)
Expand All @@ -150,15 +142,18 @@ def keyfn(obj_id):
return -1

def getObjectPosition(self, obj_id):
""" see interfaces.py """
"""see interfaces.py"""
pos = self._pos()
if obj_id in pos:
return pos[obj_id]
raise ValueError('No object with id "{:s}" exists in "{:s}".'.format(
obj_id, '/'.join(self.context.getPhysicalPath())))
raise ValueError(
'No object with id "{:s}" exists in "{:s}".'.format(
obj_id, "/".join(self.context.getPhysicalPath())
)
)

def idsInOrder(self):
""" see interfaces.py """
"""see interfaces.py"""
return list(self._order())

def __getitem__(self, index):
Expand Down
62 changes: 31 additions & 31 deletions src/plone/folder/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,73 @@


class IOrderable(Interface):
""" Marker interface for orderable portal content """
"""Marker interface for orderable portal content"""


class IFolder(Interface):
""" Marker interface for Plone-like folders """
"""Marker interface for Plone-like folders"""


class IOrderableFolder(IFolder):
""" A Plone-like folder with ordering support """
"""A Plone-like folder with ordering support"""

def getOrdering():
""" return the currently active ordering adapter for this folder """
"""return the currently active ordering adapter for this folder"""

def setOrdering(ordering=''):
""" (re)set ordering adapter to be used for this folder """
def setOrdering(ordering=""):
"""(re)set ordering adapter to be used for this folder"""


class IOrdering(Interface):
""" An adapter providing ordering operations on its context folder.
"""An adapter providing ordering operations on its context folder.
The OrderedBTreeFolderBase mix-in class will adapt self (the
folder) to this interface when trying to get object position or
find the order of items. There is a default implementation, but
you can provide a different policy.
The OrderedBTreeFolderBase mix-in class will adapt self (the
folder) to this interface when trying to get object position or
find the order of items. There is a default implementation, but
you can provide a different policy.
Your adapter (which should still adapt to IOrdered) can
optionally provide IExplicitOrdering, defined below. This is
used to support explicit ordering, e.g. through a UI. """
Your adapter (which should still adapt to IOrdered) can
optionally provide IExplicitOrdering, defined below. This is
used to support explicit ordering, e.g. through a UI."""

def notifyAdded(obj_id):
""" Inform the ordering implementation that an item was added """
"""Inform the ordering implementation that an item was added"""

def notifyRemoved(obj_id):
""" Inform the ordering implementation that an item was removed """
"""Inform the ordering implementation that an item was removed"""

def getObjectPosition(obj_id):
""" Get the position of the given object id """
"""Get the position of the given object id"""

def idsInOrder():
""" Return all object ids, in the correct order """
"""Return all object ids, in the correct order"""


class IExplicitOrdering(IOrdering):
""" An adapter allowing explicit ordering """
"""An adapter allowing explicit ordering"""

def moveObjectsByDelta(ids, delta, subset_ids=None, suppress_events=False):
""" Move the specified ids (a sequence, or a single string id)
by the given delta (a positive or negative number). By
default, this moves the objects within the whole set of
sub-items in the context container, but if subset_ids is
specified, it gives a subset of ids to consider.
Should return the number of objects that changed position. """
"""Move the specified ids (a sequence, or a single string id)
by the given delta (a positive or negative number). By
default, this moves the objects within the whole set of
sub-items in the context container, but if subset_ids is
specified, it gives a subset of ids to consider.
Should return the number of objects that changed position."""

def moveObjectsUp(ids, delta=1, subset_ids=None):
""" Move specified sub-objects up by delta in container. """
"""Move specified sub-objects up by delta in container."""

def moveObjectsDown(ids, delta=1, subset_ids=None):
""" Move specified sub-objects down by delta in container. """
"""Move specified sub-objects down by delta in container."""

def moveObjectsToTop(ids, subset_ids=None):
""" Move specified sub-objects to top of container. """
"""Move specified sub-objects to top of container."""

def moveObjectsToBottom(ids, subset_ids=None):
""" Move specified sub-objects to bottom of container. """
"""Move specified sub-objects to bottom of container."""

def moveObjectToPosition(obj_id, position, suppress_events=False):
""" Move specified object to absolute position. """
"""Move specified object to absolute position."""

def orderObjects(key, reverse=None):
""" Order sub-objects by key and direction. """
"""Order sub-objects by key and direction."""
Loading

0 comments on commit 1431f69

Please sign in to comment.