Commit 5e0d8861 authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Inherit BaseTool class to include CatalogTool inside ERP5

Some changes :
1. Add title for catalog tool and filter meta_types only for CatalogTool object
2. Solve the conflicts due to change in inheritence.

Also, update in BusinessTemplate installation with changes in portal_catalog
parent a106094e
...@@ -1311,9 +1311,12 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1311,9 +1311,12 @@ class ObjectTemplateItem(BaseTemplateItem):
# The id match, but better double check with the meta type # The id match, but better double check with the meta type
# while avoiding the impact of systematic check # while avoiding the impact of systematic check
container_container = portal.unrestrictedTraverse(container_path[:-1]) container_container = portal.unrestrictedTraverse(container_path[:-1])
if container_container.meta_type == 'ERP5 Catalog': if container_container.meta_type == 'Catalog Tool':
container_container.manage_addProduct['ZSQLCatalog'].manage_addSQLCatalog(id=container_path[-1], title='') container_container.manage_addProduct['ZSQLCatalog'].manage_addSQLCatalog(id=container_path[-1], title='')
if len(container_container.objectIds()) == 1: # We will have more than 1 objects in portal_catalog as we are
# adding both ERP5Catalog as well as SQLCatalog object here.
# Later on, this should be changed to use only ERP5Catalog object
if len(container_container.objectIds()) >= 1:
container_container.default_sql_catalog_id = container_path[-1] container_container.default_sql_catalog_id = container_path[-1]
container = portal.unrestrictedTraverse(container_path) container = portal.unrestrictedTraverse(container_path)
else: else:
...@@ -1609,7 +1612,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1609,7 +1612,7 @@ class ObjectTemplateItem(BaseTemplateItem):
container.getSkinSelections()) container.getSkinSelections())
container.manage_delObjects([object_id]) container.manage_delObjects([object_id])
if container.aq_parent.meta_type == 'ERP5 Catalog' and not len(container): if container.aq_parent.meta_type == 'Catalog Tool' and not len(container):
# We are removing a ZSQLMethod, remove the SQLCatalog if empty # We are removing a ZSQLMethod, remove the SQLCatalog if empty
container.getParentValue().manage_delObjects([container.id]) container.getParentValue().manage_delObjects([container.id])
except (NotFound, KeyError, BadRequest, AttributeError): except (NotFound, KeyError, BadRequest, AttributeError):
......
...@@ -42,6 +42,9 @@ from Acquisition import aq_base, aq_inner, aq_parent, ImplicitAcquisitionWrapper ...@@ -42,6 +42,9 @@ from Acquisition import aq_base, aq_inner, aq_parent, ImplicitAcquisitionWrapper
from Products.CMFActivity.ActiveObject import ActiveObject from Products.CMFActivity.ActiveObject import ActiveObject
from Products.CMFActivity.ActivityTool import GroupedMessage from Products.CMFActivity.ActivityTool import GroupedMessage
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import PropertySheet
from AccessControl.PermissionRole import rolesForPermissionOn from AccessControl.PermissionRole import rolesForPermissionOn
...@@ -302,31 +305,105 @@ class RelatedBaseCategory(Method): ...@@ -302,31 +305,105 @@ class RelatedBaseCategory(Method):
'RELATED_QUERY_SEPARATOR': RELATED_QUERY_SEPARATOR, 'RELATED_QUERY_SEPARATOR': RELATED_QUERY_SEPARATOR,
} }
class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): class CatalogTool (BaseTool, ZCatalog, CMFCoreCatalogTool):
""" """
This is a ZSQLCatalog that filters catalog queries. This is a ZSQLCatalog that filters catalog queries.
It is based on ZSQLCatalog It is based on ZSQLCatalog
""" """
id = 'portal_catalog' id = 'portal_catalog'
meta_type = 'ERP5 Catalog' title = 'Catalog Tool'
meta_type = 'Catalog Tool'
portal_type = 'Catalog Tool'
allowed_types = ('Catalog',)
# Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
default_result_limit = None default_result_limit = None
default_count_limit = 1 default_count_limit = 1
manage_options = ({ 'label' : 'Overview', 'action' : 'manage_overview' }, # Use all manage tab options from Folder except the one with label 'View',
) + ZCatalog.manage_options # cause we would be forcing view to display absolute_url+'/view', as
# portal_catalog is a callable object
folder_manage_option = tuple([l for l in Folder.manage_options if \
not l['label']=='View'])
manage_options = ({ 'label' : 'View', 'action' : 'view'},
{ 'label' : 'Overview', 'action' : 'manage_overview' },
{ 'label' : 'Catalog', 'action' : 'manage_catalogView'},
) + folder_manage_option
property_sheets = ( PropertySheet.Base
, PropertySheet.SimpleItem
, PropertySheet.Folder
, PropertySheet.CategoryCore
, PropertySheet.CatalogTool
)
def __init__(self): # Use reindexObject method from BaseTool class and declare it public
ZCatalog.__init__(self, self.getId()) reindexObject = BaseTool.reindexObject
security.declarePublic('reindexObject')
# Explicit Inheritance # Explicit Inheritance
__url = CMFCoreCatalogTool.__url __url = CMFCoreCatalogTool.__url
manage_catalogFind = CMFCoreCatalogTool.manage_catalogFind manage_catalogFind = CMFCoreCatalogTool.manage_catalogFind
security.declareProtected(Permissions.ManagePortal security.declareProtected(Permissions.ManagePortal
, 'manage_schema') , 'manage_overview')
manage_schema = DTMLFile('dtml/manageSchema', globals()) manage_overview = DTMLFile('dtml/explainCatalogTool', globals())
# IMPORTANT:Solve inheritance conflict, this is necessary as getObject from
# Base gives the current object, which migth be harmful for CatalogTool as
# we use this function here to sometimes get objects to delete which if
# not solved of inheritance conflict might lead to catalog deletion.
getObject = ZCatalog.getObject
default_erp5_catalog_id = None
def __init__(self):
ZCatalog.__init__(self, self.getId())
BaseTool.__init__(self, self.getId())
# Filter content (ZMI))
def filtered_meta_types(self, user=None):
# Filters the list of available meta types for CatalogTool
meta_types = []
for meta_type in CatalogTool.inheritedAttribute('filtered_meta_types')(self):
if meta_type['name'] in self.allowed_types:
meta_types.append(meta_type)
return meta_types
allowedContentTypes = BaseTool.allowedContentTypes
getVisibleAllowedContentTypeList = BaseTool.getVisibleAllowedContentTypeList
# The functions 'getERP5CatalogIdList' and 'getERP5Catalog' are meant to
# be used in restricted environment, cause the reason they were created is
# the transition of Catalog from SQLCatalog to ERP5Catalog, which basically
# means Catalog is going to be an ERP5 object, which is why we need these
# functions to be declared public.
security.declarePublic('getERP5CatalogIdList')
def getERP5CatalogIdList(self):
"""
Get ERP5 Catalog Ids
"""
return self.objectIds(spec=('ERP5 Catalog',))
security.declarePublic('getERP5Catalog')
def getERP5Catalog(self, id=None, default_value=None):
"""
Get current ERP5 Catalog
"""
if id is None:
if not self.default_erp5_catalog_id:
id_list = self.getERP5CatalogIdList()
if len(id_list) > 0:
self.default_erp5_catalog_id = id_list[0]
else:
return default_value
id = self.default_erp5_catalog_id
return self._getOb(id, default_value)
security.declarePublic('getPreferredSQLCatalogId') security.declarePublic('getPreferredSQLCatalogId')
def getPreferredSQLCatalogId(self, id=None): def getPreferredSQLCatalogId(self, id=None):
......
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