Commit 8f2b7a24 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Change the way to store selection domains, because

it is unsafe to try to store acquisition wrappers in a persistent object.
This may have undesirable effect, because this change makes an acquisition
wrapper with getSelectionFor now.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11149 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5a0d746b
...@@ -839,6 +839,7 @@ class ListBoxRenderer: ...@@ -839,6 +839,7 @@ class ListBoxRenderer:
# Create a selection, if not present, with the default sort order. # Create a selection, if not present, with the default sort order.
if selection is None: if selection is None:
selection = Selection(params = self.getDefaultParamList(), default_sort_on = self.getDefaultSortColumnList()) selection = Selection(params = self.getDefaultParamList(), default_sort_on = self.getDefaultSortColumnList())
selection = selection.__of__(selection_tool)
# Or make sure all sort arguments are valid. # Or make sure all sort arguments are valid.
else: else:
# Reset the selection, if specified. # Reset the selection, if specified.
...@@ -1070,19 +1071,15 @@ class ListBoxRenderer: ...@@ -1070,19 +1071,15 @@ class ListBoxRenderer:
if category_tool is not None: if category_tool is not None:
root = category_tool.restrictedTraverse(domain, None) root = category_tool.restrictedTraverse(domain, None)
if root is not None : if root is not None :
root_dict[base_domain] = root root_dict[base_domain] = ('portal_categories', domain)
elif domain_tool is not None: elif domain_tool is not None:
root = domain_tool.getDomainByPath(domain) root = domain_tool.getDomainByPath(domain)
if root is not None: if root is not None:
# FIXME: this is a bad hack. DomainSelection should use root_dict[base_domain] = ('portal_domains', domain)
# portal_type to determine the type of the object instead
# of whether it is a string or not.
root_dict[base_domain] = domain
if root is None: if root is None:
try: root = portal_object.restrictedTraverse(domain, None)
root_dict[None] = portal_object.restrictedTraverse(domain) if root is not None:
except KeyError: root_dict[None] = (None, domain)
pass
return DomainSelection(domain_dict = root_dict).__of__(self.getContext()) return DomainSelection(domain_dict = root_dict).__of__(self.getContext())
...@@ -1142,31 +1139,31 @@ class ListBoxRenderer: ...@@ -1142,31 +1139,31 @@ class ListBoxRenderer:
root = None root = None
if category_tool is not None: if category_tool is not None:
try: try:
obj = category_tool[category]
if category == 'parent': if category == 'parent':
# parent has a special treatment # parent has a special treatment
root = root_dict[category] = root_dict[None] = self.getContext() root = self.getContext()
report_path = report_path[1:] root_dict[category] = root_dict[None] = (root, (None, root.getRelativeUrl()))
else: else:
root = root_dict[category] = root_dict[None] = obj root = category_tool[category]
report_path = report_path[1:] root_dict[category] = root_dict[None] = (root, ('portal_categories', root.getRelativeUrl()))
report_path = report_path[1:]
except KeyError: except KeyError:
pass pass
if root is None and domain_tool is not None: if root is None and domain_tool is not None:
try: try:
obj = domain_tool[category] root = domain_tool[category]
root = root_dict[category] = root_dict[None] = obj root_dict[category] = root_dict[None] = (root, ('portal_domains', root.getRelativeUrl()))
report_path = report_path[1:] report_path = report_path[1:]
except KeyError: except KeyError:
pass pass
if root is None: if root is None:
try: root = portal_object.unrestrictedTraverse(report_path, None)
root = root_dict[None] = portal_object.unrestrictedTraverse(report_path) if root is not None:
except KeyError: root_dict[None] = (root, (None, root.getRelativeUrl()))
pass
report_path = () report_path = ()
else: else:
root = root_dict[None] = root_dict[category] root_dict[None] = root_dict[category]
root = root_dict[None][0]
report_path = report_path[1:] report_path = report_path[1:]
is_empty_level = (root is None or root.objectCount() == 0) and (len(report_path) != 0) is_empty_level = (root is None or root.objectCount() == 0) and (len(report_path) != 0)
if is_empty_level: if is_empty_level:
...@@ -1188,8 +1185,11 @@ class ListBoxRenderer: ...@@ -1188,8 +1185,11 @@ class ListBoxRenderer:
for obj in obj_list: for obj in obj_list:
new_root_dict = root_dict.copy() new_root_dict = root_dict.copy()
new_root_dict[None] = new_root_dict[base_category] = obj new_root_dict[None] = new_root_dict[base_category] = (obj, (new_root_dict[base_category][1][0], obj.getRelativeUrl()))
domain_selection = DomainSelection(domain_dict = new_root_dict) domain_dict = {}
for k, v in new_root_dict.iteritems():
domain_dict[k] = v[1]
domain_selection = DomainSelection(domain_dict = domain_dict)
if base_category == 'parent': if base_category == 'parent':
exception_uid_list = [] exception_uid_list = []
......
...@@ -382,7 +382,7 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -382,7 +382,7 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
#LOG('DomainSelection', 0, '__init__ is called with %r' % (domain_dict,)) #LOG('DomainSelection', 0, '__init__ is called with %r' % (domain_dict,))
if domain_dict is not None: if domain_dict is not None:
self.domain_dict = domain_dict self.domain_dict = domain_dict
for k,v in domain_dict.items(): for k, v in domain_dict.iteritems():
if k is not None: if k is not None:
setattr(self, k, v) setattr(self, k, v)
...@@ -393,16 +393,39 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -393,16 +393,39 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
def getCategoryList(self): def getCategoryList(self):
return return
def _getDomainObject(self, portal, domain):
"""Return a domain or category object.
"""
if isinstance(domain, tuple):
# This is the new form. The first item describes the name of a tool or
# None if a domain is under a module. The second item is the relative
# URL of a domain.
tool = domain[0]
if tool is None:
obj = portal.restrictedTraverse(domain[1])
elif tool == 'portal_domains':
# Special case, as Domain Tool may generate a domain dynamically.
obj = portal.portal_domains.getDomainByPath(domain[1])
else:
obj = portal[tool].restrictedTraverse(domain[1])
elif isinstance(domain, str):
# XXX backward compatibility: a domain was represented by a string previously.
obj = portal.portal_domains.getDomainByPath(domain)
else:
# XXX backward compatibility: a category was represented by an object itself.
obj = aq_base(domain).__of__(portal)
return obj
security.declarePublic('asSqlExpression') security.declarePublic('asSqlExpression')
def asSqlExpression(self, table_map=None, domain_id=None, def asSqlExpression(self, table_map=None, domain_id=None,
exclude_domain_id=None, strict_membership=0, exclude_domain_id=None, strict_membership=0,
join_table="catalog", join_column="uid", base_category=None): join_table="catalog", join_column="uid", base_category=None):
select_expression = [] select_expression = []
for k, d in self.domain_dict.items(): portal = self.getPortalObject()
if isinstance(d, str): for k, d in self.domain_dict.iteritems():
# get the domain object d = self._getDomainObject(portal, d)
site = self.getPortalObject()
d = site['portal_domains'].getDomainByPath(d)
if k == 'parent': if k == 'parent':
# Special treatment for parent # Special treatment for parent
select_expression.append(d.getParentSqlExpression(table='catalog', select_expression.append(d.getParentSqlExpression(table='catalog',
...@@ -431,11 +454,10 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -431,11 +454,10 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
def asSqlJoinExpression(self, domain_id=None, exclude_domain_id=None): def asSqlJoinExpression(self, domain_id=None, exclude_domain_id=None):
join_expression = [] join_expression = []
#LOG('DomainSelection', 0, 'domain_id = %r, exclude_domain_id = %r, self.domain_dict = %r' % (domain_id, exclude_domain_id, self.domain_dict)) #LOG('DomainSelection', 0, 'domain_id = %r, exclude_domain_id = %r, self.domain_dict = %r' % (domain_id, exclude_domain_id, self.domain_dict))
for k, d in self.domain_dict.items(): portal = self.getPortalObject()
if isinstance(d, str): for k, d in self.domain_dict.iteritems():
# we must the domain d = self._getDomainObject(portal, d)
site = self.getPortalObject()
d = site['portal_domains'].getDomainByPath(d)
if k == 'parent': if k == 'parent':
pass pass
elif k is not None: elif k is not None:
......
...@@ -135,7 +135,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -135,7 +135,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
""" """
Returns the selection instance for a given selection_name Returns the selection instance for a given selection_name
""" """
if not REQUEST: if REQUEST is None:
REQUEST = get_request() REQUEST = get_request()
if not hasattr(self, 'selection_data'): if not hasattr(self, 'selection_data'):
...@@ -144,11 +144,11 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -144,11 +144,11 @@ class SelectionTool( UniqueObject, SimpleItem ):
if user_id is not None: if user_id is not None:
if not self.selection_data.has_key(user_id): if not self.selection_data.has_key(user_id):
self.selection_data[user_id] = PersistentMapping() self.selection_data[user_id] = PersistentMapping()
if type(selection_name) is type(()) or type(selection_name) is type([]) : if isinstance(selection_name, (tuple, list)):
selection_name = selection_name[0] selection_name = selection_name[0]
return self.selection_data[user_id].get(selection_name, None) selection = self.selection_data[user_id].get(selection_name, None)
else: if selection is not None:
return None return selection.__of__(self)
security.declareProtected(ERP5Permissions.View, 'setSelectionFor') security.declareProtected(ERP5Permissions.View, 'setSelectionFor')
def setSelectionFor(self, selection_name, selection_object, REQUEST=None): def setSelectionFor(self, selection_name, selection_object, REQUEST=None):
......
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