diff --git a/product/CMFCategory/Filter.py b/product/CMFCategory/Filter.py index 083cb7b1d43e18cc8a4a25b59bcd31c95208f2bf..b61f15a4c7de17bdc6405fa788db8ebd500fb8c0 100644 --- a/product/CMFCategory/Filter.py +++ b/product/CMFCategory/Filter.py @@ -33,9 +33,14 @@ from zLOG import LOG 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. + + 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))) if type(filter) is type({}): @@ -54,6 +59,7 @@ class Filter(Implicit): # XXX An empty list or tuple is the same as None here. if len(spec) > 0: self.filter_dict['meta_type'] = spec + self.filter_method = filter_method def test(self, context): """ @@ -67,6 +73,8 @@ class Filter(Implicit): return 0 elif context.getProperty(k) != v: return 0 + if self.filter_method is not None: + return self.filter_method(context) return 1 diff --git a/product/CMFCategory/Renderer.py b/product/CMFCategory/Renderer.py index 04fa90e7dee2463033a7200fd7331d1db78c870d..e50b26e50cc7dfcb439a49995dd5386db941111c 100644 --- a/product/CMFCategory/Renderer.py +++ b/product/CMFCategory/Renderer.py @@ -40,7 +40,7 @@ class Renderer(Filter): def __init__(self, spec = None, filter = None, portal_type = 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, translatation_domain = None, display_base_category = 0, base_category = None, base = 1, @@ -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))) - 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.sort_id = sort_id self.display_method = display_method