From 1af89d0daa80062b6ae3fc00de3d4fcc10e1129e Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Wed, 5 Jan 2011 10:07:23 -0500 Subject: Retype (when cloning) Flag parameters to Bool for search commands. Flag parameters are always autofill by definition, causing unexpected search results. This patch retypes them to Bool for search commands, so that users have to/can enter the desired value manually. Ticket #689 Ticket #701 --- ipalib/crud.py | 12 +++++++++--- ipalib/parameters.py | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'ipalib') diff --git a/ipalib/crud.py b/ipalib/crud.py index 86e175655..6df3c733d 100644 --- a/ipalib/crud.py +++ b/ipalib/crud.py @@ -210,9 +210,15 @@ class Search(Method): for option in self.obj.params_minus(self.args): if 'no_search' in option.flags: continue - yield option.clone( - attribute=True, query=True, required=False, autofill=False - ) + if isinstance(option, parameters.Flag): + yield option.clone_retype( + option.name, parameters.Bool, + attribute=True, query=True, required=False, autofill=False + ) + else: + yield option.clone( + attribute=True, query=True, required=False, autofill=False + ) if not self.extra_options_first: for option in super(Search, self).get_options(): yield option diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 5c386c324..128c8a463 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -585,9 +585,15 @@ class Param(ReadOnly): """ Return a new `Param` instance similar to this one, but named differently """ + return self.clone_retype(name, self.__class__, **overrides) + + def clone_retype(self, name, klass, **overrides): + """ + Return a new `Param` instance similar to this one, but of a different type + """ kw = dict(self.__clonekw) kw.update(overrides) - return self.__class__(name, *self.rules, **kw) + return klass(name, *self.rules, **kw) def normalize(self, value): """ -- cgit