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

Improved filtering of nodes and leaves

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13205 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8085a7d6
...@@ -33,7 +33,8 @@ from zLOG import LOG ...@@ -33,7 +33,8 @@ from zLOG import LOG
class Filter(Implicit): class Filter(Implicit):
def __init__(self, spec=None, filter=None, portal_type=None, filter_method=None): def __init__(self, spec=None, filter=None, portal_type=None,
filter_method=None, filter_node=0, filter_leave=0):
""" """
Initialize attributes. spec and portal_type can be lists, tuples or strings. Initialize attributes. spec and portal_type can be lists, tuples or strings.
...@@ -60,12 +61,25 @@ class Filter(Implicit): ...@@ -60,12 +61,25 @@ class Filter(Implicit):
if len(spec) > 0: if len(spec) > 0:
self.filter_dict['meta_type'] = spec self.filter_dict['meta_type'] = spec
self.filter_method = filter_method self.filter_method = filter_method
self.filter_node = filter_node
self.filter_leave = filter_leave
def test(self, context): def test(self, context):
""" """
Test filter on a context Test filter on a context
""" """
#LOG('Filter test', 0, 'context = %s' % repr(context)) #LOG('Filter test', 0, 'context = %s' % repr(context))
is_node = None
if self.filter_node:
is_node = len(context.contentIds(filter={'portal_type' : 'Category'}))
if is_node:
return 0
if self.filter_leave:
if is_node is None:
# Only recalculate is_node if not already done
is_node = len(context.contentIds(filter={'portal_type' : 'Category'}))
if not is_node:
return 0
for k, v in self.filter_dict.items(): for k, v in self.filter_dict.items():
#LOG('Filter test', 0, "k = %s, v = %s" % (repr(k), repr(v))) #LOG('Filter test', 0, "k = %s, v = %s" % (repr(k), repr(v)))
if type(v) in (type([]), type(())): if type(v) in (type([]), type(())):
......
...@@ -41,6 +41,7 @@ class Renderer(Filter): ...@@ -41,6 +41,7 @@ class Renderer(Filter):
def __init__(self, spec = None, filter = None, portal_type = None, def __init__(self, spec = None, filter = None, portal_type = None,
display_id = None, sort_id = None, display_id = None, sort_id = None,
display_method = None, sort_method = None, filter_method = None, display_method = None, sort_method = None, filter_method = None,
filter_node=0, filter_leave=0,
is_right_display = 0, translate_display = 0, is_right_display = 0, translate_display = 0,
translatation_domain = None, display_base_category = 0, translatation_domain = None, display_base_category = 0,
base_category = None, base = 1, base_category = None, base = 1,
...@@ -51,6 +52,12 @@ class Renderer(Filter): ...@@ -51,6 +52,12 @@ class Renderer(Filter):
- *display_method*: a callable method which is used to calculate the value to display - *display_method*: a callable method which is used to calculate the value to display
- *filter_method*: a method to filter items in the list
- *filter_node*: do not keep node categories
- *filter_leave*: do not keep leave categories
- *sort_id*: the id of the attribute to "call" to calculate the value used for sorting. - *sort_id*: the id of the attribute to "call" to calculate the value used for sorting.
Sorting is only applied to default ItemList items. Sorting is only applied to default ItemList items.
...@@ -103,7 +110,8 @@ class Renderer(Filter): ...@@ -103,7 +110,8 @@ class Renderer(Filter):
""" """
#LOG('Renderer', 0, 'spec = %s, filter = %s, portal_type = %s, display_id = %s, sort_id = %s, display_method = %s, sort_method = %s, is_right_display = %s, translate_display = %s, translatation_domain = %s, base_category = %s, base = %s, display_none_category = %s, current_category = %s' % (repr(spec), repr(filter), repr(portal_type), repr(display_id), repr(sort_id), repr(display_method), repr(sort_method), repr(is_right_display), repr(translate_display), repr(translatation_domain), repr(base_category), repr(base), repr(display_none_category), repr(current_category))) #LOG('Renderer', 0, 'spec = %s, filter = %s, portal_type = %s, display_id = %s, sort_id = %s, display_method = %s, sort_method = %s, is_right_display = %s, translate_display = %s, translatation_domain = %s, base_category = %s, base = %s, display_none_category = %s, current_category = %s' % (repr(spec), repr(filter), repr(portal_type), repr(display_id), repr(sort_id), repr(display_method), repr(sort_method), repr(is_right_display), repr(translate_display), repr(translatation_domain), repr(base_category), repr(base), repr(display_none_category), repr(current_category)))
Filter.__init__(self, spec=spec, filter=filter, Filter.__init__(self, spec=spec, filter=filter,
portal_type=portal_type, filter_method=filter_method) portal_type=portal_type, filter_method=filter_method,
filter_node=filter_node, filter_leave=filter_leave)
self.display_id = display_id self.display_id = display_id
self.sort_id = sort_id self.sort_id = sort_id
self.display_method = display_method self.display_method = display_method
......
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