Commit bd67acb3 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

rewrite anonymous support in selection.

* now Selection for anonymous is stored per its content and its key is embedded in ListBox rendering.
* we no longer provide cookie to each anonymous user.
* thus same URL (i.e. same parameter) for any anonymous user should have the same result.
* Selection storage for anonymous can be still different from the storage for the normal users.
parent d18c8480
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>kept_names = (\'editable_mode\', \'ignore_layout\', # erp5_web\n <value> <string>kept_names = (\'editable_mode\', \'ignore_layout\', # erp5_web\n
\'selection_name\', \'selection_index\', # list mode\n \'selection_name\', \'selection_index\', # list mode\n
\'selection_key\', # list mode\n
\'bt_list\', # business template installation system\n \'bt_list\', # business template installation system\n
\'ignore_hide_rows\',\n \'ignore_hide_rows\',\n
)\n )\n
......
...@@ -546,6 +546,11 @@ ...@@ -546,6 +546,11 @@
</tbody>\n </tbody>\n
\n \n
</table>\n </table>\n
<input type="hidden" name="selection_name_selection_key" value="md5"\n
tal:define="selection_key here/getSelectionKey"\n
tal:condition="selection_key"\n
tal:attributes="name string:${selection_name}_selection_key;\n
value selection_key" />\n
</div>\n </div>\n
\n \n
<div class="listbox-footer">\n <div class="listbox-footer">\n
......
...@@ -1196,7 +1196,20 @@ class ListBoxRenderer: ...@@ -1196,7 +1196,20 @@ class ListBoxRenderer:
if self.getListMethodName(): if self.getListMethodName():
# Update parameters, only if list_method is defined. # Update parameters, only if list_method is defined.
# (i.e. do not update parameters in listboxes intended to show a previously defined selection. # (i.e. do not update parameters in listboxes intended to show a previously defined selection.
params.update(self.request.form) listbox_prefix = '%s_' % self.getId()
for k, v in self.request.form.iteritems():
# Ignore parameters for other listboxes and selection keys.
if 'listbox_' in k or k.endswith('selection_key'):
continue
elif k.startswith(listbox_prefix):
k = k[len(listbox_prefix):]
# <listbox_field_id>_uid is already handled in
# ListBoxValidator.validate() and putting uid in selection
# will limit the contents for the selection.
if k != 'uid':
params[k] = v
else:
params[k] = v
for k, v in self.getDefaultParamList(): for k, v in self.getDefaultParamList():
params.setdefault(k, v) params.setdefault(k, v)
...@@ -2102,6 +2115,11 @@ class ListBoxRenderer: ...@@ -2102,6 +2115,11 @@ class ListBoxRenderer:
""" """
return self.render(**kw) return self.render(**kw)
def getSelectionKey(self):
selection_tool = self.getSelectionTool()
selection_name = self.getSelectionName()
return selection_tool.getAnonymousSelectionKey(selection_name)
class ListBoxRendererLine: class ListBoxRendererLine:
"""This class describes a line in a ListBox to assist ListBoxRenderer. """This class describes a line in a ListBox to assist ListBoxRenderer.
""" """
...@@ -2447,6 +2465,9 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2447,6 +2465,9 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
params.extend(('selection_name=%s' % selection_name, params.extend(('selection_name=%s' % selection_name,
'selection_index=%s' % self.index, 'selection_index=%s' % self.index,
'reset:int=1')) 'reset:int=1'))
selection_tool = self.getObject().getPortalObject().portal_selections
if selection_tool._isAnonymous():
params.append('selection_key=%s' % selection.getAnonymousSelectionKey())
if params: if params:
url = '%s?%s' % (url, '&amp;'.join(params)) url = '%s?%s' % (url, '&amp;'.join(params))
except AttributeError: except AttributeError:
......
...@@ -33,6 +33,7 @@ from OFS.Traversable import Traversable ...@@ -33,6 +33,7 @@ from OFS.Traversable import Traversable
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions as ERP5Permissions from Products.ERP5Type import Permissions as ERP5Permissions
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from hashlib import md5
# Put a try in front XXX # Put a try in front XXX
from Products.CMFCategory.Category import Category from Products.CMFCategory.Category import Category
...@@ -368,6 +369,10 @@ class Selection(Acquisition.Implicit, Traversable, Persistent): ...@@ -368,6 +369,10 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
def getReportTreeMode(self): def getReportTreeMode(self):
return getattr(self, 'report_tree_mode', 0) return getattr(self, 'report_tree_mode', 0)
security.declarePublic('getAnonymousSelectionKey')
def getAnonymousSelectionKey(self):
return md5(repr(dict([(k, v) for k, v in self.__dict__.iteritems() if k != 'index']))).hexdigest()
InitializeClass(Selection) InitializeClass(Selection)
allow_class(Selection) allow_class(Selection)
......
This diff is collapsed.
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