Commit b8253d96 authored by Vincent Pelletier's avatar Vincent Pelletier

Add wrapper class aimed at interfacing properly selection API and catalog API.

Add exceptions for known method names and use new wrapper.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26563 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fa98b5bd
......@@ -58,13 +58,17 @@ try:
except NameError:
from sets import Set as set
class ListMethodWrapper:
"""This class wraps list methods so that they behave like portal_catalog.
"""
class MethodWrapper:
def __init__(self, context, method_name):
self.context = context
self.method_name = self.__name__ = method_name
def __call__(self, *args, **kw):
raise NotImplementedError
class ListMethodWrapper(MethodWrapper):
"""This class wraps list methods so that they behave like portal_catalog.
"""
def __call__(self, *args, **kw):
brain_list = []
for obj in getattr(self.context, self.method_name)(*args, **kw):
......@@ -74,6 +78,16 @@ class ListMethodWrapper:
brain_list.append(brain)
return brain_list
class CatalogMethodWrapper(MethodWrapper):
"""This class wraps catalog list methods so that they discard a pre-defined
set of parameters which are part of the Selection API but not in
SQLCatalog API.
"""
def __call__(self, *args, **kw):
for parameter_id in ('selection', 'selection_name'):
kw.pop(parameter_id, None)
return getattr(self.context, self.method_name)(*args, **kw)
class ReportTree:
"""This class describes a report tree.
"""
......@@ -1064,6 +1078,8 @@ class ListBoxRenderer:
if list_method_name in ('objectValues', 'contentValues'):
list_method = ListMethodWrapper(self.getContext(), list_method_name)
elif list_method_name == 'searchFolder':
list_method = CatalogMethodWrapper(self.getContext(), list_method_name)
elif list_method_name is not None:
try:
list_method = getattr(self.getContext(), list_method_name)
......@@ -1084,8 +1100,10 @@ class ListBoxRenderer:
if count_method_name == 'objectValues':
# Get all objects anyway in this case.
count_method = None
if count_method_name == 'portal_catalog':
count_method = self.getCatalogTool().countResults
elif count_method_name == 'portal_catalog':
count_method = CatalogMethodWrapper(self.getCatalogTool(), 'countResults')
elif count_method_name == 'countFolder':
count_method = CatalogMethodWrapper(self.getContext(), count_method_name)
elif count_method_name is not None:
try:
count_method = getattr(self.getContext(), count_method_name)
......@@ -1106,8 +1124,10 @@ class ListBoxRenderer:
if stat_method_name == 'objectValues':
# Nothing to do in this case.
stat_method = None
if stat_method_name == 'portal_catalog':
stat_method = self.getCatalogTool().countResults
elif stat_method_name == 'portal_catalog':
stat_method = CatalogMethodWrapper(self.getCatalogTool(), 'countResults')
elif stat_method_name == 'countFolder':
stat_method = CatalogMethodWrapper(self.getContext(), stat_method_name)
elif stat_method_name is not None:
try:
stat_method = getattr(self.getContext(), stat_method_name)
......
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