Commit f5a65620 authored by Jean-Paul Smets's avatar Jean-Paul Smets

merged Coramy fast input code


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@626 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4a77c011
...@@ -36,6 +36,7 @@ from Products.Formulator.MethodField import BoundMethod ...@@ -36,6 +36,7 @@ from Products.Formulator.MethodField import BoundMethod
from Selection import Selection from Selection import Selection
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.Utils import getPath from Products.ERP5Type.Utils import getPath
from Products.ERP5Type.Document import newTempBase
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from copy import copy from copy import copy
...@@ -1185,10 +1186,11 @@ class ListBoxValidator(Validator.Validator): ...@@ -1185,10 +1186,11 @@ class ListBoxValidator(Validator.Validator):
listbox_uids = REQUEST.get('%s_uid' % field.id, []) listbox_uids = REQUEST.get('%s_uid' % field.id, [])
errors = [] errors = []
for uid in listbox_uids: for uid in listbox_uids:
try: if str(uid).find('new') == 0:
# We must try this # First case: dialog input to create new objects
# because sometimes, we can be provided bad uids o = newTempBase(here, uid[4:])
o = here.portal_catalog.getObject(uid) o.uid = uid
result[uid[4:]] = {}
for sql in editable_column_ids: for sql in editable_column_ids:
alias = '_'.join(sql.split('.')) alias = '_'.join(sql.split('.'))
if '.' in sql: if '.' in sql:
...@@ -1200,44 +1202,69 @@ class ListBoxValidator(Validator.Validator): ...@@ -1200,44 +1202,69 @@ class ListBoxValidator(Validator.Validator):
my_field = form.get_field(my_field_id) my_field = form.get_field(my_field_id)
key = 'field_' + my_field.id + '_%s' % o.uid key = 'field_' + my_field.id + '_%s' % o.uid
error_result_key = my_field.id + '_%s' % o.uid error_result_key = my_field.id + '_%s' % o.uid
#if hasattr(o,cname_id): WHY THIS ???? REQUEST.cell = o
# XXX This is not acceptable - we do not calculate things the same way in 2 different cases
REQUEST.cell = o # We need cell
try: try:
value = my_field.validator.validate(my_field, key, REQUEST) # We need cell value = my_field.validator.validate(my_field, key, REQUEST) # We need cell
error_result[error_result_key] = value result[uid[4:]][sql] = value
try:
attribute_value = o.getProperty(property_id)
except:
attribute_value = getattr(o,property_id, None)
if my_field.meta_type == "MultiListField":
test_equal = 1
# Sometimes, the attribute is not a list
# so we need to force update
try:
for v in attribute_value:
if v not in value:
test_equal = 0
except:
test_equal = 0
try:
for v in value:
if v not in attribute_value:
test_equal = 0
except:
test_equal = 0
else:
test_equal = attribute_value == value
if not result.has_key(o.getUrl()):
result[o.getUrl()] = {} # We always provide an empty dict - this should be improved by migrating the test of equality to Bae - it is not the purpose of ListBox to do this probably. XXX
if not test_equal:
result[o.getUrl()][sql] = value
except ValidationError, err: # XXXX import missing except ValidationError, err: # XXXX import missing
#LOG("ListBox ValidationError",0,str(err)) #LOG("ListBox ValidationError",0,str(err))
err.field_id = error_result_key err.field_id = error_result_key
errors.append(err) errors.append(err)
except: else:
LOG("ListBox WARNING",0,"Object uid %s could not be validated" % uid) # Second case: modification of existing objects
try:
# We must try this
# because sometimes, we can be provided bad uids
o = here.portal_catalog.getObject(uid)
for sql in editable_column_ids:
alias = '_'.join(sql.split('.'))
if '.' in sql:
property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part
else:
property_id = alias
my_field_id = '%s_%s' % (field.id, alias)
if form.has_field( my_field_id ):
my_field = form.get_field(my_field_id)
key = 'field_' + my_field.id + '_%s' % o.uid
error_result_key = my_field.id + '_%s' % o.uid
#if hasattr(o,cname_id): WHY THIS ????
# XXX This is not acceptable - we do not calculate things the same way in 2 different cases
REQUEST.cell = o # We need cell
try:
value = my_field.validator.validate(my_field, key, REQUEST) # We need cell
error_result[error_result_key] = value
try:
attribute_value = o.getProperty(property_id)
except:
attribute_value = getattr(o,property_id, None)
if my_field.meta_type == "MultiListField":
test_equal = 1
# Sometimes, the attribute is not a list
# so we need to force update
try:
for v in attribute_value:
if v not in value:
test_equal = 0
except:
test_equal = 0
try:
for v in value:
if v not in attribute_value:
test_equal = 0
except:
test_equal = 0
else:
test_equal = attribute_value == value
if not result.has_key(o.getUrl()):
result[o.getUrl()] = {} # We always provide an empty dict - this should be improved by migrating the test of equality to Bae - it is not the purpose of ListBox to do this probably. XXX
if not test_equal:
result[o.getUrl()][sql] = value
except ValidationError, err: # XXXX import missing
#LOG("ListBox ValidationError",0,str(err))
err.field_id = error_result_key
errors.append(err)
except:
LOG("ListBox WARNING",0,"Object uid %s could not be validated" % uid)
if len(errors) > 0: if len(errors) > 0:
#LOG("ListBox FormValidationError",0,str(error_result)) #LOG("ListBox FormValidationError",0,str(error_result))
#LOG("ListBox FormValidationError",0,str(errors)) #LOG("ListBox FormValidationError",0,str(errors))
......
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