From 8710f2fd99a19bef4255217e279afa9afae6a173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 27 May 2013 18:47:00 +0200 Subject: [PATCH] Fix Pool.setup to re-allow extra_depends behavior review898002 --- doc/ref/pool.rst | 8 ++++++++ trytond/model/model.py | 9 +++++---- trytond/pool.py | 28 +++++++++++++++++++++------- trytond/report/report.py | 10 +++------- trytond/wizard/wizard.py | 8 +++++--- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/doc/ref/pool.rst b/doc/ref/pool.rst index 2881379e40..911a6fe7ed 100644 --- a/doc/ref/pool.rst +++ b/doc/ref/pool.rst @@ -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. diff --git a/trytond/model/model.py b/trytond/model/model.py index 27d01356e0..450bbe4f73 100644 --- a/trytond/model/model.py +++ b/trytond/model/model.py @@ -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') diff --git a/trytond/pool.py b/trytond/pool.py index 53749b527a..f57f3dccde 100644 --- a/trytond/pool.py +++ b/trytond/pool.py @@ -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 diff --git a/trytond/report/report.py b/trytond/report/report.py index c6478a86b5..e99be239e3 100644 --- a/trytond/report/report.py +++ b/trytond/report/report.py @@ -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): ''' diff --git a/trytond/wizard/wizard.py b/trytond/wizard/wizard.py index 1cb98cb246..015576cbdb 100644 --- a/trytond/wizard/wizard.py +++ b/trytond/wizard/wizard.py @@ -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