[IMP] orm: rename/cleanup: get_xml_id* -> get_external_id*

bzr revid: odo@openerp.com-20110930222355-jtuo4z9dz995emxk
This commit is contained in:
Olivier Dony
2011-10-01 00:23:55 +02:00
parent bdf846b535
commit 0489f83a44
+25 -15
View File
@@ -4591,17 +4591,21 @@ class BaseModel(object):
return False
return True
def _get_xml_ids(self, cr, uid, ids, *args, **kwargs):
"""Find out the XML ID(s) of any database record.
def _get_external_ids(self, cr, uid, ids, *args, **kwargs):
"""Retrieve the External ID(s) of any database record.
**Synopsis**: ``_get_xml_ids(cr, uid, ids) -> { 'id': ['module.xml_id'] }``
:return: map of ids to the list of their fully qualified XML IDs
(empty list when there's none).
:return: map of ids to the list of their fully qualified External IDs
in the form ``module.key``, or an empty list when there's no External
ID for a record, e.g.::
{ 'id': ['module.ext_id', 'module.ext_id_bis'],
'id2': [] }
"""
model_data_obj = self.pool.get('ir.model.data')
data_ids = model_data_obj.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)])
data_results = model_data_obj.read(cr, uid, data_ids, ['module', 'name', 'res_id'])
ir_model_data = self.pool.get('ir.model.data')
data_ids = ir_model_data.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)])
data_results = ir_model_data.read(cr, uid, data_ids, ['module', 'name', 'res_id'])
result = {}
for id in ids:
# can't use dict.fromkeys() as the list would be shared!
@@ -4610,29 +4614,35 @@ class BaseModel(object):
result[record['res_id']].append('%(module)s.%(name)s' % record)
return result
def get_xml_id(self, cr, uid, ids, *args, **kwargs):
"""Find out the XML ID of any database record, if there
def get_external_id(self, cr, uid, ids, *args, **kwargs):
"""Retrieve the External ID of any database record, if there
is one. This method works as a possible implementation
for a function field, to be able to add it to any
model object easily, referencing it as ``osv.osv.get_xml_id``.
model object easily, referencing it as ``Model.get_external_id``.
When multiple XML IDs exist for a record, only one
When multiple External IDs exist for a record, only one
of them is returned (randomly).
**Synopsis**: ``get_xml_id(cr, uid, ids) -> { 'id': 'module.xml_id' }``
:return: map of ids to their fully qualified XML ID,
defaulting to an empty string when there's none
(to be usable as a function field).
(to be usable as a function field),
e.g.::
{ 'id': 'module.ext_id',
'id2': '' }
"""
results = self._get_xml_ids(cr, uid, ids)
for k, v in results.items():
for k, v in results.iteritems():
if results[k]:
results[k] = v[0]
else:
results[k] = ''
return results
# backwards compatibility
get_xml_id = get_external_id
_get_xml_ids = _get_external_ids
# Transience
def is_transient(self):
""" Return whether the model is transient.