[REF] osv: replace isinstance(m,osv_memory) by m.is_transient().
bzr revid: vmt@openerp.com-20110816095755-2g5cblolcvchtewx
This commit is contained in:
parent
7e9c72d041
commit
51117db344
|
@ -63,7 +63,7 @@ class ir_model(osv.osv):
|
|||
models = self.browse(cr, uid, ids, context=context)
|
||||
res = dict.fromkeys(ids)
|
||||
for model in models:
|
||||
res[model.id] = isinstance(self.pool.get(model.model), osv.osv_memory)
|
||||
res[model.id] = self.pool.get(model.model).is_transient()
|
||||
return res
|
||||
|
||||
def _search_osv_memory(self, cr, uid, model, name, domain, context=None):
|
||||
|
@ -483,7 +483,7 @@ class ir_model_access(osv.osv):
|
|||
# osv_memory objects can be read by everyone, as they only return
|
||||
# results that belong to the current user (except for superuser)
|
||||
model_obj = self.pool.get(model_name)
|
||||
if isinstance(model_obj, osv.osv_memory):
|
||||
if model_obj.is_transient():
|
||||
return True
|
||||
|
||||
# We check if a specific rule exists
|
||||
|
|
|
@ -68,7 +68,7 @@ class ir_rule(osv.osv):
|
|||
return res
|
||||
|
||||
def _check_model_obj(self, cr, uid, ids, context=None):
|
||||
return not any(isinstance(self.pool.get(rule.model_id.model), osv.osv_memory) for rule in self.browse(cr, uid, ids, context))
|
||||
return not any(self.pool.get(rule.model_id.model).is_transient() for rule in self.browse(cr, uid, ids, context))
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128, select=1),
|
||||
|
|
|
@ -339,16 +339,16 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
|
|||
cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""")
|
||||
for (model, name) in cr.fetchall():
|
||||
model_obj = pool.get(model)
|
||||
if model_obj and not isinstance(model_obj, osv.osv.osv_memory):
|
||||
logger.notifyChannel('init', netsvc.LOG_WARNING, 'object %s (%s) has no access rules!' % (model, name))
|
||||
if model_obj and not model_obj.is_transient():
|
||||
logger.notifyChannel('init', netsvc.LOG_WARNING, 'The model %s (%s) has no access rules!' % (model, name))
|
||||
|
||||
# Temporary warning while we remove access rights on osv_memory objects, as they have
|
||||
# been replaced by owner-only access rights
|
||||
cr.execute("""select distinct mod.model, mod.name from ir_model_access acc, ir_model mod where acc.model_id = mod.id""")
|
||||
for (model, name) in cr.fetchall():
|
||||
model_obj = pool.get(model)
|
||||
if isinstance(model_obj, osv.osv.osv_memory):
|
||||
logger.notifyChannel('init', netsvc.LOG_WARNING, 'In-memory object %s (%s) should not have explicit access rules!' % (model, name))
|
||||
if model_obj.is_transient():
|
||||
logger.notifyChannel('init', netsvc.LOG_WARNING, 'The transient model %s (%s) should not have explicit access rules!' % (model, name))
|
||||
|
||||
cr.execute("SELECT model from ir_model")
|
||||
for (model,) in cr.fetchall():
|
||||
|
|
|
@ -4472,5 +4472,13 @@ class Model(object):
|
|||
results[k] = ''
|
||||
return results
|
||||
|
||||
def is_transient(self):
|
||||
""" Return whether the model is transient.
|
||||
|
||||
See TransientModel.
|
||||
|
||||
"""
|
||||
return self._transient
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -202,7 +202,12 @@ class object_proxy(netsvc.Service):
|
|||
|
||||
|
||||
class osv_memory(Model):
|
||||
""" Deprecated class. """
|
||||
""" Model for transient records.
|
||||
|
||||
A TransientModel works similarly to a regular Model but the assiociated
|
||||
records will be cleaned automatically from the database after some time.
|
||||
|
||||
"""
|
||||
__metaclass__ = MetaModel
|
||||
_register = False # Set to false if the model shouldn't be automatically discovered.
|
||||
_transient = True
|
||||
|
@ -212,7 +217,7 @@ class osv_memory(Model):
|
|||
|
||||
def __init__(self, pool, cr):
|
||||
super(osv_memory, self).__init__(pool, cr)
|
||||
self.check_id = 0
|
||||
self.check_count = 0
|
||||
self._max_count = config.get('osv_memory_count_limit')
|
||||
self._max_hours = config.get('osv_memory_age_limit')
|
||||
cr.execute('delete from wkf_instance where res_type=%s', (self._name,))
|
||||
|
@ -243,16 +248,18 @@ class osv_memory(Model):
|
|||
self.unlink(cr, openerp.SUPERUSER, ids)
|
||||
|
||||
def vacuum(self, cr, uid, force=False):
|
||||
""" Run the vacuum cleaner, i.e. unlink old records from the
|
||||
virtual osv_memory tables if the "max count" or "max age" conditions are enabled
|
||||
and have been reached. This method can be called very often (e.g. everytime a record
|
||||
is created), but will only actually trigger the cleanup process once out of
|
||||
"_check_time" times (by default once out of 20 calls)."""
|
||||
self.check_id += 1
|
||||
if (not force) and (self.check_id % self._check_time):
|
||||
self.check_id = 0
|
||||
""" Clean the TransientModel records.
|
||||
|
||||
This unlinks old records from the transient model tables whenever the
|
||||
"_max_count" or "_max_age" conditions (if any) are reached.
|
||||
Actual cleaning will happen only once every "_check_time" calls.
|
||||
This means this method can be called frequently called (e.g. whenever
|
||||
a new record is created).
|
||||
"""
|
||||
self.check_count += 1
|
||||
if (not force) and (self.check_count % self._check_time):
|
||||
self.check_count = 0
|
||||
return True
|
||||
tounlink = []
|
||||
|
||||
# Age-based expiration
|
||||
if self._max_hours:
|
||||
|
|
|
@ -305,7 +305,7 @@ class YamlInterpreter(object):
|
|||
import openerp.osv as osv
|
||||
record, fields = node.items()[0]
|
||||
model = self.get_model(record.model)
|
||||
if isinstance(model, osv.osv.osv_memory):
|
||||
if model.is_transient():
|
||||
record_dict=self.create_osv_memory_record(record, fields)
|
||||
else:
|
||||
self.validate_xml_id(record.id)
|
||||
|
|
Loading…
Reference in New Issue