summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-12 17:42:21 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-12 17:42:21 +0000
commit7bbeb2db69ffec5a0372e614a3b7eb5194e3b773 (patch)
treeeb98cb5db77683e13b43b32ee5fa34ec8875fc38 /ipalib
parent99d7638ff5c5cddb4f23d25ad13ef122476d5679 (diff)
downloadfreeipa-7bbeb2db69ffec5a0372e614a3b7eb5194e3b773.tar.gz
freeipa-7bbeb2db69ffec5a0372e614a3b7eb5194e3b773.tar.xz
freeipa-7bbeb2db69ffec5a0372e614a3b7eb5194e3b773.zip
116: Added a user_initials property plugin to demostrate default() method
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugins.py17
-rw-r--r--ipalib/public.py16
2 files changed, 24 insertions, 9 deletions
diff --git a/ipalib/plugins.py b/ipalib/plugins.py
index 68731044b..f33d69be0 100644
--- a/ipalib/plugins.py
+++ b/ipalib/plugins.py
@@ -60,6 +60,11 @@ api.register(user_find)
# Register some properties for the 'user' object:
+class user_login(public.prop):
+ def get_doc(self, _):
+ return _('user login')
+api.register(user_login)
+
class user_givenname(public.prop):
def get_doc(self, _):
return _('user first name')
@@ -70,10 +75,16 @@ class user_sn(public.prop):
return _('user last name')
api.register(user_sn)
-class user_login(public.prop):
+class user_initials(public.prop):
def get_doc(self, _):
- return _('user login')
-api.register(user_login)
+ return _('user initials')
+ def default(self, **kw):
+ givenname = kw.get('givenname', None)
+ sn = kw.get('sn', None)
+ if givenname is None or sn is None:
+ return None
+ return '%s%s' % (givenname[0], sn[0])
+api.register(user_initials)
# Register some methods for the 'group' object:
diff --git a/ipalib/public.py b/ipalib/public.py
index c1e644d5b..86323822c 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -184,6 +184,7 @@ class cmd(plugable.Plugin):
yield (key, value)
def normalize(self, **kw):
+ self.print_call('normalize', kw)
return dict(self.normalize_iter(kw))
def default_iter(self, kw):
@@ -194,29 +195,32 @@ class cmd(plugable.Plugin):
yield(option.name, value)
def default(self, **kw):
+ self.print_call('default', kw)
return dict(self.default_iter(kw))
def validate(self, **kw):
+ self.print_call('validate', kw)
for (key, value) in kw.items():
if key in self.options:
self.options[key].validate(value)
def execute(self, **kw):
+ self.print_call('execute', kw)
pass
- def print_n_call(self, method, kw):
+ def print_call(self, method, kw):
print '%s.%s(%s)' % (
self.name,
method,
', '.join('%s=%r' % (k, v) for (k, v) in kw.items()),
)
- return getattr(self, method)(**kw)
def __call__(self, **kw):
- kw = self.print_n_call('normalize', kw)
- kw.update(self.print_n_call('default', kw))
- self.print_n_call('validate', kw)
- return self.print_n_call('execute', kw)
+ self.print_call('__call__', kw)
+ kw = self.normalize(**kw)
+ kw.update(self.default(**kw))
+ self.validate(**kw)
+ self.execute(**kw)
class obj(plugable.Plugin):