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,49 +1762,57 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1754,49 +1762,57 @@ 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. #########################################################################
url_method = None # Link generation
for column in url_columns: #########################################################################
if sql == column[0]: object_url = None
url_method = getattr(o, column[1], '') # Try to get a link
break if not disable_link:
if url_method is not None: # Check if url_columns defines a method
try: # to retrieve the URL.
object_url = url_method(brain = o, selection = selection) url_method = None
list_body = list_body + \ for column in url_columns:
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" % if sql == column[0]:
(td_css, td_align, object_url, attribute_value)) url_method = getattr(o, column[1], '')
except ConflictError: break
raise if url_method is not None:
except: # Call the requested method
LOG('ListBox', 0, 'Could not evaluate url_method %s' % column[1], error=sys.exc_info())
list_body = list_body + \
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) )
else:
# Check if this object provides a specific URL method
url_method = getattr(o, 'getListItemUrl', None)
if url_method is None:
try:
object_url = o.absolute_url() + \
'/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:
list_body = list_body + \
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) )
else:
try: try:
object_url = url_method(alias, i, selection_name) 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:
list_body = list_body + \ # XXX FIXME: except without Error name
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) ) LOG('ListBox', 0,
'Could not evaluate url_method %s' % \
column[1], error=sys.exc_info())
pass
else:
# Check if this object provides a specific URL method
url_method = getattr(o, 'getListItemUrl', None)
if url_method is None:
try:
object_url = o.absolute_url() + \
'/view?selection_index=%s&selection_name=%s&reset=1' % (i, selection_name)
except AttributeError:
pass
else:
try:
object_url = url_method(alias, i, selection_name)
except ConflictError:
raise
except:
# XXX FIXME: except without Error name
pass
# Generate appropriate HTML
if object_url is None:
list_body = list_body + \
("<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