From 030b5dab93971495d8656f7886c29136e118a9e6 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Fri, 13 Aug 2010 16:20:41 -0400 Subject: Change the behaviour of addattr/setattr parameters. setattr and addattr can now be used both to set all values of ANY attribute. the last setattr always resets the attribute to the specified value and all addattr append to it. Examples: user-mod testuser --setattr=title=msc title: msc user-mod testuser --setattr=title=msb title: msb user-mod testuser --addattr=title=msc title: msb, msc user-mod testuser --setattr=title= title: user-mod testuser --setattr=title=msc --addattr=msb title: msc, msb user-mod testuser --setattr=title=ing --addattr=bc title: ing, bc user-mod testuser --setattr=title=doc title: doc It's not very user friendly, but it's going to be used very very rarely in special conditions in the CLI and we can use it to save lots of JSON-RPC roundtrips in the webUI. This version includes calling the validation of Params during the setting of the attrs. --- ipalib/frontend.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index d320f02e..1c4fea8c 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -519,11 +519,12 @@ class Command(HasParam): if len(value) == 0: # None means "delete this attribute" value = None - if attr not in self.params: - if append and attr in newdict: - newdict[attr].append(value) - else: - newdict[attr] = [value] + if attr in self.params: + value = self.params[attr](value) + if append and attr in newdict: + newdict[attr].append(value) + else: + newdict[attr] = [value] return newdict def __attributes_2_entry(self, kw): @@ -540,7 +541,11 @@ class Command(HasParam): adddict = self.__convert_2_dict(kw['setattr'], append=False) if kw.get('addattr'): - adddict.update(self.__convert_2_dict(kw['addattr'])) + for (k, v) in self.__convert_2_dict(kw['addattr']).iteritems(): + if k in adddict: + adddict[k] += v + else: + adddict[k] = v for name in adddict: value = adddict[name] -- cgit