Commit bc17e3e4 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added parent virtual category SQL support


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2428 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5a66801f
......@@ -293,7 +293,9 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
def _aq_dynamic(self, id):
global aq_portal_type
ptype = self.portal_type
#LOG("In _aq_dynamic", 0, str((id, ptype, self)))
# If this is a portal_type property and everything is already defined
# for that portal_type, try to return a value ASAP
if aq_portal_type.has_key(ptype):
......@@ -897,6 +899,13 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
"""
return self
security.declareProtected( Permissions.AccessContentsInformation, 'asParentSqlExpression' )
def getParentSqlExpression(self, table = 'catalog', strict_membership = 0):
"""
Builds an SQL expression to search children and subclidren
"""
return "%s.parent_uid = %s" % (table, self.getUid())
security.declareProtected( Permissions.AccessContentsInformation, 'getParentUid' )
def getParentUid(self):
"""
......
......@@ -138,7 +138,20 @@ class FolderMixIn(ExtensionClass.Base):
the portal_catalog.
"""
if not kw.has_key('parent_uid'): #WHY ????
kw['parent_uid'] = self.uid
kw['parent_uid'] = self.getUid()
# Make sure that if we use parent base category
# We do not have conflicting parent uid values
delete_parent_uid = 0
if kw.has_key('selection_domain'):
if kw['selection_domain'].asDomainDict().has_key('parent'):
delete_parent_uid = 1
if kw.has_key('selection_report'):
if kw['selection_report'].asDomainDict().has_key('parent'):
delete_parent_uid = 1
if delete_parent_uid:
del kw['parent_uid']
kw2 = {}
# Remove useless matter before calling the
# catalog. In particular, consider empty
......@@ -151,6 +164,40 @@ class FolderMixIn(ExtensionClass.Base):
method = self.portal_catalog.portal_catalog
return method(**kw2)
security.declareProtected(Permissions.View, 'countFolder')
def countFolder(self, **kw):
"""
Search the content of a folder by calling
the portal_catalog.
"""
if not kw.has_key('parent_uid'): #WHY ????
kw['parent_uid'] = self.getUid()
# Make sure that if we use parent base category
# We do not have conflicting parent uid values
delete_parent_uid = 0
if kw.has_key('selection_domain'):
if kw['selection_domain'].asDomainDict().has_key('parent'):
delete_parent_uid = 1
if kw.has_key('selection_report'):
if kw['selection_report'].asDomainDict().has_key('parent'):
delete_parent_uid = 1
if delete_parent_uid:
del kw['parent_uid']
kw2 = {}
# Remove useless matter before calling the
# catalog. In particular, consider empty
# strings as None values
for cname in kw.keys():
if kw[cname] != '' and kw[cname]!=None:
kw2[cname] = kw[cname]
# The method to call to search the folder
# content has to be called z_search_folder
method = self.portal_catalog.countResults
return method(**kw2)
# Count objects in the folder
security.declarePrivate('_count')
def _count(self, **kw):
......@@ -160,7 +207,7 @@ class FolderMixIn(ExtensionClass.Base):
# PERFORMANCE PROBLEM
# This should be improved in order to use
# SQL counting
return len(self.searchFolder(**kw))
return self.countFolder(**kw)[0][0]
class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
......@@ -598,4 +645,19 @@ be a problem)."""
# Aliases
getObjectIds = CMFBTreeFolder.objectIds
# Overloading
security.declareProtected( Permissions.AccessContentsInformation, 'asParentSqlExpression' )
def getParentSqlExpression(self, table = 'catalog', strict_membership = 0):
"""
Builds an SQL expression to search children and subclidren
"""
if strict_membership:
return Base.getParentSqlExpression(self, table=table, strict_membership=strict_membership)
result = "%s.parent_uid = %s" % (table, self.getUid())
for o in self.objectValues():
if hasattr(aq_base(o), 'objectValues'):
# Do not consider non folder objects
result = "%s OR %s" % (result, o.getParentSqlExpression(table=table, strict_membership=strict_membership))
return "( %s )" % result
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