[IMP] registry: add convenience operators ('in' and 'iter') on registry objects

bzr revid: rco@openerp.com-20130329135853-woi26cl2yiofv7h2
This commit is contained in:
Raphael Collet 2013-03-29 14:58:53 +01:00
parent e7bd5fd40d
commit d3657d858f
1 changed files with 10 additions and 2 deletions

View File

@ -94,13 +94,21 @@ class Registry(object):
self.models[model_name] = model
def get(self, model_name):
""" Return a model for a given name or None if it doesn't exist."""
""" Return the model with the given name or None if it doesn't exist."""
return self.models.get(model_name)
def __getitem__(self, model_name):
""" Return a model for a given name or raise KeyError if it doesn't exist."""
""" Return the model with the given name or raise KeyError if it doesn't exist."""
return self.models[model_name]
def __contains__(self, model_name):
""" Test whether the model with the given name exists. """
return model_name in self.models
def __iter__(self):
""" Return an iterator over all model names. """
return iter(self.models)
def load(self, cr, module):
""" Load a given module in the registry.