# Authors: Jason Gerard DeRose # # Copyright (C) 2009 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; version 2 only # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ Custom IPA widgets. """ from textwrap import dedent from wehjit import Collection, base, freeze, builtins from wehjit.util import Alternator from wehjit import Static, Dynamic, StaticProp, DynamicProp from ipaserver.rpcserver import extract_query class IPAPlugins(base.Container): plugins = Static('plugins', default=tuple()) kind = Static('kind') @DynamicProp def row(self): return Alternator(['odd', 'even']) xml = """

module
base(s)
docstring
""" style_global = ( ('tr.odd', ( ('background-color', '#ddd'), )), ('tr.even', ( ('background-color', '#eee'), )), ('td', ( ('vertical-align', 'top'), ('padding', '0.25em 0.5em'), )), ) style = ( ('', ( ('font-size', '%(font_size_mono)s'), ('font-family', 'monospace'), )), ('table', ( ('width', '100%%'), )), ('pre', ( ('margin', '0'), )), ('th', ( ('color', '#0a0'), )), ('h2', ( ('font-family', 'monospace'), ('font-weight', 'normal'), ('margin-top', '1.5em'), ('margin-bottom', '0'), )), ('h2 a', ( ('text-decoration', 'none'), ('color', 'inherit'), )), ('h2 a:hover', ( ('background-color', '#eee'), )), ('h2:target', ( ('color', '#e02'), )), ) class API(base.Widget): api = Static('api') @DynamicProp def row(self): return Alternator(['odd', 'even']) xml = """ """ class Command(base.Widget): xml = """
Object
""" class Object(base.Widget): xml = """
${"param.name"}:
""" class Conditional(base.Container): mode = Static('mode', default='input') @DynamicProp def page_mode(self): if self.page is None: return return self.page.mode xml = """
""" class Output(base.Widget): """ Shows attributes form an LDAP entry. """ order = Dynamic('order') labels = Dynamic('labels') result = Dynamic('result') xml = """
""" style = ( ('table', ( ('empty-cells', 'show'), ('border-collapse', 'collapse'), )), ('th', ( ('text-align', 'right'), ('padding', '.25em 0.5em'), ('line-height', '%(height_bar)s'), ('vertical-align', 'top'), )), ('td', ( ('padding', '.25em'), ('vertical-align', 'top'), ('text-align', 'left'), ('line-height', '%(height_bar)s'), )), ) class Hidden(base.Field): xml = """ """ class Notification(base.Widget): message = Dynamic('message') error = Dynamic('error', default=False) @property def extra_css_classes(self): if self.error: yield 'error' else: yield 'okay' xml = """

""" style = ( ('', ( ('font-weight', 'bold'), ('-moz-border-radius', '100%%'), ('background-color', '#eee'), ('border', '2px solid #966'), ('padding', '0.5em'), ('text-align', 'center'), )), ) class PageCmd(builtins.PageApp): cmd = Static('cmd') mode = Dynamic('mode', default='input') def controller(self, environ): query = extract_query(environ) self.mode = query.pop('__mode__', 'input') if self.mode == 'input': return soft = self.cmd.soft_validate(query) errors = soft['errors'] values = soft['values'] if errors: self.mode = 'input' for key in self.form: if key in errors: self.form[key].error = errors[key] if key in values: self.form[key].value = values[key] return output = self.cmd(**query) if isinstance(output, dict) and 'summary' in output: self.notification.message = output['summary'] params = self.cmd.output_params if params: order = list(params) labels = dict((p.name, p.label) for p in params()) else: order = sorted(entry) labels = dict((k, k) for k in order) self.show.order = order self.show.labels = labels self.show.result = output.get('result') def create_widgets(): widgets = Collection('freeIPA') widgets.register_builtins() widgets.register(API) widgets.register(IPAPlugins) widgets.register(Command) widgets.register(Object) widgets.register(Conditional) widgets.register(Output) widgets.register(Hidden) widgets.register(Notification) widgets.register(PageCmd) freeze(widgets) return widgets