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: ...@@ -58,13 +58,17 @@ try:
except NameError: except NameError:
from sets import Set as set from sets import Set as set
class ListMethodWrapper: class MethodWrapper:
"""This class wraps list methods so that they behave like portal_catalog.
"""
def __init__(self, context, method_name): def __init__(self, context, method_name):
self.context = context self.context = context
self.method_name = self.__name__ = method_name 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): def __call__(self, *args, **kw):
brain_list = [] brain_list = []
for obj in getattr(self.context, self.method_name)(*args, **kw): for obj in getattr(self.context, self.method_name)(*args, **kw):
...@@ -74,6 +78,16 @@ class ListMethodWrapper: ...@@ -74,6 +78,16 @@ class ListMethodWrapper:
brain_list.append(brain) brain_list.append(brain)
return brain_list 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: class ReportTree:
"""This class describes a report tree. """This class describes a report tree.
""" """
...@@ -1064,6 +1078,8 @@ class ListBoxRenderer: ...@@ -1064,6 +1078,8 @@ class ListBoxRenderer:
if list_method_name in ('objectValues', 'contentValues'): if list_method_name in ('objectValues', 'contentValues'):
list_method = ListMethodWrapper(self.getContext(), list_method_name) 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: elif list_method_name is not None:
try: try:
list_method = getattr(self.getContext(), list_method_name) list_method = getattr(self.getContext(), list_method_name)
...@@ -1084,8 +1100,10 @@ class ListBoxRenderer: ...@@ -1084,8 +1100,10 @@ class ListBoxRenderer:
if count_method_name == 'objectValues': if count_method_name == 'objectValues':
# Get all objects anyway in this case. # Get all objects anyway in this case.
count_method = None count_method = None
if count_method_name == 'portal_catalog': elif count_method_name == 'portal_catalog':
count_method = self.getCatalogTool().countResults 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: elif count_method_name is not None:
try: try:
count_method = getattr(self.getContext(), count_method_name) count_method = getattr(self.getContext(), count_method_name)
...@@ -1106,8 +1124,10 @@ class ListBoxRenderer: ...@@ -1106,8 +1124,10 @@ class ListBoxRenderer:
if stat_method_name == 'objectValues': if stat_method_name == 'objectValues':
# Nothing to do in this case. # Nothing to do in this case.
stat_method = None stat_method = None
if stat_method_name == 'portal_catalog': elif stat_method_name == 'portal_catalog':
stat_method = self.getCatalogTool().countResults 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: elif stat_method_name is not None:
try: try:
stat_method = getattr(self.getContext(), stat_method_name) 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