Commit 4fedae1e authored by Yoshinori Okuji's avatar Yoshinori Okuji

Change wrong names (i.e. selection_*), and add a workaround for a fixed bug in Selection.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1371 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1cb6b0d5
...@@ -45,8 +45,8 @@ from Acquisition import aq_base, aq_inner, aq_parent, aq_self ...@@ -45,8 +45,8 @@ from Acquisition import aq_base, aq_inner, aq_parent, aq_self
from zLOG import LOG from zLOG import LOG
import random import random
import md5 import md5
def getAsList(a): def getAsList(a):
l = [] l = []
for e in a: for e in a:
...@@ -56,34 +56,34 @@ def getAsList(a): ...@@ -56,34 +56,34 @@ def getAsList(a):
def makeTreeBody(form, root_dict, domain_path, depth, total_depth, unfolded_list, form_id, selection_name): def makeTreeBody(form, root_dict, domain_path, depth, total_depth, unfolded_list, form_id, selection_name):
""" """
This method builds a report tree This method builds a report tree
domain_path -- ('region', 'skill', 'group', 'group', 'region') domain_path -- ('region', 'skill', 'group', 'group', 'region')
root -- {'region': <instance>, 'group'; instance} root -- {'region': <instance>, 'group'; instance}
""" """
LOG('makeTreeBody root_dict', 0, str(root_dict)) LOG('makeTreeBody root_dict', 0, str(root_dict))
LOG('makeTreeBody domain_path', 0, str(domain_path)) LOG('makeTreeBody domain_path', 0, str(domain_path))
LOG('makeTreeBody unfolded_list', 0, str(unfolded_list)) LOG('makeTreeBody unfolded_list', 0, str(unfolded_list))
if total_depth is None: if total_depth is None:
total_depth = max(1, len(unfolded_list)) total_depth = max(1, len(unfolded_list))
if type(domain_path) is type('a'): domain_path = domain_path.split('/') if type(domain_path) is type('a'): domain_path = domain_path.split('/')
portal_categories = getattr(form, 'portal_categories', None) portal_categories = getattr(form, 'portal_categories', None)
portal_domains = getattr(form, 'portal_domains', None) portal_domains = getattr(form, 'portal_domains', None)
portal_object = form.portal_url.getPortalObject() portal_object = form.portal_url.getPortalObject()
if len(domain_path): if len(domain_path):
base_category = domain_path[0] base_category = domain_path[0]
else: else:
base_category = None base_category = None
if root_dict is None: if root_dict is None:
root_dict = {} root_dict = {}
is_empty_level = 1 is_empty_level = 1
while is_empty_level: while is_empty_level:
if not root_dict.has_key(base_category): if not root_dict.has_key(base_category):
root = None root = None
...@@ -101,15 +101,15 @@ def makeTreeBody(form, root_dict, domain_path, depth, total_depth, unfolded_list ...@@ -101,15 +101,15 @@ def makeTreeBody(form, root_dict, domain_path, depth, total_depth, unfolded_list
except KeyError: except KeyError:
root = None root = None
domain_path = () domain_path = ()
else: else:
root = root_dict[None] = root_dict[base_category] root = root_dict[None] = root_dict[base_category]
if len(domain_path) >= 1: if len(domain_path) >= 1:
domain_path = domain_path[1:] domain_path = domain_path[1:]
else: else:
domain_path = () domain_path = ()
is_empty_level = (len(root.objectIds()) == 0) and (domain_path is not ()) is_empty_level = (len(root.objectIds()) == 0) and (domain_path is not ())
if is_empty_level: base_category = domain_path[0] if is_empty_level: base_category = domain_path[0]
tree_body = '' tree_body = ''
if root is None: return tree_body if root is None: return tree_body
...@@ -132,24 +132,24 @@ def makeTreeBody(form, root_dict, domain_path, depth, total_depth, unfolded_list ...@@ -132,24 +132,24 @@ def makeTreeBody(form, root_dict, domain_path, depth, total_depth, unfolded_list
def makeTreeList(form, root_dict, report_path, depth, unfolded_list, form_id, selection_name, report_depth): def makeTreeList(form, root_dict, report_path, depth, unfolded_list, form_id, selection_name, report_depth):
""" """
(object, is_pure_summary, depth, is_open, select_domain_dict) (object, is_pure_summary, depth, is_open, select_domain_dict)
select_domain_dict is a dictionary of associative list of (id, domain) select_domain_dict is a dictionary of associative list of (id, domain)
""" """
if type(report_path) is type('a'): report_path = report_path.split('/') if type(report_path) is type('a'): report_path = report_path.split('/')
portal_categories = getattr(form, 'portal_categories', None) portal_categories = getattr(form, 'portal_categories', None)
portal_domains = getattr(form, 'portal_domains', None) portal_domains = getattr(form, 'portal_domains', None)
portal_object = form.portal_url.getPortalObject() portal_object = form.portal_url.getPortalObject()
if len(report_path): if len(report_path):
base_category = report_path[0] base_category = report_path[0]
else: else:
base_category = None base_category = None
if root_dict is None: if root_dict is None:
root_dict = {} root_dict = {}
is_empty_level = 1 is_empty_level = 1
while is_empty_level: while is_empty_level:
if not root_dict.has_key(base_category): if not root_dict.has_key(base_category):
root = None root = None
...@@ -167,16 +167,16 @@ def makeTreeList(form, root_dict, report_path, depth, unfolded_list, form_id, se ...@@ -167,16 +167,16 @@ def makeTreeList(form, root_dict, report_path, depth, unfolded_list, form_id, se
except KeyError: except KeyError:
root = None root = None
report_path = () report_path = ()
else: else:
root = root_dict[None] = root_dict[base_category] root = root_dict[None] = root_dict[base_category]
if len(report_path) >= 1: if len(report_path) >= 1:
report_path = report_path[1:] report_path = report_path[1:]
else: else:
report_path = () report_path = ()
is_empty_level = 0 # Stop infinite loop is_empty_level = 0 # Stop infinite loop
is_empty_level = (len(root.objectIds()) == 0) and (report_path is not ()) is_empty_level = (len(root.objectIds()) == 0) and (report_path is not ())
if is_empty_level: base_category = report_path[0] if is_empty_level: base_category = report_path[0]
tree_list = [] tree_list = []
if root is None: return tree_list if root is None: return tree_list
...@@ -190,7 +190,7 @@ def makeTreeList(form, root_dict, report_path, depth, unfolded_list, form_id, se ...@@ -190,7 +190,7 @@ def makeTreeList(form, root_dict, report_path, depth, unfolded_list, form_id, se
tree_list += makeTreeList(form, new_root_dict, report_path, depth + 1, unfolded_list, form_id, selection_name, report_depth) tree_list += makeTreeList(form, new_root_dict, report_path, depth + 1, unfolded_list, form_id, selection_name, report_depth)
else: else:
tree_list += [(o, 1, depth, 0, selection_domain)] # Summary (closed) tree_list += [(o, 1, depth, 0, selection_domain)] # Summary (closed)
return tree_list return tree_list
...@@ -446,8 +446,8 @@ class ListBoxWidget(Widget.Widget): ...@@ -446,8 +446,8 @@ class ListBoxWidget(Widget.Widget):
selection_name = field.get_value('selection_name') selection_name = field.get_value('selection_name')
portal_url_string = getToolByName(here, 'portal_url')() portal_url_string = getToolByName(here, 'portal_url')()
portal_categories = getattr(form, 'portal_categories', None) portal_categories = getattr(form, 'portal_categories', None)
portal_domains = getattr(form, 'portal_domains', None) portal_domains = getattr(form, 'portal_domains', None)
portal_object = form.portal_url.getPortalObject() portal_object = form.portal_url.getPortalObject()
#selection_name = REQUEST.get('selection_name',None) #selection_name = REQUEST.get('selection_name',None)
#if selection_name is None: #if selection_name is None:
# selection_name = str(random.randrange(1,2147483600)) # selection_name = str(random.randrange(1,2147483600))
...@@ -508,12 +508,12 @@ class ListBoxWidget(Widget.Widget): ...@@ -508,12 +508,12 @@ class ListBoxWidget(Widget.Widget):
# Filter non searchable items # Filter non searchable items
sort_list = [] sort_list = []
fix_sort = 0 fix_sort = 0
for (k , v) in selection.selection_sort_on: for (k , v) in selection.sort_on:
if k in sort_columns_id_list: if k in sort_columns_id_list:
sort_list.append((k,v)) sort_list.append((k,v))
else: else:
fix_sort = 1 fix_sort = 1
if fix_sort: selection.selection_sort_on = sort_list if fix_sort: selection.sort_on = sort_list
if not hasattr(selection, 'flat_list_mode'): if not hasattr(selection, 'flat_list_mode'):
selection.edit(flat_list_mode=(not (domain_tree or selection.edit(flat_list_mode=(not (domain_tree or
...@@ -525,7 +525,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -525,7 +525,7 @@ class ListBoxWidget(Widget.Widget):
# Display choosen by the user # Display choosen by the user
if selection.selection_flat_list_mode is not None: if selection.flat_list_mode is not None:
if selection.flat_list_mode == 1: if selection.flat_list_mode == 1:
domain_tree = 0 domain_tree = 0
report_tree = 0 report_tree = 0
...@@ -701,7 +701,8 @@ class ListBoxWidget(Widget.Widget): ...@@ -701,7 +701,8 @@ class ListBoxWidget(Widget.Widget):
selection_domain_current = selection.getDomainList() selection_domain_current = selection.getDomainList()
if len(selection_domain_current) > 0: if len(selection_domain_current) > 0:
root_dict = {} root_dict = {}
for domain in selection_domain_current: for domain in selection_domain_current:
if type(domain) != type(''): continue # XXX workaround for a past bug in Selection
root = None root = None
base_category = domain.split('/')[0] base_category = domain.split('/')[0]
if portal_categories is not None: if portal_categories is not None:
...@@ -715,12 +716,12 @@ class ListBoxWidget(Widget.Widget): ...@@ -715,12 +716,12 @@ class ListBoxWidget(Widget.Widget):
root_dict[None] = portal_object.restrictedTraverse(domain) root_dict[None] = portal_object.restrictedTraverse(domain)
except KeyError: except KeyError:
root = None root = None
LOG('domain_tree root aq_parent', 0, str(root_dict[base_category].aq_parent)) #LOG('domain_tree root aq_parent', 0, str(root_dict[base_category].aq_parent))
selection.edit(domain = DomainSelection(domain_dict = root_dict)) selection.edit(domain = DomainSelection(domain_dict = root_dict))
LOG('selection.domain', 0, str(selection.domain.__dict__)) #LOG('selection.domain', 0, str(selection.domain.__dict__))
else: else:
selection.edit(domain = None) selection.edit(domain = None)
#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__))))
############################################################### ###############################################################
...@@ -767,16 +768,16 @@ class ListBoxWidget(Widget.Widget): ...@@ -767,16 +768,16 @@ class ListBoxWidget(Widget.Widget):
selection_report_path = selection.getReportPath() selection_report_path = selection.getReportPath()
if report_depth is not None: if report_depth is not None:
selection_report_current = () selection_report_current = ()
else: else:
selection_report_current = selection.getReportList() selection_report_current = selection.getReportList()
report_tree_list = makeTreeList(form, None, selection_report_path, report_tree_list = makeTreeList(form, None, selection_report_path,
0, selection_report_current, form.id, selection_name, report_depth ) 0, selection_report_current, form.id, selection_name, report_depth )
# Update report list if report_depth was specified # Update report list if report_depth was specified
if report_depth is not None: if report_depth is not None:
report_list = map(lambda s:s[0].getRelativeUrl(), report_tree_list) report_list = map(lambda s:s[0].getRelativeUrl(), report_tree_list)
selection.edit(report_list=report_list) selection.edit(report_list=report_list)
report_sections = [] report_sections = []
#LOG("Report Tree",0,str(report_tree_list)) #LOG("Report Tree",0,str(report_tree_list))
for s in report_tree_list: for s in report_tree_list:
...@@ -826,9 +827,9 @@ class ListBoxWidget(Widget.Widget): ...@@ -826,9 +827,9 @@ class ListBoxWidget(Widget.Widget):
object_list = here.portal_selections.getSelectionValueList(selection_name, context=here, REQUEST=REQUEST) object_list = here.portal_selections.getSelectionValueList(selection_name, context=here, REQUEST=REQUEST)
# # PERFORMANCE ? is len(object_list) fast enough ? # # PERFORMANCE ? is len(object_list) fast enough ?
report_sections += [ (None, 0, s[2], object_list, len(object_list), s[3], s[4]) ] report_sections += [ (None, 0, s[2], object_list, len(object_list), s[3], s[4]) ]
# Reset original value # Reset original value
selection.edit(report = None) selection.edit(report = None)
else: else:
selection.edit( params = kw, report = None ) selection.edit( params = kw, report = None )
#LOG('ListBox 612', 0, str((selection_name, selection.__dict__))) #LOG('ListBox 612', 0, str((selection_name, selection.__dict__)))
...@@ -1159,16 +1160,16 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1159,16 +1160,16 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
current_section = report_sections[section_index] current_section = report_sections[section_index]
elif len(report_sections): elif len(report_sections):
current_section = report_sections[0] current_section = report_sections[0]
else: else:
current_section = None current_section = None
if current_section is not None: if current_section is not None:
current_section_size = current_section[4] current_section_size = current_section[4]
object_list = current_section[3] object_list = current_section[3]
#if current_section is not None: #if current_section is not None:
for i in range(start,end): for i in range(start,end):
# Set the selection index. # Set the selection index.
selection.edit(index = i) 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]
...@@ -1176,23 +1177,23 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1176,23 +1177,23 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
current_section = report_sections[section_index] current_section = report_sections[section_index]
current_section_size = current_section[4] current_section_size = current_section[4]
object_list = current_section[3] object_list = current_section[3]
is_summary = current_section[1] # Update summary type is_summary = current_section[1] # Update summary type
list_body = list_body + '<tr>' list_body = list_body + '<tr>'
o = object_list[i - current_section_base_index] # FASTER PERFORMANCE o = object_list[i - current_section_base_index] # FASTER PERFORMANCE
real_o = None real_o = None
# Define the CSS # Define the CSS
if not (i - start) % 2: if not (i - start) % 2:
td_css = 'DataA' td_css = 'DataA'
else: else:
td_css = 'DataB' td_css = 'DataB'
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"/>
""" % ( getattr(o, 'uid', '') , field.id ) # What happens if we list instances which are not instances of Base XXX """ % ( getattr(o, 'uid', '') , field.id ) # What happens if we list instances which are not instances of Base XXX
section_char = '' section_char = ''
if render_format == 'list': list_result_item = [] # Start a new item for list render format if render_format == 'list': list_result_item = [] # Start a new item for list render format
if report_tree: if report_tree:
...@@ -1215,7 +1216,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1215,7 +1216,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
"""<td class="%s" align="left" valign="middle"><a href="portal_selections/unfoldReport?report_url=%s&form_id=%s&list_selection_name=%s">%s%s%s</a></td> """<td class="%s" align="left" valign="middle"><a href="portal_selections/unfoldReport?report_url=%s&form_id=%s&list_selection_name=%s">%s%s%s</a></td>
""" % (td_css, getattr(current_section[3][0],'domain_url',''), form.id, selection_name, '&nbsp;&nbsp;' * current_section[2], section_char, section_name) """ % (td_css, getattr(current_section[3][0],'domain_url',''), form.id, selection_name, '&nbsp;&nbsp;' * current_section[2], section_char, section_name)
if render_format == 'list': list_result_item.append(section_name) if render_format == 'list': list_result_item.append(section_name)
if select: if select:
if o.uid in checked_uids: if o.uid in checked_uids:
selected = 'checked' selected = 'checked'
...@@ -1382,7 +1383,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1382,7 +1383,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) )
# Add item to list_result_item for list render format # Add item to list_result_item for list render format
if render_format == 'list': list_result_item.append(attribute_value) 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)
......
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