[IMP] move browse_record to logging, __init__ docstring to sphinx info fields

bzr revid: xmo@openerp.com-20120125113429-6stglci05rxpfo5j
This commit is contained in:
Xavier Morel
2012-01-25 12:34:29 +01:00
parent e5ab103d2a
commit d181a5e7ac
+15 -15
View File
@@ -306,21 +306,23 @@ class browse_record(object):
user_rec = uobj.browse(cr, uid, 104)
name = user_rec.name
"""
logger = netsvc.Logger()
def __init__(self, cr, uid, id, table, cache, context=None, list_class=None, fields_process=None):
def __init__(self, cr, uid, id, table, cache, context=None,
list_class=browse_record_list, fields_process=None):
"""
@param cache a dictionary of model->field->data to be shared accross browse
objects, thus reducing the SQL read()s . It can speed up things a lot,
but also be disastrous if not discarded after write()/unlink() operations
@param table the object (inherited from orm)
@param context dictionary with an optional context
:param table: the browsed object (inherited from orm)
:param dict cache: a dictionary of model->field->data to be shared
across browse objects, thus reducing the SQL
read()s. It can speed up things a lot, but also be
disastrous if not discarded after write()/unlink()
operations
:param dict context: dictionary with an optional context
"""
if fields_process is None:
fields_process = {}
if context is None:
context = {}
self._list_class = list_class or browse_record_list
self._list_class = list_class
self._cr = cr
self._uid = uid
self._id = id
@@ -328,7 +330,7 @@ class browse_record(object):
self._model = table
self._table_name = self._table._name
self.__logger = logging.getLogger(
'osv.browse_record.' + self._table_name)
'openerp.osv.orm.browse_record.' + self._table_name)
self._context = context
self._fields_process = fields_process
@@ -369,7 +371,7 @@ class browse_record(object):
return attr
else:
error_msg = "Field '%s' does not exist in object '%s'" % (name, self)
self.logger.notifyChannel("browse_record", netsvc.LOG_WARNING, error_msg)
self.__logger.warn(error_msg)
raise KeyError(error_msg)
# if the field is a classic one or a many2one, we'll fetch all classic and many2one fields
@@ -464,10 +466,8 @@ class browse_record(object):
if not name in self._data[self._id]:
# How did this happen? Could be a missing model due to custom fields used too soon, see above.
self.logger.notifyChannel("browse_record", netsvc.LOG_ERROR,
"Fields to fetch: %s, Field values: %s"%(field_names, field_values))
self.logger.notifyChannel("browse_record", netsvc.LOG_ERROR,
"Cached: %s, Table: %s"%(self._data[self._id], self._table))
self.__logger.error("Fields to fetch: %s, Field values: %s", field_names, field_values)
self.__logger.error("Cached: %s, Table: %s", self._data[self._id], self._table)
raise KeyError(_('Unknown attribute %s in %s ') % (name, self))
return self._data[self._id][name]
@@ -4213,7 +4213,7 @@ class BaseModel(object):
"""Fetch records as objects allowing to use dot notation to browse fields and relations
:param cr: database cursor
:param user: current user id
:param uid: current user id
:param select: id or list of ids.
:param context: context arguments, like lang, time zone
:rtype: object or list of objects requested