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