Commit 212d2ddb authored by Romain Courteaud's avatar Romain Courteaud

Bug fix.

MultiRelationField does not crash anymore when the property does not exist on
object.
Add StringValidator properties to RelationFieldValidator.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6297 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c2cee8c3
......@@ -46,6 +46,7 @@ NEW_CONTENT_PREFIX = '_newContent_'
# Key for sub listfield
SUB_FIELD_ID = 'relation'
ITEM_ID = 'item'
NO_VALUE = '??? (No Value)'
def checkSameKeys(a , b):
"""
......@@ -208,6 +209,12 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
if isinstance(value_list, StringType):
# Value is a string, reformat it correctly
value_list = value_list.split("\n")
else:
# We get a list
# rather than displaying nothing, display a marker when the
# property is not set
# XXX Translate ?
value_list = [(x or NO_VALUE) for x in value_list]
# Check all relation
for i in range(len(value_list)):
###################################
......@@ -224,11 +231,6 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
if (relation_item_list is not None) and \
(value != ''):
need_validation = 1
if value is None :
# rather than displaying nothing, display a marker when the
# property is not set
# XXX Translate ?
value = '??? (no value)'
# If we get a empty string, display nothing !
if value != '':
result_list.append((Widget.TextWidgetInstance, relation_field_id,
......@@ -565,7 +567,6 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator):
if (found == 1) and \
(value != display_text):
relation_editor_list = None
# import pdb; pdb.set_trace()
need_to_revalidate = 1
REQUEST.set(relation_field_id, None)
break
......
......@@ -37,7 +37,8 @@ from Products.ERP5Type.Message import Message
from Products.ERP5Form import MultiRelationField
from Products.ERP5Form.MultiRelationField import MAX_SELECT, \
NEW_CONTENT_PREFIX, \
SUB_FIELD_ID, ITEM_ID
SUB_FIELD_ID, ITEM_ID, \
NO_VALUE
from types import StringType
from AccessControl import ClassSecurityInfo
from zLOG import LOG
......@@ -56,6 +57,7 @@ class RelationStringFieldWidget(
default_widget_rendering_instance = Widget.TextWidgetInstance
def _generateRenderValueList(self, field, key, value, REQUEST):
# value = value or NO_VALUE
relation_field_id = field.generate_subfield_key(SUB_FIELD_ID, key=key)
relation_item_key = field.generate_subfield_key(ITEM_ID, key=key)
relation_item_list = REQUEST.get(relation_item_key, [])
......@@ -75,13 +77,17 @@ class RelationEditor(MultiRelationField.MultiRelationEditor):
allow_class(RelationEditor)
class RelationStringFieldValidator(
MultiRelationField.MultiRelationStringFieldValidator):
MultiRelationField.MultiRelationStringFieldValidator,
Validator.StringValidator):
"""
Validation includes lookup of relared instances
"""
message_names = Validator.StringValidator.message_names + \
MultiRelationField.MultiRelationStringFieldValidator.message_names
property_names = Validator.StringValidator.property_names + \
MultiRelationField.MultiRelationStringFieldValidator.property_names
# Delete double in order to keep a usable ZMI...
# Need to keep order !
_v_dict = {}
......@@ -92,6 +98,14 @@ class RelationStringFieldValidator(
_v_dict[message_name] = 1
message_names = _v_message_name_list
_v_dict = {}
_v_property_name_list = []
for property_name in property_names:
if not _v_dict.has_key(property_name):
_v_property_name_list.append(property_name)
_v_dict[property_name] = 1
property_names = _v_property_name_list
# Relation field variable
editor = RelationEditor
default_validator_instance = Validator.StringValidatorInstance
......
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