Commit c2da6fd8 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Improve Predicate_view interface.

* use parallel MultiListField to specify Membership Categories for each category instead of using a single long MultiListField for all categories.
* display fallback category id instead of own id for using fallback cases (eg. region/europe for source_region categories).
  * update test to follow this change.
* add LinesField to specify Membership Values (eg. source/person_module/123).
  * add an external validator for this field.
* accept filter argument in getMembershipCriterionCategoryList to return categories only or documents only for membership values.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26643 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a4c97885
...@@ -558,3 +558,36 @@ class Predicate(XMLObject, Folder): ...@@ -558,3 +558,36 @@ class Predicate(XMLObject, Folder):
TO BE IMPLEMENTED using portal_catalog(**kw) TO BE IMPLEMENTED using portal_catalog(**kw)
""" """
pass pass
security.declareProtected(Permissions.AccessContentsInformation,
'getMembershipCriterionCategoryList')
def getMembershipCriterionCategoryList(self, filter=None, **kw):
"""
If filter is specified, return category only or document only
in membership_criterion_category values.
"""
all_list = self._baseGetMembershipCriterionCategoryList()
if filter in ('category', 'document'):
portal_categories = self.getPortalObject().portal_categories
result_dict = {'category':[], 'document':[]}
for x in all_list:
try:
if portal_categories.restrictedTraverse(x).getPortalType() == \
'Category':
result_dict['category'].append(x)
else:
result_dict['document'].append(x)
except KeyError:
result_dict['document'].append(x)
return result_dict[filter]
else:
return all_list
security.declareProtected(Permissions.ModifyPortalContent,
'setMembershipCriterionDocumentList' )
def setMembershipCriterionDocumentList(self, document_list):
"""
Appends to membership_criterion_category values.
"""
return self.setMembershipCriterionCategoryList(
(self.getMembershipCriterionCategoryList() + document_list))
...@@ -68,10 +68,10 @@ for item in mixed_list:\n ...@@ -68,10 +68,10 @@ for item in mixed_list:\n
base_category = ctool[item]\n base_category = ctool[item]\n
item_list = base_category.getCategoryChildCompactLogicalPathItemList(base=1)[:]\n item_list = base_category.getCategoryChildCompactLogicalPathItemList(base=1)[:]\n
if item_list == [[\'\', \'\']]:\n if item_list == [[\'\', \'\']]:\n
for fallback_category in base_category.getFallbackBaseCategoryList():\n for fallback_category_id in base_category.getFallbackBaseCategoryList():\n
fallback_category = ctool.restrictedTraverse(fallback_category, None)\n fallback_category = ctool.restrictedTraverse(fallback_category_id, None)\n
if fallback_category is not None and fallback_category.objectIds():\n if fallback_category is not None and fallback_category.objectIds():\n
item_list.extend([(\'%s/%s\' % (item, x[0]), \'%s/%s\' % (item, x[1])) \\\n item_list.extend([(\'%s/%s\' % (fallback_category_id, x[0]), \'%s/%s\' % (item, x[1])) \\\n
for x in fallback_category.getCategoryChildCompactLogicalPathItemList(base=1) if x[0]])\n for x in fallback_category.getCategoryChildCompactLogicalPathItemList(base=1) if x[0]])\n
break\n break\n
\n \n
...@@ -126,8 +126,9 @@ return category_list\n ...@@ -126,8 +126,9 @@ return category_list\n
<string>_getitem_</string> <string>_getitem_</string>
<string>base_category</string> <string>base_category</string>
<string>item_list</string> <string>item_list</string>
<string>fallback_category</string> <string>fallback_category_id</string>
<string>None</string> <string>None</string>
<string>fallback_category</string>
<string>append</string> <string>append</string>
<string>$append0</string> <string>$append0</string>
<string>x</string> <string>x</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
This script is used in parallel list fields in Predicate_view\n
"""\n
# Initialise result\n
sub_field_list = []\n
\n
# use MultiListField\n
default_sub_field_property_dict.update({\'field_type\':\'MultiListField\'})\n
\n
z = 0\n
category_list = context.getMembershipCriterionBaseCategoryList()\n
category_list += [i for i in context.getMultimembershipCriterionBaseCategoryList() \\\n
if i not in category_list]\n
\n
for category in category_list:\n
new_dict = default_sub_field_property_dict.copy()\n
new_dict[\'value\'] = [x for x in value_list if x.startswith(\'%s/\' % category)]\n
if z == 0:\n
new_dict[\'title\'] = \'%s (%s)\' % (default_sub_field_property_dict[\'title\'], category)\n
else:\n
new_dict[\'title\'] = \'(%s)\' % category\n
new_dict[\'item_list\'] = [[\'\', \'\']] + [x for x in item_list if x[1].startswith(\'%s/\' % category)]\n
new_dict[\'key\'] = str(z)\n
if len(new_dict[\'item_list\']) == 1:\n
continue\n
z += 1\n
sub_field_list.append(new_dict)\n
\n
request = context.REQUEST\n
\n
return sub_field_list\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>item_list</string>
<string>value_list</string>
<string>default_sub_field_property_dict</string>
<string>is_right_display</string>
<string>sub_field_list</string>
<string>_getattr_</string>
<string>z</string>
<string>context</string>
<string>category_list</string>
<string>_inplacevar_</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>i</string>
<string>category</string>
<string>new_dict</string>
<string>x</string>
<string>_write_</string>
<string>_getitem_</string>
<string>str</string>
<string>len</string>
<string>request</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<dictionary/>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Predicate_hashCategoryList</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>category_list = context.getMembershipCriterionBaseCategoryList()\n
category_list += [i for i in context.getMultimembershipCriterionBaseCategoryList() \\\n
if i not in category_list]\n
portal_categories = context.getPortalObject().portal_categories\n
\n
for item in item_list:\n
base_category, relative_url = item.split(\'/\', 1)\n
if base_category not in category_list or \\\n
portal_categories.restrictedTraverse(relative_url, None) is None:\n
return 0\n
return 1\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, request</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>2</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>item_list</string>
<string>request</string>
<string>_getattr_</string>
<string>context</string>
<string>category_list</string>
<string>_inplacevar_</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>i</string>
<string>portal_categories</string>
<string>item</string>
<string>base_category</string>
<string>relative_url</string>
<string>None</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Predicate_validateMembershipCriterionDocument</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<value> <value>
<list> <list>
<string>my_membership_criterion_category_list</string> <string>my_membership_criterion_category_list</string>
<string>my_membership_criterion_document_list</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<tuple> <tuple>
<global name="MultiListField" module="Products.Formulator.StandardFields"/> <global name="ParallelListField" module="Products.ERP5Form.ParallelListField"/>
<tuple/> <tuple/>
</tuple> </tuple>
</pickle> </pickle>
...@@ -72,6 +72,14 @@ ...@@ -72,6 +72,14 @@
<key> <string>extra_item</string> </key> <key> <string>extra_item</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>first_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hash_script_id</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>hidden</string> </key> <key> <string>hidden</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -117,7 +125,9 @@ ...@@ -117,7 +125,9 @@
</item> </item>
<item> <item>
<key> <string>default</string> </key> <key> <string>default</string> </key>
<value> <string></string> </value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -143,6 +153,14 @@ ...@@ -143,6 +153,14 @@
<key> <string>extra_item</string> </key> <key> <string>extra_item</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>first_item</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hash_script_id</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>hidden</string> </key> <key> <string>hidden</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -150,7 +168,7 @@ ...@@ -150,7 +168,7 @@
<item> <item>
<key> <string>items</string> </key> <key> <string>items</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
<item> <item>
...@@ -218,6 +236,14 @@ ...@@ -218,6 +236,14 @@
<key> <string>extra_item</string> </key> <key> <string>extra_item</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>first_item</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>hash_script_id</string> </key>
<value> <string>Predicate_hashCategoryList</string> </value>
</item>
<item> <item>
<key> <string>hidden</string> </key> <key> <string>hidden</string> </key>
<value> <int>0</int> </value> <value> <int>0</int> </value>
...@@ -234,11 +260,11 @@ ...@@ -234,11 +260,11 @@
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>10</int> </value> <value> <int>5</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Membership Values</string> </value> <value> <string>Membership Criterion Categories</string> </value>
</item> </item>
<item> <item>
<key> <string>unicode</string> </key> <key> <string>unicode</string> </key>
...@@ -259,6 +285,22 @@ ...@@ -259,6 +285,22 @@
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.getMembershipCriterionCategoryList(filter=\'category\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<tuple> <tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/> <global name="TALESMethod" module="Products.Formulator.TALESField"/>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="LinesField" module="Products.Formulator.StandardFields"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_membership_criterion_document_list</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>You specify an invalid base category or a non-existing document.</string> </value>
</item>
<item>
<key> <string>line_too_long</string> </key>
<value> <string>A line was too long.</string> </value>
</item>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
<item>
<key> <string>too_long</string> </key>
<value> <string>You entered too many characters.</string> </value>
</item>
<item>
<key> <string>too_many_lines</string> </key>
<value> <string>You entered too many lines.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>height</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>height</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>height</string> </key>
<value> <int>5</int> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Membership Criterion Documents</string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string encoding="cdata"><![CDATA[
<br />
]]></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <int>40</int> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python:here.getMembershipCriterionCategoryList(filter=\'document\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="Method" module="Products.Formulator.MethodField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>method_name</string> </key>
<value> <string>Predicate_validateMembershipCriterionDocument</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1169 1170
\ No newline at end of file \ No newline at end of file
...@@ -413,7 +413,7 @@ class TestPredicates(TestPredicateMixIn): ...@@ -413,7 +413,7 @@ class TestPredicates(TestPredicateMixIn):
# note that the id of the actual base category is displayed in the first # note that the id of the actual base category is displayed in the first
# item too, for making it clear in the UI that it's the content of a # item too, for making it clear in the UI that it's the content of a
# category used for another base category. # category used for another base category.
self.failUnless(('source_region/europe/western_europe', self.failUnless(('region/europe/western_europe',
'source_region/region/europe/western_europe') in 'source_region/region/europe/western_europe') in
[tuple(x) for x in pred.Predicate_getMembershipCriterionCategoryList()], [tuple(x) for x in pred.Predicate_getMembershipCriterionCategoryList()],
pred.Predicate_getMembershipCriterionCategoryList(),) pred.Predicate_getMembershipCriterionCategoryList(),)
......
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