[IMP] simplify traversal of fields: remove unused enumerate, don't create a second collection for the keys (instead just sort the dict.iteritems() result correctly)
bzr revid: xmo@openerp.com-20110831122101-1sy2uruu9e8bmrv6
This commit is contained in:
parent
c57b768d87
commit
0e302b7cd5
|
@ -1088,41 +1088,40 @@ class Export(View):
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def get_fields(self, req, model, prefix='', name= '',
|
def get_fields(self, req, model, prefix='', name= '',
|
||||||
import_compat=True, field_parent_type=None):
|
import_compat=True, field_parent_type=None):
|
||||||
fields = self.fields_get(req, model)
|
|
||||||
|
|
||||||
|
fields = self.fields_get(req, model)
|
||||||
if import_compat and field_parent_type == "many2one":
|
if import_compat and field_parent_type == "many2one":
|
||||||
fields = {}
|
fields = {}
|
||||||
|
|
||||||
fields.update({'id': {'string': 'ID'}, '.id': {'string': 'Database ID'}})
|
fields.update({'id': {'string': 'ID'}, '.id': {'string': 'Database ID'}})
|
||||||
records = []
|
|
||||||
fields_order = fields.keys()
|
|
||||||
fields_order.sort(lambda x,y: -cmp(fields[x].get('string', ''), fields[y].get('string', '')))
|
|
||||||
|
|
||||||
for index, field in enumerate(fields_order):
|
fields_seq = sorted(fields.iteritems(),
|
||||||
value = fields[field]
|
key=lambda field: field[1].get('string', ''), reverse=True)
|
||||||
if import_compat and value.get('readonly'):
|
|
||||||
|
records = []
|
||||||
|
for field_name, field in fields_seq:
|
||||||
|
if import_compat and field.get('readonly'):
|
||||||
ok = False
|
ok = False
|
||||||
for sl in value.get('states', {}).values():
|
for sl in field.get('states', {}).values():
|
||||||
for s in sl:
|
for s in sl:
|
||||||
ok = ok or (s==['readonly',False])
|
ok = ok or (s==['readonly',False])
|
||||||
if not ok: continue
|
if not ok: continue
|
||||||
|
|
||||||
id = prefix + (prefix and '/'or '') + field
|
id = prefix + (prefix and '/'or '') + field_name
|
||||||
nm = name + (name and '/' or '') + value['string']
|
nm = name + (name and '/' or '') + field['string']
|
||||||
record = {'id': id, 'string': nm, 'children': [],
|
record = {'id': id, 'string': nm, 'children': [],
|
||||||
'field_type': value.get('type', False),
|
'field_type': field.get('type', False),
|
||||||
'required': value.get('required', False)}
|
'required': field.get('required', False)}
|
||||||
records.append(record)
|
records.append(record)
|
||||||
|
|
||||||
if len(nm.split('/')) < 3 and value.get('relation'):
|
if len(nm.split('/')) < 3 and field.get('relation'):
|
||||||
if import_compat:
|
if import_compat:
|
||||||
ref = value.pop('relation')
|
ref = field.pop('relation')
|
||||||
cfields = self.fields_get(req, ref)
|
cfields = self.fields_get(req, ref)
|
||||||
if value['type'] == 'many2many':
|
if field['type'] == 'many2many':
|
||||||
record['children'] = []
|
record['children'] = []
|
||||||
record['params'] = {'model': ref, 'prefix': id, 'name': nm}
|
record['params'] = {'model': ref, 'prefix': id, 'name': nm}
|
||||||
|
|
||||||
elif value['type'] == 'many2one':
|
elif field['type'] == 'many2one':
|
||||||
record['children'] = [id + '/id', id + '/.id']
|
record['children'] = [id + '/id', id + '/.id']
|
||||||
record['params'] = {'model': ref, 'prefix': id, 'name': nm}
|
record['params'] = {'model': ref, 'prefix': id, 'name': nm}
|
||||||
|
|
||||||
|
@ -1137,7 +1136,7 @@ class Export(View):
|
||||||
record['children'] = children or []
|
record['children'] = children or []
|
||||||
record['params'] = {'model': ref, 'prefix': id, 'name': nm}
|
record['params'] = {'model': ref, 'prefix': id, 'name': nm}
|
||||||
else:
|
else:
|
||||||
ref = value.pop('relation')
|
ref = field.pop('relation')
|
||||||
cfields = self.fields_get(req, ref)
|
cfields = self.fields_get(req, ref)
|
||||||
cfields_order = cfields.keys()
|
cfields_order = cfields.keys()
|
||||||
cfields_order.sort(lambda x,y: -cmp(cfields[x].get('string', ''), cfields[y].get('string', '')))
|
cfields_order.sort(lambda x,y: -cmp(cfields[x].get('string', ''), cfields[y].get('string', '')))
|
||||||
|
|
Loading…
Reference in New Issue