Commit 5c404a28 authored by Jean-Paul Smets's avatar Jean-Paul Smets

fixed reset issue and added alias handling for multi table catalog


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@594 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5129e405
...@@ -361,6 +361,11 @@ class ListBoxWidget(Widget.Widget): ...@@ -361,6 +361,11 @@ class ListBoxWidget(Widget.Widget):
selection = Selection(params=default_params, sort_on = sort) selection = Selection(params=default_params, sort_on = sort)
# Or make sure all sort arguments are valid # Or make sure all sort arguments are valid
else: else:
# Reset Selection is needed
if reset is not 0 and reset is not '0':
here.portal_selections.setSelectionToAll(selection_name)
here.portal_selections.setSelectionSortOrder(selection_name, sort_on = sort)
# Filter non searchable items # Filter non searchable items
sort = [] sort = []
fix_sort = 0 fix_sort = 0
...@@ -375,10 +380,8 @@ class ListBoxWidget(Widget.Widget): ...@@ -375,10 +380,8 @@ class ListBoxWidget(Widget.Widget):
selection.edit(flat_list_mode=(not (domain_tree or selection.edit(flat_list_mode=(not (domain_tree or
report_tree)),domain_tree_mode=domain_tree,report_tree_mode= report_tree) report_tree)),domain_tree_mode=domain_tree,report_tree_mode= report_tree)
# Reset Selection is needed # Selection
if reset is not 0 and reset is not '0': #LOG("Selection",0,str(selection.__dict__))
here.portal_selections.setSelectionToAll(selection_name)
here.portal_selections.setSelectionSortOrder(selection_name, sort_on = sort)
# Display choosen by the user # Display choosen by the user
...@@ -655,7 +658,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -655,7 +658,7 @@ class ListBoxWidget(Widget.Widget):
#LOG("Selection", 0, str(selection.__dict__)) #LOG("Selection", 0, str(selection.__dict__))
# Build the real list by slicing it # Build the real list by slicing it
# PERFORMANCE ANALYSIS: the result of the query should be # PERFORMANCE ANALYSIS: the result of the query should be
# if possible a lazy sequence # if possible a lazy sequence
...@@ -926,7 +929,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -926,7 +929,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
list_body = list_body + \ list_body = list_body + \
"""<input type="hidden" value="%s" name="%s_uid:list"/> """<input type="hidden" value="%s" name="%s_uid:list"/>
""" % ( o.uid , field.id ) """ % ( getattr(o, 'uid', '') , field.id ) # What happens if we list instances which are not instances of Base XXX
section_char = '' section_char = ''
if report_tree: if report_tree:
...@@ -962,11 +965,16 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -962,11 +965,16 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
<input type="checkbox" %s value="%s" id="cb_%s" name="uids:list"/></td> <input type="checkbox" %s value="%s" id="cb_%s" name="uids:list"/></td>
""" % (td_css, selected, o.uid , o.uid) """ % (td_css, selected, o.uid , o.uid)
for cname in extended_columns: for cname in extended_columns:
cname_id = cname[2] sql = cname[0] # (sql, title, alias)
alias = cname[2] # (sql, title, alias)
if '.' in sql:
property_id = '.'.join(sql.split('.')[1:]) # Only take trailing part
else:
property_id = alias
# attribute_value = getattr(o, cname_id) # FUTURE WAY OF DOING TGW Brains # attribute_value = getattr(o, cname_id) # FUTURE WAY OF DOING TGW Brains
if hasattr(aq_self(o),cname_id): # Block acquisition to reduce risks if hasattr(aq_self(o),alias): # Block acquisition to reduce risks
# First take the indexed value # First take the indexed value
attribute_value = getattr(o,cname_id) # We may need acquisition in case of method call attribute_value = getattr(o,alias) # We may need acquisition in case of method call
else: else:
# MUST IMPROVE FOR PERFORMANCE REASON # MUST IMPROVE FOR PERFORMANCE REASON
# attribute_value = 'Does not exist' # attribute_value = 'Does not exist'
...@@ -978,17 +986,17 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -978,17 +986,17 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if real_o is not None: if real_o is not None:
try: try:
try: try:
attribute_value = getattr(real_o,cname_id, None) attribute_value = getattr(real_o,property_id, None)
#LOG('Look up attribute %s' % cname_id,0,str(attribute_value)) #LOG('Look up attribute %s' % cname_id,0,str(attribute_value))
if not callable(attribute_value): if not callable(attribute_value):
#LOG('Look up accessor %s' % cname_id,0,'') #LOG('Look up accessor %s' % cname_id,0,'')
attribute_value = real_o.getProperty(cname_id) attribute_value = real_o.getProperty(property_id)
#LOG('Look up accessor %s' % cname_id,0,str(attribute_value)) #LOG('Look up accessor %s' % cname_id,0,str(attribute_value))
except: except:
attribute_value = getattr(real_o,cname_id) attribute_value = getattr(real_o,property_id)
#LOG('Fallback to attribute %s' % cname_id,0,str(attribute_value)) #LOG('Fallback to attribute %s' % cname_id,0,str(attribute_value))
except: except:
attribute_value = 'Can not evaluate attribute: %s' % cname_id attribute_value = 'Can not evaluate attribute: %s' % sql
else: else:
attribute_value = 'Object does not exist' attribute_value = 'Object does not exist'
if callable(attribute_value): if callable(attribute_value):
...@@ -997,7 +1005,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -997,7 +1005,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
except: except:
attribute_value = "Could not evaluate" attribute_value = "Could not evaluate"
if type(attribute_value) is type(0.0): if type(attribute_value) is type(0.0):
if cname_id in editable_column_ids and form.has_field('%s_%s' % (field.id, cname_id) ): if sql in editable_column_ids and form.has_field('%s_%s' % (field.id, alias) ):
# Do not truncate if editable # Do not truncate if editable
pass pass
else: else:
...@@ -1007,8 +1015,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1007,8 +1015,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
td_align = "right" td_align = "right"
else: else:
td_align = "left" td_align = "left"
if cname_id in editable_column_ids and form.has_field('%s_%s' % (field.id, cname_id) ): if sql in editable_column_ids and form.has_field('%s_%s' % (field.id, alias) ):
my_field_id = '%s_%s' % (field.id, cname_id) my_field_id = '%s_%s' % (field.id, alias)
my_field = form.get_field(my_field_id) my_field = form.get_field(my_field_id)
key = my_field.id + '_%s' % o.uid key = my_field.id + '_%s' % o.uid
cell_body = my_field.render(value = attribute_value, REQUEST = o, key = key) cell_body = my_field.render(value = attribute_value, REQUEST = o, key = key)
...@@ -1029,7 +1037,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1029,7 +1037,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) ) ("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) )
else: else:
try: try:
object_url = url_method(cname_id, i, selection_name) object_url = url_method(alias, i, selection_name)
list_body = list_body + \ list_body = list_body + \
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" % ("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" %
(td_css, td_align, object_url, attribute_value)) (td_css, td_align, object_url, attribute_value))
...@@ -1050,8 +1058,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1050,8 +1058,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
list_body += '<td class="Data">&nbsp;</td>' list_body += '<td class="Data">&nbsp;</td>'
elif report_tree == 1: elif report_tree == 1:
try: try:
cname_id = extended_columns[n-1][2] alias = extended_columns[n-1][2]
value = getattr(count_results[0],cname_id,'') value = getattr(count_results[0],alias,'')
if callable(value): value=value() if callable(value): value=value()
if type(value) is type(1.0): if type(value) is type(1.0):
list_body += '<td class="Data" align="right">%.2f</td>' % value list_body += '<td class="Data" align="right">%.2f</td>' % value
...@@ -1061,8 +1069,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1061,8 +1069,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
list_body += '<td class="Data">&nbsp;</td>' list_body += '<td class="Data">&nbsp;</td>'
else: else:
try: try:
cname_id = extended_columns[n][2] alias = extended_columns[n][2]
value = getattr(count_results[0],cname_id,'') value = getattr(count_results[0],alias,'')
if callable(value): value=value() if callable(value): value=value()
if type(value) is type(1.0): if type(value) is type(1.0):
list_body += '<td class="Data" align="right">%.2f</td>' % value list_body += '<td class="Data" align="right">%.2f</td>' % value
...@@ -1138,16 +1146,22 @@ class ListBoxValidator(Validator.Validator): ...@@ -1138,16 +1146,22 @@ class ListBoxValidator(Validator.Validator):
# We must try this # We must try this
# because sometimes, we can be provided bad uids # because sometimes, we can be provided bad uids
o = here.portal_catalog.getObject(uid) o = here.portal_catalog.getObject(uid)
for cname_id in editable_column_ids: for sql in editable_column_ids:
my_field_id = '%s_%s' % (field.id, cname_id) 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 ): if form.has_field( my_field_id ):
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
#if hasattr(o,cname_id): WHY THIS ???? #if hasattr(o,cname_id): WHY THIS ????
# XXX This is not acceptable - we do not calculate things the same way in 2 different cases
try: try:
attribute_value = o.getProperty(cname_id) attribute_value = o.getProperty(property_id)
except: except:
attribute_value = getattr(o,cname_id, None) attribute_value = getattr(o,property_id, None)
REQUEST.cell = o # We need cell REQUEST.cell = o # We need cell
value = my_field.validator.validate(my_field, key, REQUEST) # We need cell value = my_field.validator.validate(my_field, key, REQUEST) # We need cell
if my_field.meta_type == "MultiListField": if my_field.meta_type == "MultiListField":
...@@ -1171,7 +1185,7 @@ class ListBoxValidator(Validator.Validator): ...@@ -1171,7 +1185,7 @@ class ListBoxValidator(Validator.Validator):
if not result.has_key(o.getUrl()): 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 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: if not test_equal:
result[o.getUrl()][cname_id] = value result[o.getUrl()][sql] = value
except: except:
LOG("ListBox WARNING",0,"Object uid %s could not be validated" % uid) LOG("ListBox WARNING",0,"Object uid %s could not be validated" % uid)
return result return result
......
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