Add Object.label class attribute, enable in webUI

This commit is contained in:
Jason Gerard DeRose 2010-02-08 05:03:28 -07:00 committed by Rob Crittenden
parent 338578d10a
commit 069763c5c6
17 changed files with 88 additions and 7 deletions

View File

@ -1110,6 +1110,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__'))
)

View File

@ -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):
"""

View File

@ -197,6 +197,9 @@ class aci(Object):
"""
ACI object.
"""
label = _('ACIs')
takes_params = (
Str('aciname',
cli_name='name',

View File

@ -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):
@ -227,6 +228,8 @@ class automountmap(LDAPObject):
),
)
label = _('Automount Maps')
api.register(automountmap)
@ -315,6 +318,8 @@ class automountkey(LDAPObject):
),
)
label = _('Automount Keys')
api.register(automountkey)
@ -384,4 +389,3 @@ class automountkey_show(LDAPRetrieve):
"""
api.register(automountkey_show)

View File

@ -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)

View File

@ -55,6 +55,8 @@ class group(LDAPObject):
'memberof': ['group', 'netgroup', 'rolegroup', 'taskgroup'],
}
label = _('User Groups')
takes_params = (
Str('cn',
cli_name='name',

View File

@ -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',

View File

@ -79,6 +79,8 @@ class host(LDAPObject):
'memberof': ['hostgroup', 'netgroup', 'rolegroup'],
}
label = _('Hosts')
takes_params = (
Str('fqdn', validate_host,
cli_name='hostname',

View File

@ -46,6 +46,8 @@ class hostgroup(LDAPObject):
'memberof': ['hostgroup'],
}
label = _('Host Groups')
takes_params = (
Str('cn',
cli_name='name',

View File

@ -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)

View File

@ -47,6 +47,8 @@ class rolegroup(LDAPObject):
'memberof': ['taskgroup'],
}
label = _('Role Groups')
takes_params = (
Str('cn',
cli_name='name',

View File

@ -119,6 +119,8 @@ class service(LDAPObject):
'managedby': ['host'],
}
label = _('Services')
takes_params = (
Str('krbprincipalname', validate_principal,
cli_name='principal',

View File

@ -47,6 +47,8 @@ class taskgroup(LDAPObject):
# FIXME: taskgroup can be member of ???
}
label = _('Task Groups')
takes_params = (
Str('cn',
cli_name='name',

View File

@ -68,6 +68,8 @@ class user(LDAPObject):
'memberof': ['group', 'netgroup', 'rolegroup', 'taskgroup'],
}
label = _('Users')
takes_params = (
Str('uid',
cli_name='login',

View File

@ -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):

View File

@ -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

View File

@ -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