Commit 1b1b1b82 authored by Jérome Perrin's avatar Jérome Perrin

added support for *_relative_url dynamic related keys



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8926 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2811be92
...@@ -123,11 +123,13 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): ...@@ -123,11 +123,13 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
return list(allowed.keys()) return list(allowed.keys())
class RelatedBaseCategory(Method): class RelatedBaseCategory(Method):
"""A Dynamic Method to act as a related key.
"""
def __init__(self, id): def __init__(self, id):
self._id = id self._id = id
def __call__(self, instance, table_0, table_1, query_table='catalog',**kw): def __call__(self, instance, table_0, table_1, query_table='catalog',**kw):
"""Create the sql code for this related key."""
base_category_uid = instance.portal_categories._getOb(self._id).getUid() base_category_uid = instance.portal_categories._getOb(self._id).getUid()
expression_list = [] expression_list = []
append = expression_list.append append = expression_list.append
...@@ -551,14 +553,16 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -551,14 +553,16 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# can find 'title', or 'portal_type'... # can find 'title', or 'portal_type'...
for i in range(1,len(splitted_key))[::-1]: for i in range(1,len(splitted_key))[::-1]:
expected_base_cat_id = '_'.join(splitted_key[0:i]) expected_base_cat_id = '_'.join(splitted_key[0:i])
if expected_base_cat_id!='parent' and \ if expected_base_cat_id != 'parent' and \
expected_base_cat_id in base_cat_id_list: expected_base_cat_id in base_cat_id_list:
# We have found a base_category # We have found a base_category
end_key = '_'.join(splitted_key[i:]) end_key = '_'.join(splitted_key[i:])
# accept only some catalog columns # accept only some catalog columns
if end_key in ('title','uid','description','id','portal_type'): if end_key in ('title', 'uid', 'description',
related_key_list.append('%s%s | category,catalog/%s/z_related_%s' % 'relative_url', 'id', 'portal_type'):
(prefix,key,end_key,expected_base_cat_id)) related_key_list.append(
'%s%s | category,catalog/%s/z_related_%s' %
(prefix, key, end_key, expected_base_cat_id))
return related_key_list return related_key_list
......
...@@ -713,5 +713,10 @@ class TestERP5Catalog(ERP5TypeTestCase): ...@@ -713,5 +713,10 @@ class TestERP5Catalog(ERP5TypeTestCase):
organisation_list = [x.getObject() for x in organisation_list = [x.getObject() for x in
module.searchFolder(default_group_description='c')] module.searchFolder(default_group_description='c')]
self.assertEquals(organisation_list,[]) self.assertEquals(organisation_list,[])
# Try to get the organisation with group relative_url
group_relative_url = group_nexedi_category.getRelativeUrl()
organisation_list = [x.getObject() for x in
module.searchFolder(group_relative_url=group_relative_url)]
self.assertEquals(organisation_list, [organisation])
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