Commit e2f046c4 authored by Yusei Tahara's avatar Yusei Tahara

Improved to find appropriate proxy target and fixed a bug which

occured when obsolete variable remained in field.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15600 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2de113f8
...@@ -514,13 +514,17 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -514,13 +514,17 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
manage_FTPput = PUT manage_FTPput = PUT
#Methods for Proxify tab. #Methods for Proxify tab.
security.declareProtected('View management screens', 'getAllFormFieldList') security.declareProtected('View management screens', 'getFormFieldList')
def getAllFormFieldList(self): def getFormFieldList(self):
"""""" """
find fields and forms which name ends with 'FieldLibrary' in
same skin folder.
"""
form_list = [] form_list = []
def iterate(obj): def iterate(obj):
for i in obj.objectValues(): for i in obj.objectValues():
if i.meta_type=='ERP5 Form': if (i.meta_type=='ERP5 Form' and
i.getId().endswith('FieldLibrary')):
form_id = i.getId() form_id = i.getId()
form_path = '%s.%s' % (obj.getId(), form_id) form_path = '%s.%s' % (obj.getId(), form_id)
field_list = [] field_list = []
...@@ -528,15 +532,9 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -528,15 +532,9 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
'form_id':form_id, 'form_id':form_id,
'field_list':field_list}) 'field_list':field_list})
for field in i.objectValues(): for field in i.objectValues():
if field.meta_type=='ProxyField': field_type, proxy_flag = get_field_meta_type_and_proxy_flag(field)
template_field = field.getRecursiveTemplateField() if proxy_flag:
template_meta_type = getattr(template_field, field_type = '%s(Proxy)' % field_type
'meta_type', None)
field_type = '%s(Proxy)' % template_meta_type
proxy_flag = True
else:
field_type = field.meta_type
proxy_flag = False
field_list.append({'field_object':field, field_list.append({'field_object':field,
'field_type':field_type, 'field_type':field_type,
'proxy_flag':proxy_flag}) 'proxy_flag':proxy_flag})
...@@ -548,31 +546,109 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -548,31 +546,109 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
security.declareProtected('View management screens', 'getProxyableFieldList') security.declareProtected('View management screens', 'getProxyableFieldList')
def getProxyableFieldList(self, field, form_field_list=None): def getProxyableFieldList(self, field, form_field_list=None):
"""""" """"""
def extract_keyword(name):
return [i for i in name.split('_') if not i in ('my', 'default')]
def check_keyword_list(name, keyword_list):
count = 0
for i in keyword_list:
if i in name:
count += 1
return count/float(len(keyword_list))
def match(field_data):
if not field_data['field_type'].startswith(field.meta_type):
return 0
field_object = field_data['field_object']
if field_object.aq_base is field.aq_base:
return 0
field_id = field_object.getId()
if id_.startswith('my_') and not field_id.startswith('my_'):
return 0
return check_keyword_list(field_id, extract_keyword(id_))
def make_dict_list_append_function(dic, order_list):
def append(key, item):
if not key in order_list:
order_list.append(key)
dic[key] = []
dic[key].append(item)
return append
def add_default_field_library():
portal_url = getToolByName(self, 'portal_url')
portal = portal_url.getPortalObject()
portal_skins = getToolByName(self, 'portal_skins')
default_field_library_path = portal.getProperty('erp5_default_field_library_path', None)
if (not default_field_library_path or
len(default_field_library_path.split('.'))!=2):
return
skinfolder_id, form_id = default_field_library_path.split('.')
skinfolder = getattr(portal_skins, skinfolder_id, None)
default_field_library = getattr(skinfolder, form_id, None)
if default_field_library is None:
return
if not default_field_library_path in form_order:
for i in default_field_library.objectValues():
field_meta_type, proxy_flag = get_field_meta_type_and_proxy_flag(i)
if meta_type==field_meta_type:
if proxy_flag:
field_meta_type = '%s(Proxy' % field_meta_type
matched_item = {'form_id':form_id,
'field_type':field_meta_type,
'field_object':i,
'proxy_flag':proxy_flag,
'matched_rate':0
}
matched_append(default_field_library_path,
matched_item)
id_ = field.getId()
meta_type = field.meta_type meta_type = field.meta_type
matched = {} matched = {}
form_order = [] form_order = []
matched_append = make_dict_list_append_function(matched, form_order)
perfect_matched = {}
perfect_matched_form_order = []
perfect_matched_append = make_dict_list_append_function(perfect_matched, perfect_matched_form_order)
if form_field_list is None: if form_field_list is None:
form_field_list = self.getAllFormFieldList() form_field_list = self.getFormFieldList()
for i in form_field_list: for i in form_field_list:
for data in i['field_list']: for data in i['field_list']:
if data['field_type'].startswith(meta_type): tmp = []
matched_rate = match(data)
if matched_rate>=0.5:
form_path = i['form_path'] form_path = i['form_path']
form_id = i['form_id'] form_id = i['form_id']
field_type = data['field_type'] field_type = data['field_type']
field_object = data['field_object'] field_object = data['field_object']
if field.aq_base is field_object.aq_base:
continue
proxy_flag = data['proxy_flag'] proxy_flag = data['proxy_flag']
if not form_path in form_order:
form_order.append(form_path) matched_item = {'form_id':form_id,
matched[form_path] = []
matched[form_path].append({'form_id':form_id,
'field_type':field_type, 'field_type':field_type,
'field_object':field_object, 'field_object':field_object,
'proxy_flag':proxy_flag}) 'proxy_flag':proxy_flag,
'matched_rate':matched_rate
}
if matched_rate==1:
perfect_matched_append(form_path, matched_item)
elif not perfect_matched:
matched_append(form_path, matched_item)
if perfect_matched:
perfect_matched_form_order.sort()
return perfect_matched_form_order, perfect_matched
form_order.sort() form_order.sort()
add_default_field_library()
return form_order, matched return form_order, matched
security.declareProtected('Change Formulator Forms', 'proxifyField') security.declareProtected('Change Formulator Forms', 'proxifyField')
...@@ -655,14 +731,28 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -655,14 +731,28 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
if target_field.meta_type=='ProxyField': if target_field.meta_type=='ProxyField':
for i in new_values.keys(): for i in new_values.keys():
if (not i in target_field.delegated_list and if not i in target_field.delegated_list:
is_equal(target_field.get_recursive_orig_value(i), # obsolete variable check
new_values[i])): try:
target_field.get_recursive_orig_value(i)
except KeyError:
# then `i` is obsolete!
del new_values[i]
else:
if is_equal(target_field.get_recursive_orig_value(i),
new_values[i]):
del new_values[i] del new_values[i]
for i in new_tales: for i in new_tales:
if (not i in target_field.delegated_list and if not i in target_field.delegated_list:
is_equal(target_field.get_recursive_tales(i), # obsolete variable check
new_tales[i])): try:
target_field.get_recursive_tales(i)
except KeyError:
# then `i` is obsolete!
del new_tales[i]
else:
if is_equal(target_field.get_recursive_tales(i),
new_tales[i]):
del new_tales[i] del new_tales[i]
delegated_list = [] delegated_list = []
...@@ -682,6 +772,15 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -682,6 +772,15 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
psyco.bind(__call__) psyco.bind(__call__)
psyco.bind(_exec) psyco.bind(_exec)
# utility function
def get_field_meta_type_and_proxy_flag(field):
if field.meta_type=='ProxyField':
return field.getRecursiveTemplateField().meta_type, True
else:
return field.meta_type, False
# More optimizations # More optimizations
#psyco.bind(ERP5Field) #psyco.bind(ERP5Field)
# XXX Not useful, as we patch those methods in FormulatorPatch # XXX Not useful, as we patch those methods in FormulatorPatch
......
<dtml-var manage_page_header> <dtml-var manage_page_header>
<dtml-var manage_tabs> <dtml-var manage_tabs>
<dtml-let form_field_list=getAllFormFieldList> <dtml-let form_field_list=getFormFieldList>
<p class="form-help"> <p class="form-help">
Proxify non-proxy fields. Proxify non-proxy fields.
......
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