Commit 8df1f143 authored by Julien Muchembled's avatar Julien Muchembled

ERP5Form: fix name of newly-created selections for listboxes that are not rendered in HTML

parent 4327a7db
......@@ -50,14 +50,13 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>selection_name = context.REQUEST.get(\'list_selection_name\', None)\n
listbox_uid =context.REQUEST.get(\'listbox_uid\', None)\n
uids = context.REQUEST.get(\'uids\', None)\n
<value> <string>portal = context.getPortalObject()\n
get = portal.REQUEST.get\n
selection_name = get(\'list_selection_name\')\n
\n
if selection_name is not None:\n
context.portal_selections.updateSelectionCheckedUidList(listbox_uid = listbox_uid,\n
uids=uids,\n
selection_name=selection_name)\n
if isinstance(selection_name, basestring):\n
portal.portal_selections.updateSelectionCheckedUidList(\n
selection_name, get(\'listbox_uid\'), get(\'uids\'))\n
</string> </value>
</item>
<item>
......
......@@ -1072,8 +1072,10 @@ class ListBoxRenderer:
# Create a selection, if not present, with the default sort order.
if selection is None:
selection = Selection(params = dict(self.getDefaultParamList()), default_sort_on = self.getDefaultSortColumnList())
selection = selection.__of__(selection_tool)
selection = Selection(selection_name,
params=dict(self.getDefaultParamList()),
default_sort_on=self.getDefaultSortColumnList(),
).__of__(selection_tool)
# Or make sure all sort arguments are valid.
else:
# Reset the selection, if specified.
......@@ -2605,8 +2607,8 @@ class ListBoxHTMLRenderer(ListBoxRenderer):
# Make it sure to store the current selection, only if a list method is defined.
list_method = self.getListMethod()
selection = self.getSelection()
if list_method is not None:
selection = self.getSelection()
method_path = '%s/%s' % (getPath(self.getContext()), self.getListMethodName())
list_url = '%s?selection_name=%s' % (self.getUrl(), self.getRequestedSelectionName())
selection_index = self.getSelectionIndex()
......
......@@ -1063,7 +1063,8 @@ class BasicStructure:
#recovering selection if necessary
if self.selection is None:
self.selection = Selection(params={}, default_sort_on=self.sort)
self.selection = Selection(self.selection_name, params={},
default_sort_on=self.sort)
self.selection.edit(default_sort_on=self.sort)
self.getSelectionTool().setSelectionSortOrder(self.selection_name,\
......
......@@ -338,7 +338,8 @@ class ReportSection:
portal_selections.pushSelection(selection_name)
else:
if portal_selections.getSelectionFor(selection_name) is None:
portal_selections.setSelectionFor(selection_name, Selection())
portal_selections.setSelectionFor(selection_name,
Selection(selection_name))
if self.selection_report_list is not None:
selection = portal_selections.getSelectionFor(selection_name,
......
......@@ -104,7 +104,6 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
list_url=''
columns=()
checked_uids=()
name=None
index=None
domain_path = ('portal_categories',)
domain_list = ((),)
......@@ -123,9 +122,10 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
def getId(self):
return self.name
def __init__(self, method_path=None, params=None, sort_on=None, default_sort_on=None,
uids=None, invert_mode=0, list_url='', domain=None, report=None,
columns=None, checked_uids=None, name=None, index=None):
def __init__(self, name, method_path=None, params=None, sort_on=None,
default_sort_on=None, uids=None, invert_mode=0, list_url='',
domain=None, report=None, columns=None, checked_uids=None,
index=None):
if params is None: params = {}
if sort_on is None: sort_on = []
if default_sort_on is None: default_sort_on = []
......
......@@ -284,9 +284,7 @@ class SelectionTool( BaseTool, SimpleItem ):
if anonymous_uid is not None:
self.REQUEST.response.setCookie('anonymous_uid', anonymous_uid,
path='/')
if selection_object != None:
# Set the name so that this selection itself can get its own name.
selection_object.edit(name=selection_name)
assert selection_object is None or selection_name == selection_object.name
if self.getSelectionFor(selection_name) != selection_object:
self._setSelectionToContainer(selection_name, selection_object)
......@@ -317,7 +315,7 @@ class SelectionTool( BaseTool, SimpleItem ):
if selection_object is not None:
selection_object.edit(params=params)
else:
selection_object = Selection(params=params)
selection_object = Selection(selection_name, params=params)
self.setSelectionFor(selection_name, selection_object, REQUEST)
security.declareProtected(ERP5Permissions.View, 'getSelectionDomainDictFor')
......@@ -353,7 +351,7 @@ class SelectionTool( BaseTool, SimpleItem ):
if selection_object:
selection_object.edit(checked_uids=checked_uids)
else:
selection_object = Selection(checked_uids=checked_uids)
selection_object = Selection(selection_name, checked_uids=checked_uids)
self.setSelectionFor(selection_name, selection_object, REQUEST)
security.declareProtected(ERP5Permissions.View, 'updateSelectionCheckedUidList')
......@@ -1062,7 +1060,7 @@ class SelectionTool( BaseTool, SimpleItem ):
# Get the selection
selection = self.getSelectionFor(selection_name, REQUEST)
if selection is None:
selection = Selection()
selection = Selection(selection_name)
self.setSelectionFor(selection_name, selection, REQUEST=REQUEST)
if listbox_display_mode == 'FlatListMode':
......@@ -1443,7 +1441,7 @@ class SelectionTool( BaseTool, SimpleItem ):
def pushSelection(self, selection_name):
selection = self.getSelectionFor(selection_name)
# a temporary selection is kept in transaction.
temp_selection = Selection()
temp_selection = Selection(selection_name)
if selection:
temp_selection.__dict__.update(selection.__dict__)
self.getTemporarySelectionDict()\
......
......@@ -139,7 +139,7 @@ class ZGDChartWidget(Widget.Widget):
# Creation selection if needed
if selection is None:
selection = Selection(params=data)
selection = Selection(selection_name, params=data)
else:
LOG('ZGDChart.render',0,'selection is not None')
kw = {'params':data}
......
......@@ -164,7 +164,7 @@ class ZPyChart(ZMIField, PythonScript):
# If selection is None, create a new one
if selection is None:
selection = Selection()
selection = Selection(selection_name)
# Get the data method if defined
if data_method is not None:
......
......@@ -252,8 +252,8 @@ class TestListBox(ERP5TypeTestCase):
portal.ListBoxZuite_reset()
listbox = portal.FooModule_viewFooList.listbox
# XXX isn't Selection automatically created ?
portal.portal_selections.setSelectionFor(
listbox.get_value('selection_name'), Selection())
name = listbox.get_value('selection_name')
portal.portal_selections.setSelectionFor(name, Selection(name))
request = get_request()
request['here'] = portal.foo_module
......
......@@ -53,7 +53,8 @@ class TestSelectionTool(ERP5TypeTestCase):
user = uf.getUserById('manager').__of__(uf)
newSecurityManager(None, user)
self.portal_selections = self.getPortal().portal_selections
self.portal_selections.setSelectionFor('test_selection', Selection())
name = 'test_selection'
self.portal_selections.setSelectionFor(name, Selection(name))
self.portal_selections.setSelectionParamsFor('test_selection', {'key':'value'})
def testGetSelectionContainer(self):
......@@ -252,7 +253,8 @@ class TestSelectionPersistence(unittest.TestCase):
self.cnx = self.db.open()
self.portal_selections = \
self.cnx.root().portal_selections = SelectionTool()
self.portal_selections.setSelectionFor('test_selection', Selection())
name = 'test_selection'
self.portal_selections.setSelectionFor(name, Selection(name))
transaction.commit()
def tearDown(self):
......
......@@ -82,8 +82,8 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.portal.changeSkin(self.skin)
self.validator = Validator()
# make sure selections are empty
self.portal.portal_selections.setSelectionFor(
'person_module_selection', Selection())
name = 'person_module_selection'
self.portal.portal_selections.setSelectionFor(name, Selection(name))
def setDefaultSitePreference(self):
default_pref = self.portal.portal_preferences.default_site_preference
......
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