Commit 4b25512d authored by Vincent Pelletier's avatar Vincent Pelletier

CategoryTool: Become a BaseTool subclass.

Allows having a more consistent API between this tool and all other
Nexedi-maintained tools.
parent c3de53b8
...@@ -33,14 +33,13 @@ ERP portal_categories tool. ...@@ -33,14 +33,13 @@ ERP portal_categories tool.
from collections import deque from collections import deque
import re import re
from BTrees.OOBTree import OOTreeSet from BTrees.OOBTree import OOTreeSet
from OFS.Folder import Folder
from Products.CMFCore.utils import UniqueObject
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl import Unauthorized, getSecurityManager from AccessControl import Unauthorized, getSecurityManager
from Acquisition import aq_base, aq_inner from Acquisition import aq_base, aq_inner
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Base import Base from Products.ERP5Type.Core.Folder import OFS_HANDLER
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type.Cache import getReadOnlyTransactionCache from Products.ERP5Type.Cache import getReadOnlyTransactionCache
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.CMFCategory import _dtmldir from Products.CMFCategory import _dtmldir
...@@ -83,7 +82,7 @@ class RelatedIndex(): # persistent.Persistent can be added ...@@ -83,7 +82,7 @@ class RelatedIndex(): # persistent.Persistent can be added
pass pass
class CategoryTool( UniqueObject, Folder, Base ): class CategoryTool(BaseTool):
""" """
The CategoryTool object is the placeholder for all methods The CategoryTool object is the placeholder for all methods
and algorithms related to categories and relations in CMF. and algorithms related to categories and relations in CMF.
...@@ -130,30 +129,16 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -130,30 +129,16 @@ class CategoryTool( UniqueObject, Folder, Base ):
portal_type = 'Category Tool' portal_type = 'Category Tool'
allowed_types = ( 'CMF Base Category', ) allowed_types = ( 'CMF Base Category', )
_folder_handler = OFS_HANDLER # BBB
# Declarative Security # Declarative Security
security = ClassSecurityInfo() security = ClassSecurityInfo()
#
# ZMI methods
#
manage_options = ( ( { 'label' : 'Overview'
, 'action' : 'manage_overview'
}
,
)
+ Folder.manage_options
)
security.declareProtected( Permissions.ManagePortal security.declareProtected( Permissions.ManagePortal
, 'manage_overview' ) , 'manage_overview' )
manage_overview = DTMLFile( 'explainCategoryTool', _dtmldir ) manage_overview = DTMLFile( 'explainCategoryTool', _dtmldir )
# Multiple inheritance inconsistency caused by Base must be circumvented
def __init__( self, *args, **kwargs ):
Base.__init__(self, self.id, **kwargs)
# Filter content (ZMI)) # Filter content (ZMI))
def filtered_meta_types(self, user=None): def filtered_meta_types(self, user=None):
# Filters the list of available meta types. # Filters the list of available meta types.
...@@ -196,10 +181,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -196,10 +181,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
result = self.objectIds() result = self.objectIds()
else: else:
# XXX Incompatible with ERP5Type per portal type categories # XXX Incompatible with ERP5Type per portal type categories
result = list(context._categories[:]) result = context._categories
if sort: return (sorted if sort else list)(result)
result.sort()
return result
security.declareProtected(Permissions.AccessContentsInformation, 'getBaseCategoryIds') security.declareProtected(Permissions.AccessContentsInformation, 'getBaseCategoryIds')
getBaseCategoryIds = getBaseCategoryList getBaseCategoryIds = getBaseCategoryList
...@@ -1729,12 +1712,6 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1729,12 +1712,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
return obj return obj
# Use Base class's methods for properties instead of patched PropertyManager's
_propertyMap = Base._propertyMap
_setProperty = Base._setProperty
getProperty = Base.getProperty
hasProperty = Base.hasProperty
def _removeDuplicateBaseCategoryIdInCategoryPath(self, base_category_id, def _removeDuplicateBaseCategoryIdInCategoryPath(self, base_category_id,
path): path):
"""Specific Handling to remove duplicated base_categories in path """Specific Handling to remove duplicated base_categories in path
......
...@@ -146,7 +146,7 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject): ...@@ -146,7 +146,7 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject):
portal): portal):
try: try:
cat_object = portal.portal_categories._getOb(category_id) cat_object = portal.portal_categories._getOb(category_id)
except AttributeError: except KeyError:
if portal.hasObject('portal_categories'): if portal.hasObject('portal_categories'):
LOG("ERP5Type.Core.CategoryProperty", WARNING, LOG("ERP5Type.Core.CategoryProperty", WARNING,
"Base Category %r is missing. Accessors can not be generated." % \ "Base Category %r is missing. Accessors can not be generated." % \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment