Commit 0acdc2de authored by Romain Courteaud's avatar Romain Courteaud

Add the possibility to disable HTML link on the lines of a listbox.

This is requested for example when tempObject are displayed, like in
Base_viewHistory.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4335 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent de0ee5b7
...@@ -273,7 +273,8 @@ class ListBoxWidget(Widget.Widget): ...@@ -273,7 +273,8 @@ class ListBoxWidget(Widget.Widget):
""" """
property_names = Widget.Widget.property_names +\ property_names = Widget.Widget.property_names +\
['lines', 'columns', 'all_columns', 'search_columns', 'sort_columns', 'sort', ['lines', 'columns', 'all_columns', 'search_columns', 'sort_columns', 'sort',
'editable_columns', 'all_editable_columns', 'stat_columns', 'url_columns', 'global_attributes', 'editable_columns', 'all_editable_columns',
'stat_columns', 'disable_link', 'url_columns', 'global_attributes',
'list_method', 'count_method', 'stat_method', 'selection_name', 'list_method', 'count_method', 'stat_method', 'selection_name',
'meta_types', 'portal_types', 'default_params', 'meta_types', 'portal_types', 'default_params',
'search', 'select', 'search', 'select',
...@@ -412,6 +413,12 @@ class ListBoxWidget(Widget.Widget): ...@@ -412,6 +413,12 @@ class ListBoxWidget(Widget.Widget):
default=[], default=[],
required=0) required=0)
disable_link = fields.CheckBoxField('disable_link',
title='Disable Link',
description=('Disable URL'),
default='',
required=0)
url_columns = fields.ListTextAreaField('url_columns', url_columns = fields.ListTextAreaField('url_columns',
title="URL Columns", title="URL Columns",
description=( description=(
...@@ -514,6 +521,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -514,6 +521,7 @@ class ListBoxWidget(Widget.Widget):
editable_columns = field.get_value('editable_columns') editable_columns = field.get_value('editable_columns')
all_editable_columns = field.get_value('all_editable_columns') all_editable_columns = field.get_value('all_editable_columns')
stat_columns = field.get_value('stat_columns') stat_columns = field.get_value('stat_columns')
disable_link = field.get_value('disable_link')
url_columns = field.get_value('url_columns') url_columns = field.get_value('url_columns')
search_columns = field.get_value('search_columns') search_columns = field.get_value('search_columns')
sort_columns = field.get_value('sort_columns') sort_columns = field.get_value('sort_columns')
...@@ -1754,24 +1762,31 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1754,24 +1762,31 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
current_listboxline.addColumn( cname[0] , attribute_value_tmp) current_listboxline.addColumn( cname[0] , attribute_value_tmp)
else: else:
# Check if url_columns defines a method to retrieve the URL. #########################################################################
# Link generation
#########################################################################
object_url = None
# Try to get a link
if not disable_link:
# Check if url_columns defines a method
# to retrieve the URL.
url_method = None url_method = None
for column in url_columns: for column in url_columns:
if sql == column[0]: if sql == column[0]:
url_method = getattr(o, column[1], '') url_method = getattr(o, column[1], '')
break break
if url_method is not None: if url_method is not None:
# Call the requested method
try: try:
object_url = url_method(brain = o, selection = selection) object_url = url_method(brain=o, selection=selection)
list_body = list_body + \
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" %
(td_css, td_align, object_url, attribute_value))
except ConflictError: except ConflictError:
raise raise
except: except:
LOG('ListBox', 0, 'Could not evaluate url_method %s' % column[1], error=sys.exc_info()) # XXX FIXME: except without Error name
list_body = list_body + \ LOG('ListBox', 0,
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) ) 'Could not evaluate url_method %s' % \
column[1], error=sys.exc_info())
pass
else: else:
# Check if this object provides a specific URL method # Check if this object provides a specific URL method
url_method = getattr(o, 'getListItemUrl', None) url_method = getattr(o, 'getListItemUrl', None)
...@@ -1779,24 +1794,25 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1779,24 +1794,25 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
try: try:
object_url = o.absolute_url() + \ object_url = o.absolute_url() + \
'/view?selection_index=%s&selection_name=%s&reset=1' % (i, selection_name) '/view?selection_index=%s&selection_name=%s&reset=1' % (i, selection_name)
list_body = list_body + \
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" %
(td_css, td_align, object_url, attribute_value))
except AttributeError: except AttributeError:
list_body = list_body + \ pass
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) )
else: else:
try: try:
object_url = url_method(alias, i, selection_name) object_url = url_method(alias, i, selection_name)
list_body = list_body + \
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" %
(td_css, td_align, object_url, attribute_value))
except ConflictError: except ConflictError:
raise raise
except: except:
# XXX FIXME: except without Error name
pass
# Generate appropriate HTML
if object_url is None:
list_body = list_body + \ list_body = list_body + \
("<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:
list_body = list_body + \
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" %
(td_css, td_align, object_url, attribute_value))
if render_format == 'list': if render_format == 'list':
# Make sure that attribute value is UTF-8 # Make sure that attribute value is UTF-8
......
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