Commit b1853b93 authored by Jérome Perrin's avatar Jérome Perrin

rename keyword strict to strict_membership in category membership generated methods. (Bug #42)

Base_zSearchRelatedObjectsByCategoryList ZSQL Method was modified for this


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3295 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ce68568a
...@@ -360,12 +360,18 @@ class Category(Folder): ...@@ -360,12 +360,18 @@ class Category(Folder):
return '/'.join(self.portal_url.getRelativeContentPath(self)[1:]) return '/'.join(self.portal_url.getRelativeContentPath(self)[1:])
security.declareProtected( Permissions.View, 'isMemberOf' ) security.declareProtected( Permissions.View, 'isMemberOf' )
def isMemberOf(self, category, strict = 0): def isMemberOf(self, category, **kw):
""" """
Tests if an object if member of a given category Tests if an object if member of a given category
Category is a string here. It could be more than a string (ex. an object) Category is a string here. It could be more than a string (ex. an object)
Keywords parameters :
- strict_membership: if we want strict membership checking
- strict : alias for strict_membership (deprecated but still here for
skins backward compatibility. )
""" """
if strict: strict_membership = kw.get('strict_membership', kw.get('strict', 0))
if strict_membership:
if self.getRelativeUrl().find(category) >= 0: if self.getRelativeUrl().find(category) >= 0:
if len(self.getRelativeUrl()) == len(category) + self.getRelativeUrl().find(category): if len(self.getRelativeUrl()) == len(category) + self.getRelativeUrl().find(category):
return 1 return 1
...@@ -376,14 +382,14 @@ class Category(Folder): ...@@ -376,14 +382,14 @@ class Category(Folder):
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' )
def getCategoryMemberValueList(self, base_category = None, def getCategoryMemberValueList(self, base_category = None,
spec=(), filter=None, portal_type=(), strict = 0): spec=(), filter=None, portal_type=(), **kw):
""" """
Returns a list of objects or brains Returns a list of objects or brains
""" """
strict_membership = kw.get('strict_membership', kw.get('strict', 0))
return self.portal_categories.getCategoryMemberValueList(self, return self.portal_categories.getCategoryMemberValueList(self,
base_category = base_category, base_category = base_category,
spec=spec, filter=filter, portal_type=portal_type,strict = strict) spec=spec, filter=filter, portal_type=portal_type, strict_membership=strict_membership)
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' )
def getCategoryMemberItemList(self, **kw): def getCategoryMemberItemList(self, **kw):
......
...@@ -982,20 +982,26 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -982,20 +982,26 @@ class CategoryTool( UniqueObject, Folder, Base ):
return result return result
security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' ) security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' )
def isMemberOf(self, context, category, strict=0): def isMemberOf(self, context, category, **kw):
""" """
Tests if an object if member of a given category Tests if an object if member of a given category
Category is a string here. It could be more than a string (ex. an object) Category is a string here. It could be more than a string (ex. an object)
Keywords parameters :
- strict_membership: if we want strict membership checking
- strict : alias for strict_membership (deprecated but still here for
skins backward compatibility. )
XXX - there should be 2 different methods, one which acuiqred XXX - there should be 2 different methods, one which acuiqred
and the other which does not. A complete review of and the other which does not. A complete review of
the use of isMemberOf is required the use of isMemberOf is required
""" """
strict_membership = kw.get('strict_membership', kw.get('strict', 0))
if getattr(aq_base(context), 'isCategory', 0) : if getattr(aq_base(context), 'isCategory', 0) :
if context.isMemberOf(category, strict=strict) == 1 : if context.isMemberOf(category, strict_membership = strict_membership) == 1 :
return 1 return 1
base_category = category.split('/')[0] # Extract base_category for optimisation base_category = category.split('/')[0] # Extract base_category for optimisation
if strict: if strict_membership:
for c in self.getAcquiredCategoryMembershipList(context, base_category = base_category): for c in self.getAcquiredCategoryMembershipList(context, base_category = base_category):
if c == category: if c == category:
return 1 return 1
...@@ -1170,12 +1176,13 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1170,12 +1176,13 @@ class CategoryTool( UniqueObject, Folder, Base ):
self.updateRelatedContent(o, previous_o_category_url, new_o_category_url) self.updateRelatedContent(o, previous_o_category_url, new_o_category_url)
security.declareProtected( Permissions.AccessContentsInformation, 'getRelatedValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getRelatedValueList' )
def getRelatedValueList(self, context, base_category_list=None, def getRelatedValueList(self, context, base_category_list=None,
spec=(), filter=None, base=1, **kw): spec=(), filter=None, base=1, **kw):
#LOG('getRelatedValueList',0,'base_category_list: %s, filter: %s, kw: %s' % #LOG('getRelatedValueList',0,'base_category_list: %s, filter: %s, kw: %s' %
# (str(base_category_list),str(filter),str(kw))) # (str(base_category_list),str(filter),str(kw)))
strict_membership = kw.get('strict_membership', kw.get('strict', 0))
portal_type = kw.get('portal_type') portal_type = kw.get('portal_type')
if type(portal_type) is type('a'): if type(portal_type) is type('a'):
portal_type = [portal_type] portal_type = [portal_type]
if spec is (): spec = None # We do not want to care about spec if spec is (): spec = None # We do not want to care about spec
...@@ -1188,9 +1195,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1188,9 +1195,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
#LOG('getRelatedValueList',0,'base_category_list: %s' % str(base_category_list)) #LOG('getRelatedValueList',0,'base_category_list: %s' % str(base_category_list))
for base_category in base_category_list: for base_category in base_category_list:
category_list += ["%s/%s" % (base_category, context.getRelativeUrl())] category_list += ["%s/%s" % (base_category, context.getRelativeUrl())]
brain_result = self.Base_zSearchRelatedObjectsByCategoryList(category_list = category_list, brain_result = self.Base_zSearchRelatedObjectsByCategoryList(category_list = category_list,
portal_type = portal_type ) portal_type = portal_type,
strict_membership = strict_membership)
result = [] result = []
for b in brain_result: for b in brain_result:
...@@ -1257,29 +1265,32 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1257,29 +1265,32 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' )
def getCategoryMemberValueList(self, context, base_category = None, def getCategoryMemberValueList(self, context, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0): spec = (), filter=None, portal_type=(), **kw):
""" """
This returns a catalog_search resource with can then be used by getCategoryMemberItemList This returns a catalog_search resource with can then be used by getCategoryMemberItemList
""" """
from Products.ERP5Form.Selection import DomainSelection from Products.ERP5Form.Selection import DomainSelection
if base_category is None: base_category = 'related' if base_category is None: base_category = 'related'
if spec is (): strict_membership = kw.get('strict_membership', kw.get('strict', 0))
catalog_search = self.portal_catalog(selection_domain = DomainSelection(domain_dict = {base_category:context})) catalog_search = self.portal_catalog(portal_type = portal_type,
else: # TODO: make it work in catalog tool
catalog_search = self.portal_catalog(portal_type = portal_type, # category_strict_membership = strict_membership,
selection_domain = DomainSelection(domain_dict = {base_category:context})) selection_domain = DomainSelection(domain_dict = {base_category:context}))
return catalog_search return catalog_search
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' )
def getCategoryMemberItemList(self, context, strict = 0, **kw): def getCategoryMemberItemList(self, context, **kw):
""" """
This returns a list of items belonging to a category This returns a list of items belonging to a category.
The following parameters are accepted :
portal_type : returns only objects from the given portal_type
strict_membership : returns only object belonging to this category, not
objects belonging to child categories.
strict : a deprecated alias for strict_membership
""" """
k = {} k = {}
for v in ('portal_type', 'spec'): for v in ('portal_type', 'spec', 'strict', 'strict_membership'):
if v in kw: if v in kw:
k[v] = kw[v] k[v] = kw[v]
catalog_search = self.getCategoryMemberValueList(context, **k) catalog_search = self.getCategoryMemberValueList(context, **k)
...@@ -1288,13 +1299,16 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1288,13 +1299,16 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getCategoryMemberTitleItemList' ) 'getCategoryMemberTitleItemList' )
def getCategoryMemberTitleItemList(self, context, base_category = None, def getCategoryMemberTitleItemList(self, context, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0): spec = (), filter=None, portal_type=(), strict_membership = 0,
strict="DEPRECATED"):
""" """
This returns a title list of items belonging to a category This returns a title list of items belonging to a category
""" """
getCategoryMemberItemList(self, context, base_category = base_category, getCategoryMemberItemList(self, context, base_category = base_category,
spec = spec, filter=filter, portal_type=portal_type, strict = strict, display_id = 'getTitle') spec = spec, filter=filter, portal_type=portal_type,
strict_membership = strict_membership, strict = strict,
display_id = 'getTitle')
security.declarePublic('resolveCategory') security.declarePublic('resolveCategory')
......
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