From 9ac8a8b49984ec5727b9da4803ae7823a9e44e13 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 12 Aug 2008 19:22:48 +0000 Subject: 118: Added user_login.default() method as another example; print_call() now prints sorted by the keys in ascending order --- ipalib/plugins.py | 16 +++++++++++----- ipalib/public.py | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ipalib/plugins.py b/ipalib/plugins.py index f33d69be..c8eede0b 100644 --- a/ipalib/plugins.py +++ b/ipalib/plugins.py @@ -60,11 +60,6 @@ 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') @@ -75,6 +70,17 @@ class user_sn(public.prop): return _('user last name') api.register(user_sn) +class user_login(public.prop): + def get_doc(self, _): + return _('user login') + 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)).lower() +api.register(user_login) + class user_initials(public.prop): def get_doc(self, _): return _('user initials') diff --git a/ipalib/public.py b/ipalib/public.py index 0dcf71d6..e173bdd5 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -213,7 +213,7 @@ class cmd(plugable.Plugin): ' ' * (tab *2), self.name, method, - ', '.join('%s=%r' % (k, v) for (k, v) in kw.items()), + ', '.join('%s=%r' % (k, kw[k]) for k in sorted(kw)), ) def __call__(self, **kw): -- cgit