[FIX] mutable default in osv
lp bug: https://launchpad.net/bugs/525808 fixed bzr revid: ls@numerigraphe.fr-20100722134948-5axugpkr0nwbda2a
This commit is contained in:
parent
f9b199fa5f
commit
70fd90d33b
|
@ -63,7 +63,7 @@ class _column(object):
|
|||
_symbol_set = (_symbol_c, _symbol_f)
|
||||
_symbol_get = None
|
||||
|
||||
def __init__(self, string='unknown', required=False, readonly=False, domain=None, context={}, states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args):
|
||||
def __init__(self, string='unknown', required=False, readonly=False, domain=None, context=None, states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args):
|
||||
self.states = states or {}
|
||||
self.string = string
|
||||
self.readonly = readonly
|
||||
|
@ -75,7 +75,7 @@ class _column(object):
|
|||
self.ondelete = ondelete
|
||||
self.translate = translate
|
||||
self._domain = domain or []
|
||||
self._context = context
|
||||
self._context = context or {}
|
||||
self.write = False
|
||||
self.read = False
|
||||
self.view_load = 0
|
||||
|
@ -375,7 +375,7 @@ class one2many(_column):
|
|||
assert(self.change_default != True)
|
||||
|
||||
def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
|
||||
if not context:
|
||||
if context is None:
|
||||
context = {}
|
||||
if self._context:
|
||||
context = context.copy()
|
||||
|
@ -734,7 +734,7 @@ class function(_column):
|
|||
|
||||
class related(function):
|
||||
|
||||
def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}):
|
||||
def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None):
|
||||
self._field_get2(cr, uid, obj, context)
|
||||
i = len(self._arg)-1
|
||||
sarg = name
|
||||
|
@ -750,7 +750,7 @@ class related(function):
|
|||
i -= 1
|
||||
return [(self._arg[0], 'in', sarg)]
|
||||
|
||||
def _fnct_write(self,obj,cr, uid, ids, field_name, values, args, context=None):
|
||||
def _fnct_write(self, obj, cr, uid, ids, field_name, values, args, context=None):
|
||||
if values and field_name:
|
||||
self._field_get2(cr, uid, obj, context)
|
||||
relation = obj._name
|
||||
|
@ -835,7 +835,7 @@ class related(function):
|
|||
# TODO: improve here to change self.store = {...} according to related objects
|
||||
pass
|
||||
|
||||
def _field_get2(self, cr, uid, obj, context={}):
|
||||
def _field_get2(self, cr, uid, obj, context=None):
|
||||
if self._relations:
|
||||
return
|
||||
obj_name = obj._name
|
||||
|
@ -855,10 +855,10 @@ class related(function):
|
|||
# ---------------------------------------------------------
|
||||
|
||||
class dummy(function):
|
||||
def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}):
|
||||
def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None):
|
||||
return []
|
||||
|
||||
def _fnct_write(self,obj,cr, uid, ids, field_name, values, args, context=None):
|
||||
def _fnct_write(self, obj, cr, uid, ids, field_name, values, args, context=None):
|
||||
return False
|
||||
|
||||
def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None):
|
||||
|
|
|
@ -126,13 +126,11 @@ class browse_record_list(list):
|
|||
class browse_record(object):
|
||||
logger = netsvc.Logger()
|
||||
|
||||
def __init__(self, cr, uid, id, table, cache, context=None, list_class = None, fields_process={}):
|
||||
def __init__(self, cr, uid, id, table, cache, context=None, list_class=None, fields_process=None):
|
||||
'''
|
||||
table : the object (inherited from orm)
|
||||
context : dictionary with an optional context
|
||||
'''
|
||||
if not context:
|
||||
context = {}
|
||||
self._list_class = list_class or browse_record_list
|
||||
self._cr = cr
|
||||
self._uid = uid
|
||||
|
@ -141,8 +139,8 @@ class browse_record(object):
|
|||
self._table_name = self._table._name
|
||||
self.__logger = logging.getLogger(
|
||||
'osv.browse_record.' + self._table_name)
|
||||
self._context = context
|
||||
self._fields_process = fields_process
|
||||
self._context = context or {}
|
||||
self._fields_process = fields_process or {}
|
||||
|
||||
cache.setdefault(table._name, {})
|
||||
self._data = cache[table._name]
|
||||
|
@ -400,14 +398,16 @@ class orm_template(object):
|
|||
context=context
|
||||
)
|
||||
|
||||
def view_init(self, cr , uid , fields_list, context=None):
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
"""Override this method to do specific things when a view on the object is opened."""
|
||||
pass
|
||||
|
||||
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None):
|
||||
raise NotImplementedError(_('The read_group method is not implemented on this object !'))
|
||||
|
||||
def _field_create(self, cr, context={}):
|
||||
def _field_create(self, cr, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
cr.execute("SELECT id FROM ir_model WHERE model=%s", (self._name,))
|
||||
if not cr.rowcount:
|
||||
cr.execute('SELECT nextval(%s)', ('ir_model_id_seq',))
|
||||
|
@ -492,8 +492,8 @@ class orm_template(object):
|
|||
continue
|
||||
cr.commit()
|
||||
|
||||
def _auto_init(self, cr, context={}):
|
||||
self._field_create(cr, context)
|
||||
def _auto_init(self, cr, context=None):
|
||||
self._field_create(cr, context=context)
|
||||
|
||||
def __init__(self, cr):
|
||||
if not self._name and not hasattr(self, '_inherit'):
|
||||
|
@ -509,7 +509,7 @@ class orm_template(object):
|
|||
if not self._table:
|
||||
self._table = self._name.replace('.', '_')
|
||||
|
||||
def browse(self, cr, uid, select, context=None, list_class=None, fields_process={}):
|
||||
def browse(self, cr, uid, select, context=None, list_class=None, fields_process=None):
|
||||
"""
|
||||
Fetch records as objects allowing to use dot notation to browse fields and relations
|
||||
|
||||
|
@ -520,8 +520,6 @@ class orm_template(object):
|
|||
:rtype: object or list of objects requested
|
||||
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
self._list_class = list_class or browse_record_list
|
||||
cache = {}
|
||||
# need to accepts ints and longs because ids coming from a method
|
||||
|
@ -529,7 +527,7 @@ class orm_template(object):
|
|||
if isinstance(select, (int, long)):
|
||||
return browse_record(cr, uid, select, self, cache, context=context, list_class=self._list_class, fields_process=fields_process)
|
||||
elif isinstance(select, list):
|
||||
return self._list_class([browse_record(cr, uid, id, self, cache, context=context, list_class=self._list_class, fields_process=fields_process) for id in select], context)
|
||||
return self._list_class([browse_record(cr, uid, id, self, cache, context=context, list_class=self._list_class, fields_process=fields_process) for id in select], context=context)
|
||||
else:
|
||||
return browse_null()
|
||||
|
||||
|
@ -1018,7 +1016,7 @@ class orm_template(object):
|
|||
def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
|
||||
raise NotImplementedError(_('The read method is not implemented on this object !'))
|
||||
|
||||
def get_invalid_fields(self,cr,uid):
|
||||
def get_invalid_fields(self, cr, uid):
|
||||
return list(self._invalids)
|
||||
|
||||
def _validate(self, cr, uid, ids, context=None):
|
||||
|
@ -1409,14 +1407,14 @@ class orm_template(object):
|
|||
|
||||
return arch
|
||||
|
||||
def __get_default_search_view(self, cr, uid, context={}):
|
||||
def __get_default_search_view(self, cr, uid, context=None):
|
||||
|
||||
def encode(s):
|
||||
if isinstance(s, unicode):
|
||||
return s.encode('utf8')
|
||||
return s
|
||||
|
||||
view = self.fields_view_get(cr, uid, False, 'form', context)
|
||||
view = self.fields_view_get(cr, uid, False, 'form', context=context)
|
||||
|
||||
root = etree.fromstring(encode(view['arch']))
|
||||
res = etree.XML("<search string='%s'></search>" % root.get("string", ""))
|
||||
|
@ -2228,7 +2226,9 @@ class orm(orm_template):
|
|||
if column['attnotnull']:
|
||||
cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, column['attname']))
|
||||
|
||||
def _auto_init(self, cr, context={}):
|
||||
def _auto_init(self, cr, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
store_compute = False
|
||||
logger = netsvc.Logger()
|
||||
create = False
|
||||
|
|
Loading…
Reference in New Issue