Commit 044d8f38 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_core: remove abbreviations in Base_edit

parent 75c9a1a2
...@@ -42,8 +42,8 @@ except FormValidationError, validation_errors: ...@@ -42,8 +42,8 @@ except FormValidationError, validation_errors:
field_errors = form.ErrorFields(validation_errors) field_errors = form.ErrorFields(validation_errors)
request.set('field_errors', field_errors) request.set('field_errors', field_errors)
# Make sure editors are pushed back as values into the REQUEST object # Make sure editors are pushed back as values into the REQUEST object
for f in form.get_fields(): for field in form.get_fields():
field_id = f.id field_id = field.id
if request.has_key(field_id): if request.has_key(field_id):
value = request.get(field_id) value = request.get(field_id)
if callable(value): if callable(value):
...@@ -55,17 +55,17 @@ def editListBox(listbox_field, listbox): ...@@ -55,17 +55,17 @@ def editListBox(listbox_field, listbox):
""" Function called to edit a listbox """ Function called to edit a listbox
""" """
if listbox is not None: if listbox is not None:
gv = {} global_property_dict = {}
if listbox_field.has_value('global_attributes'): if listbox_field.has_value('global_attributes'):
hidden_attributes = map(lambda x:x[0], listbox_field.get_value('global_attributes')) hidden_attribute_list = map(lambda x:x[0], listbox_field.get_value('global_attributes'))
for k in hidden_attributes: for hidden_attribute in hidden_attribute_list:
gv[k] = getattr(request, k, None) global_property_dict[hidden_attribute] = getattr(request, hidden_attribute, None)
for url, v in listbox.items(): for item_url, listbox_item_dict in listbox.items():
v.update(gv) listbox_item_dict.update(global_property_dict)
# Form: '' -> ERP5: None # Form: '' -> ERP5: None
encapsulated_editor_list = [] encapsulated_editor_list = []
cleaned_v = {} cleaned_v = {}
for key, value in v.items(): for key, value in listbox_item_dict.items():
if hasattr(value, 'edit'): if hasattr(value, 'edit'):
encapsulated_editor_list.append(value) encapsulated_editor_list.append(value)
else: else:
...@@ -75,10 +75,10 @@ def editListBox(listbox_field, listbox): ...@@ -75,10 +75,10 @@ def editListBox(listbox_field, listbox):
if cleaned_v: if cleaned_v:
if listbox_edit is None: if listbox_edit is None:
obj = context.restrictedTraverse(url) obj = context.restrictedTraverse(item_url)
obj.edit(edit_order=edit_order, **cleaned_v) obj.edit(edit_order=edit_order, **cleaned_v)
else: else:
listbox_edit(url, edit_order, cleaned_v) listbox_edit(item_url, edit_order, cleaned_v)
for encapsulated_editor in encapsulated_editor_list: for encapsulated_editor in encapsulated_editor_list:
encapsulated_editor.edit(obj) encapsulated_editor.edit(obj)
...@@ -95,14 +95,14 @@ def editMatrixBox(matrixbox_field, matrixbox): ...@@ -95,14 +95,14 @@ def editMatrixBox(matrixbox_field, matrixbox):
else: else:
matrix_context = context matrix_context = context
if matrix_context is not None: if matrix_context is not None:
kd = {} k_dict = {}
kd['portal_type'] = portal_type k_dict['portal_type'] = portal_type
kd['base_id'] = cell_base_id k_dict['base_id'] = cell_base_id
gv = {} global_property_dict = {}
if matrixbox_field.has_value('global_attributes'): if matrixbox_field.has_value('global_attributes'):
hidden_attributes = [x[0] for x in matrixbox_field.get_value('global_attributes')] hidden_attribute_list = [x[0] for x in matrixbox_field.get_value('global_attributes')]
for k in hidden_attributes: for hidden_attribute in hidden_attribute_list:
gv[k] = getattr(request, k, None) global_property_dict[hidden_attribute] = getattr(request, hidden_attribute, None)
if matrixbox_field.get_value('update_cell_range'): if matrixbox_field.get_value('update_cell_range'):
as_cell_range_script_id = matrixbox_field.get_value( as_cell_range_script_id = matrixbox_field.get_value(
'as_cell_range_script_id') 'as_cell_range_script_id')
...@@ -157,57 +157,57 @@ def editMatrixBox(matrixbox_field, matrixbox): ...@@ -157,57 +157,57 @@ def editMatrixBox(matrixbox_field, matrixbox):
if cell_range != matrixbox_cell_range: if cell_range != matrixbox_cell_range:
matrix_context.setCellRange(base_id=cell_base_id, *matrixbox_cell_range) matrix_context.setCellRange(base_id=cell_base_id, *matrixbox_cell_range)
for k,v in matrixbox.items(): for cell_index_tuple, cell_dict in matrixbox.items():
# Only update cells which still exist # Only update cells which still exist
if matrix_context.hasInRange(*k, **kd): if matrix_context.hasInRange(*cell_index_tuple, **k_dict):
c = matrix_context.newCell(*k, **kd) cell = matrix_context.newCell(*cell_index_tuple, **k_dict)
if c is not None: if cell is not None:
c.edit(edit_order=edit_order, **gv) # First update globals which include the def. of property_list cell.edit(edit_order=edit_order, **global_property_dict) # First update globals which include the def. of property_list
if v.has_key('variated_property'): if cell_dict.has_key('variated_property'):
# For Variated Properties # For Variated Properties
value = v['variated_property'] variated_property = cell_dict['variated_property']
del v['variated_property'] del cell_dict['variated_property']
if gv.has_key('mapped_value_property_list'): if global_property_dict.has_key('mapped_value_property_list'):
# Change the property which is defined by the # Change the property which is defined by the
# first element of mapped_value_property_list # first element of mapped_value_property_list
# XXX May require some changes with Sets # XXX May require some changes with Sets
key = gv['mapped_value_property_list'][0] key = global_property_dict['mapped_value_property_list'][0]
v[key] = value cell_dict[key] = variated_property
# Form: '' -> ERP5: None # Form: '' -> ERP5: None
cleaned_v = v.copy() cleaned_v = cell_dict.copy()
for key, value in cleaned_v.items(): for key, value in cleaned_v.items():
if value == '': if value == '':
cleaned_v[key] = None cleaned_v[key] = None
c.edit(edit_order=edit_order, **cleaned_v) # and update the cell specific values cell.edit(edit_order=edit_order, **cleaned_v) # and update the cell specific values
else: else:
return "Could not create cell %s" % str(k) return "Could not create cell %s" % str(cell_index_tuple)
else: else:
return "Cell %s does not exist" % str(k) return "Cell %s does not exist" % str(cell_index_tuple)
field_prefix_len = len(field_prefix) field_prefix_len = len(field_prefix)
def parseField(f): def parseField(field):
""" """
Parse given form field, to put them in Parse given form field, to put them in
kw or in encapsulated_editor_list kw or in encapsulated_editor_list
""" """
k = f.id field_id = field.id
if f.has_value('alternate_name'): if field.has_value('alternate_name'):
k = f.get_value('alternate_name') or f.id field_id = field.get_value('alternate_name') or field_id
v = getattr(request, k, MARKER) value = getattr(request, field_id, MARKER)
if hasattr(v, 'edit'): if hasattr(value, 'edit'):
# This is an encapsulated editor # This is an encapsulated editor
# call it # call it
encapsulated_editor_list.append(v) encapsulated_editor_list.append(value)
elif v is not MARKER: elif value is not MARKER:
if k.startswith(field_prefix): if field_id.startswith(field_prefix):
# We only take into account # We only take into account
# the object attributes # the object attributes
k = k[field_prefix_len:] field_id = field_id[field_prefix_len:]
# Form: '' -> ERP5: None # Form: '' -> ERP5: None
if v == '': if value == '':
v = None value = None
kw[k] = v kw[field_id] = value
# Some initilizations # Some initilizations
kw = {} kw = {}
...@@ -246,12 +246,12 @@ if message_only: ...@@ -246,12 +246,12 @@ if message_only:
ignore_layout = int(ignore_layout) ignore_layout = int(ignore_layout)
editable_mode = int(editable_mode) editable_mode = int(editable_mode)
spp = context.getPhysicalPath() server_physical_path = context.getPhysicalPath()
spp =list(spp) server_physical_path = list(server_physical_path)
s_url = request["SERVER_URL"] server_url = request["SERVER_URL"]
spp.insert(0,s_url) server_physical_path.insert(0, server_url)
#calculate direct the url instead of using absolute_url #calculate direct the url instead of using absolute_url
new_url = '/'.join(spp) new_url = '/'.join(server_physical_path)
# for web mode, we should use 'view' instead of passed form_id # for web mode, we should use 'view' instead of passed form_id
# after 'Save & View'. # after 'Save & View'.
......
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