This is (knock on wood) a low risk change that adds an Object.label attribute that is exposed through the webUI, cleans up some UI funkiness.
I was accidentally making post-alpha changes in the same branch as my error and other string cleanups, which is taking me a bit to sort out, so this is the last patch from me till after the alpha.
>From 0446b7858c533d5c15e423c540bdbec768fe6333 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose <jder...@redhat.com> Date: Mon, 8 Feb 2010 05:03:28 -0700 Subject: [PATCH] Add Object.label class attribute, enable in webUI --- ipalib/frontend.py | 3 +++ ipalib/plugable.py | 17 +++++++++++++++++ ipalib/plugins/aci.py | 3 +++ ipalib/plugins/automount.py | 6 +++++- ipalib/plugins/dns.py | 4 +++- ipalib/plugins/group.py | 2 ++ ipalib/plugins/hbac.py | 3 +++ ipalib/plugins/host.py | 2 ++ ipalib/plugins/hostgroup.py | 2 ++ ipalib/plugins/netgroup.py | 4 +++- ipalib/plugins/rolegroup.py | 2 ++ ipalib/plugins/service.py | 2 ++ ipalib/plugins/taskgroup.py | 2 ++ ipalib/plugins/user.py | 2 ++ ipalib/text.py | 20 +++++++++++++++++--- ipawebui/engine.py | 2 +- tests/test_ipalib/test_text.py | 19 +++++++++++++++++++ 17 files changed, 88 insertions(+), 7 deletions(-) diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 1cc2ea2..8a0b51d 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -1103,6 +1103,9 @@ class Property(Attribute): def __init__(self): super(Property, self).__init__() + # FIXME: This is a hack till Param.label is updated to require a + # LazyText instance: + self.label = None self.rules = tuple( sorted(self.__rules_iter(), key=lambda f: getattr(f, '__name__')) ) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 6b2c6f7..51c09fc 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -37,9 +37,13 @@ import optparse import errors from config import Env import util +import text from base import ReadOnly, NameSpace, lock, islocked, check_name from constants import DEFAULT_CONFIG, FORMAT_STDERR, FORMAT_FILE +# FIXME: Updated constants.TYPE_ERROR to use this clearer format from wehjit: +TYPE_ERROR = '%s: need a %r; got a %r: %r' + class SetProxy(ReadOnly): """ @@ -155,6 +159,8 @@ class Plugin(ReadOnly): Base class for all plugins. """ + label = None + def __init__(self): self.__api = None cls = self.__class__ @@ -177,6 +183,17 @@ class Plugin(ReadOnly): self.name, name, getattr(self, name)) ) setattr(self, name, getattr(log, name)) + if self.label is None: + self.label = text.FixMe(self.name + '.label') + if not isinstance(self.label, text.LazyText): + raise TypeError( + TYPE_ERROR % ( + self.fullname + '.label', + text.LazyText, + type(self.label), + self.label + ) + ) def __get_api(self): """ diff --git a/ipalib/plugins/aci.py b/ipalib/plugins/aci.py index ea5b3e4..a722d76 100644 --- a/ipalib/plugins/aci.py +++ b/ipalib/plugins/aci.py @@ -197,6 +197,9 @@ class aci(Object): """ ACI object. """ + + label = _('ACIs') + takes_params = ( Str('aciname', cli_name='name', diff --git a/ipalib/plugins/automount.py b/ipalib/plugins/automount.py index 051f6d0..56f2c0b 100644 --- a/ipalib/plugins/automount.py +++ b/ipalib/plugins/automount.py @@ -88,6 +88,7 @@ from ipalib import api, errors from ipalib import Object, Command from ipalib import Flag, Str from ipalib.plugins.baseldap import * +from ipalib import _, ngettext class automountlocation(LDAPObject): @@ -224,6 +225,8 @@ class automountmap(LDAPObject): ), ) + label = _('Automount Maps') + api.register(automountmap) @@ -312,6 +315,8 @@ class automountkey(LDAPObject): ), ) + label = _('Automount Keys') + api.register(automountkey) @@ -381,4 +386,3 @@ class automountkey_show(LDAPRetrieve): """ api.register(automountkey_show) - diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index b31ded6..49d073e 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -66,6 +66,7 @@ import time from ipalib import api, crud, errors, output from ipalib import Object, Command from ipalib import Flag, Int, Str, StrEnum +from ipalib import _, ngettext # parent DN _zone_container_dn = api.env.container_dns @@ -110,6 +111,8 @@ def _get_record_dn(ldap, zone, idnsname): class dns(Object): """DNS zone/SOA record object.""" + label = _('DNS') + takes_params = ( Str('idnsname', cli_name='name', @@ -857,4 +860,3 @@ class dns_show_rr(Command): textui.print_entry(entry_attrs) api.register(dns_show_rr) - diff --git a/ipalib/plugins/group.py b/ipalib/plugins/group.py index 5fea412..0cc42a7 100644 --- a/ipalib/plugins/group.py +++ b/ipalib/plugins/group.py @@ -55,6 +55,8 @@ class group(LDAPObject): 'memberof': ['group', 'netgroup', 'rolegroup', 'taskgroup'], } + label = _('User Groups') + takes_params = ( Str('cn', cli_name='name', diff --git a/ipalib/plugins/hbac.py b/ipalib/plugins/hbac.py index ac94459..29567cf 100644 --- a/ipalib/plugins/hbac.py +++ b/ipalib/plugins/hbac.py @@ -23,6 +23,7 @@ Host based access control from ipalib import api, errors from ipalib import AccessTime, Password, Str, StrEnum from ipalib.plugins.baseldap import * +from ipalib import _, ngettext class hbac(LDAPObject): """ @@ -58,6 +59,8 @@ class hbac(LDAPObject): 'sourcehost': ['host', 'hostgroup'], } + label = _('HBAC') + takes_params = ( Str('cn', cli_name='name', diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py index 6368b8b..7e9dd90 100644 --- a/ipalib/plugins/host.py +++ b/ipalib/plugins/host.py @@ -79,6 +79,8 @@ class host(LDAPObject): 'memberof': ['hostgroup', 'netgroup', 'rolegroup'], } + label = _('Hosts') + takes_params = ( Str('fqdn', validate_host, cli_name='hostname', diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py index 2376b43..7accca6 100644 --- a/ipalib/plugins/hostgroup.py +++ b/ipalib/plugins/hostgroup.py @@ -46,6 +46,8 @@ class hostgroup(LDAPObject): 'memberof': ['hostgroup'], } + label = _('Host Groups') + takes_params = ( Str('cn', cli_name='name', diff --git a/ipalib/plugins/netgroup.py b/ipalib/plugins/netgroup.py index 66508b6..094a6d8 100644 --- a/ipalib/plugins/netgroup.py +++ b/ipalib/plugins/netgroup.py @@ -23,6 +23,7 @@ Netgroups from ipalib import api, errors from ipalib.plugins.baseldap import * +from ipalib import _, ngettext class netgroup(LDAPObject): @@ -51,6 +52,8 @@ class netgroup(LDAPObject): 'externalhost': [], } + label = _('Net Groups') + takes_params = ( Str('cn', cli_name='name', @@ -200,4 +203,3 @@ class netgroup_remove_member(LDAPRemoveMember): return (completed + completed_external, dn) api.register(netgroup_remove_member) - diff --git a/ipalib/plugins/rolegroup.py b/ipalib/plugins/rolegroup.py index d0ed0f0..ea89aa5 100644 --- a/ipalib/plugins/rolegroup.py +++ b/ipalib/plugins/rolegroup.py @@ -47,6 +47,8 @@ class rolegroup(LDAPObject): 'memberof': ['taskgroup'], } + label = _('Role Groups') + takes_params = ( Str('cn', cli_name='name', diff --git a/ipalib/plugins/service.py b/ipalib/plugins/service.py index a477de9..a5de17b 100644 --- a/ipalib/plugins/service.py +++ b/ipalib/plugins/service.py @@ -119,6 +119,8 @@ class service(LDAPObject): 'managedby': ['host'], } + label = _('Services') + takes_params = ( Str('krbprincipalname', validate_principal, cli_name='principal', diff --git a/ipalib/plugins/taskgroup.py b/ipalib/plugins/taskgroup.py index 575db48..a39f5c0 100644 --- a/ipalib/plugins/taskgroup.py +++ b/ipalib/plugins/taskgroup.py @@ -47,6 +47,8 @@ class taskgroup(LDAPObject): # FIXME: taskgroup can be member of ??? } + label = _('Task Groups') + takes_params = ( Str('cn', cli_name='name', diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index 1686d67..c06a928 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -68,6 +68,8 @@ class user(LDAPObject): 'memberof': ['group', 'netgroup', 'rolegroup', 'taskgroup'], } + label = _('Users') + takes_params = ( Str('uid', cli_name='login', diff --git a/ipalib/text.py b/ipalib/text.py index 0c86840..07f1b21 100644 --- a/ipalib/text.py +++ b/ipalib/text.py @@ -26,10 +26,25 @@ placeholders for the rest of the code. class LazyText(object): - def __init__(self, domain, localedir): + def __init__(self, domain=None, localedir=None): self.domain = domain self.localedir = localedir + def __mod__(self, kw): + return self.__unicode__() % kw + + +class FixMe(LazyText): + def __init__(self, msg): + self.msg = msg + super(FixMe, self).__init__() + + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.msg) + + def __unicode__(self): + return u'<%s>' % self.msg + class Gettext(LazyText): def __init__(self, msg, domain, localedir): @@ -39,8 +54,7 @@ class Gettext(LazyText): def __unicode__(self): return self.msg.decode('utf-8') - def __mod__(self, value): - return self.__unicode__() % value + class NGettext(LazyText): diff --git a/ipawebui/engine.py b/ipawebui/engine.py index 01b271a..dc59b09 100644 --- a/ipawebui/engine.py +++ b/ipawebui/engine.py @@ -131,7 +131,7 @@ class Engine(object): ) def build_cruds_page(self, obj): - page = self.app.new('PageGrid', title=obj.name, id=obj.name) + page = self.app.new('PageGrid', title=obj.label, id=obj.name) # Setup CRUDS widget: page.cruds.autoload = True diff --git a/tests/test_ipalib/test_text.py b/tests/test_ipalib/test_text.py index 924534a..dc5d02f 100644 --- a/tests/test_ipalib/test_text.py +++ b/tests/test_ipalib/test_text.py @@ -39,6 +39,25 @@ class test_LazyText(object): assert inst.localedir == 'bar' +class test_FixMe(object): + klass = text.FixMe + + def test_init(self): + inst = self.klass('user.label') + assert inst.msg == 'user.label' + assert inst.domain is None + assert inst.localedir is None + + def test_repr(self): + inst = self.klass('user.label') + assert repr(inst) == "FixMe('user.label')" + + def test_unicode(self): + inst = self.klass('user.label') + assert unicode(inst) == u'<user.label>' + assert type(unicode(inst)) is unicode + + class test_Gettext(object): klass = text.Gettext -- 1.6.3.3
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel