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

Added support for arbitrary filtering

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10035 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8487712e
...@@ -33,9 +33,14 @@ from zLOG import LOG ...@@ -33,9 +33,14 @@ from zLOG import LOG
class Filter(Implicit): class Filter(Implicit):
def __init__(self, spec=None, filter=None, portal_type=None): def __init__(self, spec=None, filter=None, portal_type=None, filter_method=None):
""" """
Initialize attributes. spec and portal_type can be lists, tuples or strings. Initialize attributes. spec and portal_type can be lists, tuples or strings.
filter_method - filter_method allows for extending filtering in an arbitrary way
filter_method must be provided with a category and should
return 0 (False) or 1 (True)
""" """
#LOG('Filter __init__', 0, 'self = %s, spec = %s, filter = %s, portal_type = %s' % (str(self), str(spec), str(filter), str(portal_type))) #LOG('Filter __init__', 0, 'self = %s, spec = %s, filter = %s, portal_type = %s' % (str(self), str(spec), str(filter), str(portal_type)))
if type(filter) is type({}): if type(filter) is type({}):
...@@ -54,6 +59,7 @@ class Filter(Implicit): ...@@ -54,6 +59,7 @@ class Filter(Implicit):
# XXX An empty list or tuple is the same as None here. # XXX An empty list or tuple is the same as None here.
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
def test(self, context): def test(self, context):
""" """
...@@ -67,6 +73,8 @@ class Filter(Implicit): ...@@ -67,6 +73,8 @@ class Filter(Implicit):
return 0 return 0
elif context.getProperty(k) != v: elif context.getProperty(k) != v:
return 0 return 0
if self.filter_method is not None:
return self.filter_method(context)
return 1 return 1
......
...@@ -40,7 +40,7 @@ class Renderer(Filter): ...@@ -40,7 +40,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, display_method = None, sort_method = None, filter_method = None,
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,
...@@ -102,7 +102,8 @@ class Renderer(Filter): ...@@ -102,7 +102,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, portal_type=portal_type) Filter.__init__(self, spec=spec, filter=filter,
portal_type=portal_type, filter_method=filter_method)
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