Commit 727cdeff authored by Yoshinori Okuji's avatar Yoshinori Okuji

Add URL columns


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1272 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6cf64da8
...@@ -137,7 +137,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -137,7 +137,7 @@ 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', 'global_attributes', 'editable_columns', 'all_editable_columns', 'stat_columns', 'url_columns', 'global_attributes',
'list_method', 'stat_method', 'selection_name', 'list_method', 'stat_method', 'selection_name',
'meta_types', 'portal_types', 'default_params', 'meta_types', 'portal_types', 'default_params',
'search', 'select', 'search', 'select',
...@@ -328,7 +328,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -328,7 +328,7 @@ class ListBoxWidget(Widget.Widget):
# First, grasp and intialize the variables we may need later # First, grasp and intialize the variables we may need later
# #
############################################################### ###############################################################
here = REQUEST['here'] here = REQUEST['here']
reset = REQUEST.get('reset', 0) reset = REQUEST.get('reset', 0)
form = field.aq_parent form = field.aq_parent
...@@ -346,6 +346,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -346,6 +346,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')
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')
domain_tree = field.get_value('domain_tree') domain_tree = field.get_value('domain_tree')
...@@ -387,6 +388,9 @@ class ListBoxWidget(Widget.Widget): ...@@ -387,6 +388,9 @@ class ListBoxWidget(Widget.Widget):
for column in all_columns: for column in all_columns:
stat_columns.append((column[0], column[0])) stat_columns.append((column[0], column[0]))
if not url_columns:
url_columns = []
has_catalog_path = None has_catalog_path = None
for (k, v) in all_columns: for (k, v) in all_columns:
if k == 'catalog.path' or k == 'path': if k == 'catalog.path' or k == 'path':
...@@ -486,7 +490,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -486,7 +490,7 @@ class ListBoxWidget(Widget.Widget):
params['portal_type'] = filtered_portal_types params['portal_type'] = filtered_portal_types
############################################################### ###############################################################
# #
# Build the columns selections # Build the columns selections
# #
# The idea is: instead of selecting *, listbox is able to # The idea is: instead of selecting *, listbox is able to
...@@ -516,11 +520,11 @@ class ListBoxWidget(Widget.Widget): ...@@ -516,11 +520,11 @@ class ListBoxWidget(Widget.Widget):
params['select_columns'] = sql_columns_string params['select_columns'] = sql_columns_string
############################################################### ###############################################################
# #
# Execute the query # Execute the query
# #
############################################################### ###############################################################
kw = params kw = params
# XXX Remove selection_expression if present. # XXX Remove selection_expression if present.
...@@ -609,10 +613,10 @@ class ListBoxWidget(Widget.Widget): ...@@ -609,10 +613,10 @@ class ListBoxWidget(Widget.Widget):
#LOG('ListBox', 0, 'list_method = %s, list_method.__dict__ = %s' % (repr(list_method), repr((list_method.__dict__)))) #LOG('ListBox', 0, 'list_method = %s, list_method.__dict__ = %s' % (repr(list_method), repr((list_method.__dict__))))
############################################################### ###############################################################
# #
# Prepare the stat select_expression # Prepare the stat select_expression
# #
############################################################### ###############################################################
if show_stat: if show_stat:
stats = here.portal_selections.getSelectionStats(selection_name, REQUEST=REQUEST) stats = here.portal_selections.getSelectionStats(selection_name, REQUEST=REQUEST)
select_expression = '' select_expression = ''
...@@ -636,9 +640,9 @@ class ListBoxWidget(Widget.Widget): ...@@ -636,9 +640,9 @@ class ListBoxWidget(Widget.Widget):
index = index + 1 index = index + 1
select_expression = select_expression[:len(select_expression) - 1] select_expression = select_expression[:len(select_expression) - 1]
############################################################### ###############################################################
# #
# Build the report tree # Build the report tree
# #
# When we build the body, we have to go through all report lines # When we build the body, we have to go through all report lines
...@@ -646,8 +650,8 @@ class ListBoxWidget(Widget.Widget): ...@@ -646,8 +650,8 @@ class ListBoxWidget(Widget.Widget):
# Each report line is a tuple of the form: # Each report line is a tuple of the form:
# #
# (section_id, is_summary, depth, object_list, object_list_size, is_open) # (section_id, is_summary, depth, object_list, object_list_size, is_open)
# #
############################################################### ###############################################################
report_query = '' report_query = ''
if report_tree: if report_tree:
original_query = kw.get('query') original_query = kw.get('query')
...@@ -668,7 +672,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -668,7 +672,7 @@ class ListBoxWidget(Widget.Widget):
s[0].asSqlExpression(strict_membership=0)) s[0].asSqlExpression(strict_membership=0))
else: else:
kw['query'] = s[0].asSqlExpression(strict_membership=0) kw['query'] = s[0].asSqlExpression(strict_membership=0)
# Push new select_expression # Push new select_expression
original_select_expression = kw.get('select_expression') original_select_expression = kw.get('select_expression')
kw['select_expression'] = select_expression kw['select_expression'] = select_expression
...@@ -736,11 +740,11 @@ class ListBoxWidget(Widget.Widget): ...@@ -736,11 +740,11 @@ class ListBoxWidget(Widget.Widget):
# PERFORMANCE PROBLEM ? is len(object_list) fast enough ? # PERFORMANCE PROBLEM ? is len(object_list) fast enough ?
report_sections = ( (None, 0, 0, object_list, len(object_list), 0), ) report_sections = ( (None, 0, 0, object_list, len(object_list), 0), )
############################################################### ###############################################################
# #
# Build an md5 signature of the selection # Build an md5 signature of the selection
# #
# It is calculated based on the selection uid list # It is calculated based on the selection uid list
# It is used in order to do some checks in scripts. # It is used in order to do some checks in scripts.
# For example, if we do delete objects, then we do have a list of # For example, if we do delete objects, then we do have a list of
...@@ -748,9 +752,9 @@ class ListBoxWidget(Widget.Widget): ...@@ -748,9 +752,9 @@ class ListBoxWidget(Widget.Widget):
# change, and then when we confirm the deletion, we don't delete what # change, and then when we confirm the deletion, we don't delete what
# we want, so this is really dangerous. with this md5 we can check if the # we want, so this is really dangerous. with this md5 we can check if the
# selection is the same # selection is the same
# #
############################################################### ###############################################################
object_uid_list = map(lambda x: getattr(x, 'uid', None), object_list) object_uid_list = map(lambda x: getattr(x, 'uid', None), object_list)
#LOG('ListBox.render, object_uid_list:',0,object_uid_list) #LOG('ListBox.render, object_uid_list:',0,object_uid_list)
sorted_object_uid_list = copy(object_uid_list) sorted_object_uid_list = copy(object_uid_list)
...@@ -760,25 +764,25 @@ class ListBoxWidget(Widget.Widget): ...@@ -760,25 +764,25 @@ class ListBoxWidget(Widget.Widget):
############################################################### ###############################################################
# #
# Calculate list start and stop # Calculate list start and stop
# #
# 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
# #
############################################################### ###############################################################
#LOG("Selection", 0, str(selection.__dict__)) #LOG("Selection", 0, str(selection.__dict__))
total_size = 0 total_size = 0
for s in report_sections: for s in report_sections:
total_size += s[4] total_size += s[4]
if render_format == 'list': if render_format == 'list':
start = 0 start = 0
end = total_size end = total_size
total_pages = 1 total_pages = 1
current_page = 0 current_page = 0
else: else:
try: try:
start = REQUEST.get('list_start') start = REQUEST.get('list_start')
start = int(start) start = int(start)
...@@ -795,12 +799,12 @@ class ListBoxWidget(Widget.Widget): ...@@ -795,12 +799,12 @@ class ListBoxWidget(Widget.Widget):
kw['list_lines'] = lines kw['list_lines'] = lines
############################################################### ###############################################################
# #
# Store new selection values # Store new selection values
# #
# Store the resulting selection if list_method is not None and render_format is not list # Store the resulting selection if list_method is not None and render_format is not list
# #
############################################################### ###############################################################
if list_method is not None and render_format != 'list': if list_method is not None and render_format != 'list':
try: try:
method_path = getPath(here) + '/' + list_method.method_name method_path = getPath(here) + '/' + list_method.method_name
...@@ -817,11 +821,11 @@ class ListBoxWidget(Widget.Widget): ...@@ -817,11 +821,11 @@ class ListBoxWidget(Widget.Widget):
here.portal_selections.setSelectionFor(selection_name, selection, REQUEST=REQUEST) here.portal_selections.setSelectionFor(selection_name, selection, REQUEST=REQUEST)
############################################################### ###############################################################
# #
# Build HTML header and footer # Build HTML header and footer
# #
############################################################### ###############################################################
# Provide the selection name # Provide the selection name
selection_line = """\ selection_line = """\
<input type="hidden" name="list_selection_name" value="%s" /> <input type="hidden" name="list_selection_name" value="%s" />
...@@ -1028,7 +1032,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1028,7 +1032,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
list_search = list_search + "</tr>" list_search = list_search + "</tr>"
else: else:
list_search = '' list_search = ''
# Build the tuple of columns # Build the tuple of columns
if render_format == 'list': if render_format == 'list':
c_name_list = [] c_name_list = []
...@@ -1036,11 +1040,11 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1036,11 +1040,11 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
c_name_list.append(cname[1]) c_name_list.append(cname[1])
############################################################### ###############################################################
# #
# Build lines # Build lines
# #
############################################################### ###############################################################
# Build Lines # Build Lines
list_body = '' list_body = ''
if render_format == 'list': list_result = [c_name_list] # Create initial list for list render format if render_format == 'list': list_result = [c_name_list] # Create initial list for list render format
...@@ -1050,6 +1054,9 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1050,6 +1054,9 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
current_section_size = current_section[4] current_section_size = current_section[4]
object_list = current_section[3] object_list = current_section[3]
for i in range(start,end): for i in range(start,end):
# Set the selection index.
selection.edit(index = i)
# Make sure we go to the right section # Make sure we go to the right section
while current_section_base_index + current_section_size <= i: while current_section_base_index + current_section_size <= i:
current_section_base_index += current_section[4] current_section_base_index += current_section[4]
...@@ -1108,7 +1115,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1108,7 +1115,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
"""<td class="%s" width="50" align="center" valign="middle">&nbsp; """<td class="%s" width="50" align="center" valign="middle">&nbsp;
<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)
error_list = [] error_list = []
for cname in extended_columns: for cname in extended_columns:
sql = cname[0] # (sql, title, alias) sql = cname[0] # (sql, title, alias)
alias = cname[2] # (sql, title, alias) alias = cname[2] # (sql, title, alias)
...@@ -1165,7 +1172,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1165,7 +1172,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
except TypeError: except TypeError:
attribute_value = attribute_value() attribute_value = attribute_value()
except: except:
LOG('ListBox', 0, '', error=sys.exc_info()) LOG('ListBox', 0, 'Could not evaluate', error=sys.exc_info())
attribute_value = "Could not evaluate" attribute_value = "Could not evaluate"
#LOG('ListBox', 0, 'o = %s' % repr(dir(o))) #LOG('ListBox', 0, 'o = %s' % repr(dir(o)))
if type(attribute_value) is type(0.0): if type(attribute_value) is type(0.0):
...@@ -1197,47 +1204,64 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1197,47 +1204,64 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
# This prevents from using standard display process # This prevents from using standard display process
list_body = list_body + \ list_body = list_body + \
('<td class=\"%s%s\">%s%s</td>' % (td_css, error_css, cell_body, error_message)) ('<td class=\"%s%s\">%s%s</td>' % (td_css, error_css, cell_body, error_message))
# Add item to list_result_item for list render format # Add item to list_result_item for list render format
if render_format == 'list': if render_format == 'list':
list_result_item.append(my_field._get_default(self.generate_field_key(), display_value, o)) list_result_item.append(my_field._get_default(self.generate_field_key(), display_value, o))
else: else:
# Check if this object provides a specific URL method # Check if url_columns defines a method to retrieve the URL.
url_method = getattr(o, 'getListItemUrl', None) url_method = None
if url_method is None: for column in url_columns:
if sql == column[0]:
url_method = getattr(o, column[1], '')
break
if url_method is not None:
try: try:
object_url = o.absolute_url() + \ object_url = url_method(brain = o, selection = selection)
'/view?selection_index=%s&selection_name=%s&reset=1' % (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))
except: except:
LOG('ListBox', 0, 'Could not evaluate url_method %s' % column[1], error=sys.exc_info())
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: else:
try: # Check if this object provides a specific URL method
object_url = url_method(alias, i, selection_name) url_method = getattr(o, 'getListItemUrl', None)
list_body = list_body + \ if url_method is None:
("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" % try:
(td_css, td_align, object_url, attribute_value)) object_url = o.absolute_url() + \
except: '/view?selection_index=%s&selection_name=%s&reset=1' % (i, selection_name)
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\"><a href=\"%s\">%s</a></td>" %
# Add item to list_result_item for list render format (td_css, td_align, object_url, attribute_value))
if render_format == 'list': list_result_item.append(attribute_value) except:
list_body = list_body + \
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) )
else:
try:
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:
list_body = list_body + \
("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) )
# Add item to list_result_item for list render format
if render_format == 'list': list_result_item.append(attribute_value)
list_body = list_body + '</tr>' list_body = list_body + '</tr>'
if render_format == 'list': if render_format == 'list':
list_result.append(list_result_item) list_result.append(list_result_item)
############################################################### ###############################################################
# #
# Build statistics # Build statistics
# #
############################################################### ###############################################################
# Call the stat method # Call the stat method
if show_stat: if show_stat:
kw['select_expression'] = select_expression kw['select_expression'] = select_expression
selection.edit( params = kw ) selection.edit( params = kw )
...@@ -1277,13 +1301,13 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1277,13 +1301,13 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
list_body += '<td class="Data" align="right">%.2f</td>' % value list_body += '<td class="Data" align="right">%.2f</td>' % value
else: else:
list_body += '<td class="Data">' + str(value) + '</td>' list_body += '<td class="Data">' + str(value) + '</td>'
if render_format == 'list': list_result_item.append(value) if render_format == 'list': list_result_item.append(value)
else: else:
list_body += '<td class="Data">&nbsp;</td>' list_body += '<td class="Data">&nbsp;</td>'
if render_format == 'list': list_result_item.append(None) if render_format == 'list': list_result_item.append(None)
except: except:
list_body += '<td class="Data">&nbsp;</td>' list_body += '<td class="Data">&nbsp;</td>'
if render_format == 'list': list_result_item.append(None) if render_format == 'list': list_result_item.append(None)
list_body += '</tr>' list_body += '</tr>'
list_html = header + selection_line + list_header + list_search + list_body + footer list_html = header + selection_line + list_header + list_search + list_body + footer
...@@ -1292,7 +1316,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1292,7 +1316,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if render_format == 'list': if render_format == 'list':
list_result.append(list_result_item) list_result.append(list_result_item)
return list_result return list_result
#Create DomainTree Selector and DomainTree box #Create DomainTree Selector and DomainTree box
if domain_tree: if domain_tree:
select_tree_options = '' select_tree_options = ''
...@@ -1514,14 +1538,14 @@ class ListBox(ZMIField): ...@@ -1514,14 +1538,14 @@ class ListBox(ZMIField):
validator = ListBoxValidatorInstance validator = ListBoxValidatorInstance
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareProtected('Access contents information', 'get_value') security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw): def get_value(self, id, **kw):
if id == 'default' and kw.get('render_format') in ('list', ): if id == 'default' and kw.get('render_format') in ('list', ):
return self.widget.render(self, self.generate_field_key() , None , kw.get('REQUEST'), render_format=kw.get('render_format')) return self.widget.render(self, self.generate_field_key() , None , kw.get('REQUEST'), render_format=kw.get('render_format'))
else: else:
return ZMIField.get_value(self, id, **kw) return ZMIField.get_value(self, id, **kw)
# Psyco # Psyco
import psyco import psyco
psyco.bind(ListBoxWidget.render) psyco.bind(ListBoxWidget.render)
......
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