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:
# Create a selection, if not present, with the default sort order.
if selection is None:
selection = Selection(params = self.getDefaultParamList(), default_sort_on = self.getDefaultSortColumnList())
selection = selection.__of__(selection_tool)
# Or make sure all sort arguments are valid.
else:
# Reset the selection, if specified.
......@@ -1070,19 +1071,15 @@ class ListBoxRenderer:
if category_tool is not None:
root = category_tool.restrictedTraverse(domain, None)
if root is not None :
root_dict[base_domain] = root
root_dict[base_domain] = ('portal_categories', domain)
elif domain_tool is not None:
root = domain_tool.getDomainByPath(domain)
if root is not None:
# FIXME: this is a bad hack. DomainSelection should use
# portal_type to determine the type of the object instead
# of whether it is a string or not.
root_dict[base_domain] = domain
root_dict[base_domain] = ('portal_domains', domain)
if root is None:
try:
root_dict[None] = portal_object.restrictedTraverse(domain)
except KeyError:
pass
root = portal_object.restrictedTraverse(domain, None)
if root is not None:
root_dict[None] = (None, domain)
return DomainSelection(domain_dict = root_dict).__of__(self.getContext())
......@@ -1142,31 +1139,31 @@ class ListBoxRenderer:
root = None
if category_tool is not None:
try:
obj = category_tool[category]
if category == 'parent':
# parent has a special treatment
root = root_dict[category] = root_dict[None] = self.getContext()
report_path = report_path[1:]
root = self.getContext()
root_dict[category] = root_dict[None] = (root, (None, root.getRelativeUrl()))
else:
root = root_dict[category] = root_dict[None] = obj
root = category_tool[category]
root_dict[category] = root_dict[None] = (root, ('portal_categories', root.getRelativeUrl()))
report_path = report_path[1:]
except KeyError:
pass
if root is None and domain_tool is not None:
try:
obj = domain_tool[category]
root = root_dict[category] = root_dict[None] = obj
root = domain_tool[category]
root_dict[category] = root_dict[None] = (root, ('portal_domains', root.getRelativeUrl()))
report_path = report_path[1:]
except KeyError:
pass
if root is None:
try:
root = root_dict[None] = portal_object.unrestrictedTraverse(report_path)
except KeyError:
pass
root = portal_object.unrestrictedTraverse(report_path, None)
if root is not None:
root_dict[None] = (root, (None, root.getRelativeUrl()))
report_path = ()
else:
root = root_dict[None] = root_dict[category]
root_dict[None] = root_dict[category]
root = root_dict[None][0]
report_path = report_path[1:]
is_empty_level = (root is None or root.objectCount() == 0) and (len(report_path) != 0)
if is_empty_level:
......@@ -1188,8 +1185,11 @@ class ListBoxRenderer:
for obj in obj_list:
new_root_dict = root_dict.copy()
new_root_dict[None] = new_root_dict[base_category] = obj
domain_selection = DomainSelection(domain_dict = new_root_dict)
new_root_dict[None] = new_root_dict[base_category] = (obj, (new_root_dict[base_category][1][0], obj.getRelativeUrl()))
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':
exception_uid_list = []
......
......@@ -382,7 +382,7 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
#LOG('DomainSelection', 0, '__init__ is called with %r' % (domain_dict,))
if domain_dict is not None:
self.domain_dict = domain_dict
for k,v in domain_dict.items():
for k, v in domain_dict.iteritems():
if k is not None:
setattr(self, k, v)
......@@ -393,16 +393,39 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
def getCategoryList(self):
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')
def asSqlExpression(self, table_map=None, domain_id=None,
exclude_domain_id=None, strict_membership=0,
join_table="catalog", join_column="uid", base_category=None):
select_expression = []
for k, d in self.domain_dict.items():
if isinstance(d, str):
# get the domain object
site = self.getPortalObject()
d = site['portal_domains'].getDomainByPath(d)
portal = self.getPortalObject()
for k, d in self.domain_dict.iteritems():
d = self._getDomainObject(portal, d)
if k == 'parent':
# Special treatment for parent
select_expression.append(d.getParentSqlExpression(table='catalog',
......@@ -431,11 +454,10 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
def asSqlJoinExpression(self, domain_id=None, exclude_domain_id=None):
join_expression = []
#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():
if isinstance(d, str):
# we must the domain
site = self.getPortalObject()
d = site['portal_domains'].getDomainByPath(d)
portal = self.getPortalObject()
for k, d in self.domain_dict.iteritems():
d = self._getDomainObject(portal, d)
if k == 'parent':
pass
elif k is not None:
......
......@@ -135,7 +135,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
"""
Returns the selection instance for a given selection_name
"""
if not REQUEST:
if REQUEST is None:
REQUEST = get_request()
if not hasattr(self, 'selection_data'):
......@@ -144,11 +144,11 @@ class SelectionTool( UniqueObject, SimpleItem ):
if user_id is not None:
if not self.selection_data.has_key(user_id):
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]
return self.selection_data[user_id].get(selection_name, None)
else:
return None
selection = self.selection_data[user_id].get(selection_name, None)
if selection is not None:
return selection.__of__(self)
security.declareProtected(ERP5Permissions.View, 'setSelectionFor')
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