Fix Pool.setup to re-allow extra_depends behavior

review898002
This commit is contained in:
Cédric Krier committed 2013-05-27 18:47:00 +02:00
1 parent 305ab64504
commit 8710f2fd99
5 files changed
+42 -21

No files matched your search

+8
View File
@@ -56,3 +56,11 @@ PoolMeta
The PoolMeta is a metaclass helper to setup __name__ on class to be registered
in the Pool.
========
PoolBase
========
.. class:: PoolBase
The base class of registered class that will be setup.
+5 -4
View File
@@ -7,7 +7,7 @@ import warnings
from trytond.model import fields
from trytond.error import WarningErrorMixin
from trytond.pool import Pool, PoolMeta
from trytond.pool import Pool, PoolBase
from trytond.pyson import PYSONEncoder
from trytond.transaction import Transaction
from trytond.url import URLMixin
@@ -16,17 +16,17 @@ from trytond.rpc import RPC
__all__ = ['Model']
class Model(WarningErrorMixin, URLMixin):
class Model(WarningErrorMixin, URLMixin, PoolBase):
"""
Define a model in Tryton.
"""
__metaclass__ = PoolMeta
_rec_name = 'name'
id = fields.Integer('ID', readonly=True)
@classmethod
def __setup__(cls):
super(Model, cls).__setup__()
cls.__rpc__ = {
'default_get': RPC(),
'fields_get': RPC(),
@@ -44,7 +44,7 @@ class Model(WarningErrorMixin, URLMixin):
@classmethod
def __post_setup__(cls):
pool = Pool()
super(Model, cls).__post_setup__()
# Set _fields
cls._fields = {}
@@ -104,6 +104,7 @@ class Model(WarningErrorMixin, URLMixin):
"""
Add model in ir.model and ir.model.field.
"""
super(Model, cls).__register__(module_name)
pool = Pool()
Translation = pool.get('ir.translation')
Property = pool.get('ir.property')
+21 -7
View File
@@ -6,7 +6,7 @@ from trytond.modules import load_modules, register_classes
from trytond.transaction import Transaction
import __builtin__
__all__ = ['Pool', 'PoolMeta']
__all__ = ['Pool', 'PoolMeta', 'PoolBase']
class PoolMeta(type):
@@ -18,6 +18,22 @@ class PoolMeta(type):
return new
class PoolBase(object):
__metaclass__ = PoolMeta
@classmethod
def __setup__(cls):
pass
@classmethod
def __post_setup__(cls):
pass
@classmethod
def __register__(cls, module_name):
pass
class Pool(object):
classes = {
@@ -62,6 +78,7 @@ class Pool(object):
for cls in classes:
mpool = Pool.classes[type_].setdefault(module, [])
assert cls not in mpool, cls
assert issubclass(cls.__class__, PoolMeta), cls
mpool.append(cls)
@classmethod
@@ -203,14 +220,11 @@ class Pool(object):
cls = type(cls.__name__, (cls, previous_cls), {})
except KeyError:
pass
if (not hasattr(cls, '__setup__')
and issubclass(cls.__class__, PoolMeta)):
if not issubclass(cls, PoolBase):
continue
else:
cls.__setup__()
cls.__setup__()
self.add(cls, type=type_)
classes[type_].append(cls)
for cls in classes[type_]:
if hasattr(cls, '__post_setup__'):
cls.__post_setup__()
cls.__post_setup__()
return classes
+3 -7
View File
@@ -22,7 +22,7 @@ except ImportError:
from genshi.filters import Translator
import lxml.etree
from trytond.config import CONFIG
from trytond.pool import Pool, PoolMeta
from trytond.pool import Pool, PoolBase
from trytond.transaction import Transaction
from trytond.url import URLMixin
from trytond.rpc import RPC
@@ -92,19 +92,15 @@ class TranslateFactory:
self.language = language
class Report(URLMixin):
__metaclass__ = PoolMeta
class Report(URLMixin, PoolBase):
@classmethod
def __setup__(cls):
super(Report, cls).__setup__()
cls.__rpc__ = {
'execute': RPC(),
}
@classmethod
def __register__(cls, module_name):
pass
@classmethod
def execute(cls, ids, data):
'''
+5 -3
View File
@@ -9,7 +9,7 @@ except ImportError:
import json
import copy
from trytond.pool import Pool, PoolMeta
from trytond.pool import Pool, PoolBase
from trytond.transaction import Transaction
from trytond.error import WarningErrorMixin
from trytond.url import URLMixin
@@ -142,13 +142,13 @@ class StateAction(StateTransition):
return Action.get_action_values(action.type, [action.id])[0]
class Wizard(WarningErrorMixin, URLMixin):
__metaclass__ = PoolMeta
class Wizard(WarningErrorMixin, URLMixin, PoolBase):
start_state = 'start'
end_state = 'end'
@classmethod
def __setup__(cls):
super(Wizard, cls).__setup__()
cls.__rpc__ = {
'create': RPC(readonly=False),
'delete': RPC(readonly=False),
@@ -163,6 +163,7 @@ class Wizard(WarningErrorMixin, URLMixin):
@classmethod
def __post_setup__(cls):
super(Wizard, cls).__post_setup__()
# Set states
cls.states = {}
for attr in dir(cls):
@@ -173,6 +174,7 @@ class Wizard(WarningErrorMixin, URLMixin):
@classmethod
def __register__(cls, module_name):
super(Wizard, cls).__register__(module_name)
pool = Pool()
Translation = pool.get('ir.translation')
cursor = Transaction().cursor