From 79b33ad3663b91ad7816cf55737faa28603fca70 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 25 Sep 2008 00:00:58 +0000 Subject: 355: Object.set_api() now creates Object.params namespace by merging takes_params and properties together intelegintly --- ipalib/frontend.py | 27 +++++++++++++++++---------- ipalib/tests/test_frontend.py | 2 ++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 6c5f8c76b..6aa21eb80 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -520,21 +520,12 @@ class Object(plugable.Plugin): params = None takes_params = tuple() - def __create_params(self): - props = self.properties.__todict__() - for spec in self.takes_params: - if type(spec) is str and spec.rstrip('?*+') in props: - yield props.pop(spec.rstrip('?*+')).param - else: - yield create_param(spec) - - def set_api(self, api): super(Object, self).set_api(api) self.methods = self.__create_namespace('Method') self.properties = self.__create_namespace('Property') self.params = plugable.NameSpace( - (create_param(p) for p in self.takes_params), sort=False + self.__create_params(), sort=False ) def __create_namespace(self, name): @@ -547,6 +538,22 @@ class Object(plugable.Plugin): if proxy.obj_name == self.name: yield proxy.__clone__('attr_name') + def __create_params(self): + props = self.properties.__todict__() + for spec in self.takes_params: + if type(spec) is str and spec.rstrip('?*+') in props: + yield props.pop(spec.rstrip('?*+')).param + else: + yield create_param(spec) + def get_key(p): + if p.param.required: + if p.param.default_from is None: + return 0 + return 1 + return 2 + for prop in sorted(props.itervalues(), key=get_key): + yield prop.param + class Attribute(plugable.Plugin): __public__ = frozenset(( diff --git a/ipalib/tests/test_frontend.py b/ipalib/tests/test_frontend.py index f6bca9b9d..ec7cccd61 100644 --- a/ipalib/tests/test_frontend.py +++ b/ipalib/tests/test_frontend.py @@ -788,6 +788,8 @@ class test_Object(ClassChecker): self.name = '%s_%s' % (obj_name, attr_name) else: self.name = name + self.param = frontend.create_param(attr_name) + def __clone__(self, attr_name): return self.__class__( self.obj_name, -- cgit