Esempio n. 1
0
class ExtendedInspectableAdapter(object):
    implements(IExtendedInspectable)
    adapts(IInspectable)

    def __init__(self, inspectable):
        self.context = inspectable

    def getattr(self, name):
        return self.context.getattr(name)

    def hasattr(self, name):
        return self.context.has_attr(name)

    def has_method(self, name):
        return self.context.has_method(name)

    def get_method(self, name):
        return self.context.get_method(name)

    def getattrs(self, names, conversions=[]):
        if not conversions:
            conversions = [None] * len(names)
        return map(self.getattr, names, conversions)

    def hasattrs(self, names):
        return map(self.hasattr, names)

    def has_methods(self, names):
        return map(self.has_method, names)

    def get_methods(self, names):
        return map(self.get_method, names)
Esempio n. 2
0
class RSS2AlarmEventItem(object):
    implements(IRSS2ItemElement)
    adapts(IAlarmEvent)

    def __init__(self, alarmevent):
        self.alarmevent = alarmevent
        super(RSS2AlarmEventItem, self).__init__()

    def as_item(self):
        event = self.alarmevent
        item = rss.Item()
        alarm = event.source
        priority = alarm.priority
        if not priority:
            priority = 'Normal'
        title = "%s (%s): %s" % (alarm.name, priority, event.state.upper())
        link = "http://%s/syndication?guid=%s" % (event.origin, event.GUID)
        item.title = rss.Title(title)
        item.link = rss.Link(link)
        item.guid = rss.Guid(event.GUID)
        item.pub_date = rss.PubDate(event.created())
        description = alarm.description
        for change in event.get_audit():
            description += '<br />\n%s.  ' % change.tostring()
        item.description = rss.Description(tools.escape_html(description))
        item.source = rss.Source(event.origin,
                                 "http://%s/syndication" % event.origin)
        eventcategory = rss.Category('Event')
        alarmcategory = rss.Category('Alarm')
        item.categories.append(eventcategory)
        item.categories.append(alarmcategory)
        return item

    def render(self):
        return str(self.as_item())
Esempio n. 3
0
class OGConfigurableNeodeAdapter(object):
    implements(IConfigurableNode)
    adapts(IOGConfigurableNode)
    nodespace = None

    def __init__(self, node):
        directly_provides(self, *tuple(provided_by(node)))
        self.__dict__['node'] = node

    def get_nodespace(self):
        return OGConfigurableNeodeAdapter.nodespace

    def get_url(self):
        return as_node_url(self.node)

    url = property(get_url)
    absolute_url = url

    def __get_parent(self):
        parent = self.node.parent
        if parent is not None:
            parent = IConfigurableNode(parent)
        return parent

    parent = property(__get_parent)

    def __getattr__(self, name):
        return getattr(self.node, name)

    def __setattr__(self, name, value):
        if name == '__provides__':
            return super(OGConfigurableNeodeAdapter,
                         self).__setattr__(name, value)
        return setattr(self.node, name, value)
Esempio n. 4
0
class Adapts(object):
    implements(IA)
    adapts(INoA)
    def __init__(self, context):
        self.context = context
    def show(self, name = 'shane'):
        self.context.say(name)
Esempio n. 5
0
class RSS2FaultEventItem(object):
    implements(IRSS2ItemElement)
    adapts(IFaultEvent)

    def __init__(self, faultevent):
        self.faultevent = faultevent

    def as_item(self):
        event = self.faultevent
        item = rss.Item()
        title = event.title
        faulttype = event.faulttype
        #item.title = rss.Title('%s: %s' % (title, faulttype))
        item.title = rss.Title('%s (%s): %s' %
                               (title, 'P1', event.state.upper()))
        item.link = rss.Link('http://%s/syndication?guid=%s' %
                             (event.origin, event.GUID))
        item.pub_date = rss.PubDate(event.timestamp)
        description = event.description
        event_history = event.history + [event.current_event]
        for change in event_history:
            description += '<br />\n%s.  ' % change.detail
        item.description = rss.Description(tools.escape_html(description))
        item.guid = rss.Guid(event.GUID)
        item.source = rss.Source(event.LOCALORIGIN,
                                 'http://%s/syndication' % event.LOCALORIGIN)
        for category in event.types:
            item.categories.append(rss.Category(category))
        return item

    def render(self):
        return str(self.as_item())
Esempio n. 6
0
class OGCompositeNeodeAdapter(OGConfigurableNeodeAdapter):
    implements(ICompositeNode)
    adapts(IOGCompositeNode)

    def add_child(self, child):
        self.node._add_child(child)
        return path.join(self.url, child.name)

    def remove_child(self, childname):
        if not isinstance(childname, str):
            childname = childname.name
        del (self.node._children[childname])

    def children_nodes(self, *args, **kw):
        nodes = self.node.children_nodes(*args, **kw)
        nodes = map(IConfigurableNode, nodes)
        return nodes

    def get_child(self, name, *args, **kw):
        node = self.node.get_child(name, *args, **kw)
        return IConfigurableNode(node)

    def as_node(self, *args):
        node = self.node.as_node(*args)
        return IConfigurableNode(node)
Esempio n. 7
0
class UniquelyIdentified(object):
    implements(IUniquelyIdentified)
    adapts(Interface)

    def get_identifier(obj, default=None, create=False):
        uuid = MetaDataProvider.get_subject_meta(obj, 'identifier', default)
        if uuid is None and create:
            uuid = UniquelyIdentified(obj).identifier
        return uuid

    get_identifier = staticmethod(get_identifier)

    def get_identified(uuid, default=None):
        return identifier_registry.get(uuid, default)

    get_identified = staticmethod(get_identified)

    def __new__(klass, context):
        adapter = super(UniquelyIdentified, klass).__new__(klass)
        meta_context = IMetaDataProvider(context)
        uuid = meta_context.setdefault_meta('identifier', UUID())
        identifier_registry.setdefault(uuid, context)
        adapter.initialize(meta_context)
        return adapter

    def initialize(self, context):
        self.context = context

    def __get_id(self):
        return self.context['identifier']

    def __set_id(self, id):
        self.context['identifier'] = id

    identifier = property(__get_id, __set_id)
Esempio n. 8
0
class LeafNodeDOM(object):
    implements(IDOMish)
    adapts(ILeafNode)
    def __init__(self, tag):
        self.tag = tag
        return
    def getAttribute(self, name):
        if hasattr(self.tag,name):
            return getattr(self.tag,name)
        elif hasattr(self.tag,'attr_dict'):
            if self.tag.attr_dict.has_key(name):
                ugh = self.tag.attr_dict[name].split('"')
                if len(ugh) == 3:
                    return ugh[1]
        return None
    def setAttribute(self, name, value):
        if hasattr(self.tag,name):
            return setattr(self.tag,name,value)
        elif hasattr(self.tag,'attr_dict'):
            self.tag.attr_dict[name] = ' %s="%s"' % (name, value)
        return None
    def getTagById(self, id):
        my_id = self.getAttribute('id')
        if my_id == id:
            return self.tag
        return None
Esempio n. 9
0
class PickleableOGCompositeNode(PickleableOGConfigurableNode):
    adapts(IOGCompositeNode)
    privatevars = PickleableOGConfigurableNode.privatevars[:]
    privatevars += ['_children']

    def __init__(self, context):
        super(PickleableOGCompositeNode, self).__init__(context)
        context._children = getattr(context, '_children', {})
Esempio n. 10
0
class MultiAdapts(object):
    implements(IB)
    adapts(INoA, INoB)
    def __init__(self, a, b):
        self.contexts = [a, b]
    def show(self, name = 'shane'):
        for context in self.contexts:
            context.say(name)
Esempio n. 11
0
class HTMLScheduleForm(object):
    implements(IWebContent)
    adapts(ISchedule)

    def __init__(self, schedule):
        self.schedule = schedule

    def render(self, request_path):
        attrs = KeyWordAssist()
        document = HTMLgen.Div(**attrs("class", "content"))
        encoded_schedule = urllib.quote_plus(self.schedule.url)
        config_form = HTMLgen.Form(request_path)
        nodeinput = HTMLgen.Input(name='node',
                                  value=encoded_schedule,
                                  type='hidden')
        actioninput = HTMLgen.Input(name="actionName",
                                    value="configure",
                                    type="hidden")
        config_form.append(nodeinput)
        config_form.append(actioninput)
        config_form.submit.value = 'save'
        config_form.submit.onClick = ('return utils.schedule.'
                                      'validate_configuration(this.form);')
        config_section = HTMLgen.Div(**attrs('class', 'section'))
        config_table = HTMLgen.TableLite(
            **attrs('class', 'configuration-table'))
        config_header = HTMLgen.TR(**attrs('class', 'table-header'))
        for header in ['Attribute', 'Value']:
            headcell = HTMLgen.TH(header,
                                  scope="col",
                                  abbr=header,
                                  id="%sheader" % header)
            if header == "Action":
                setattr(headcell, "class", "control")

            config_header.append(headcell)
        config_table.append(config_header)
        configrows = []
        classes = itertools.cycle(['light', 'dark'])
        config = Dictionary(self.schedule.configuration())
        namerow = HTMLgen.TR(**attrs('class', classes.next()))
        namerow.append(HTMLgen.TH('Schedule Name'))
        sched_name = config.pop('name').split("RZSched_")
        namefield = HTMLgen.Input(value=sched_name[1], name='configure.name')
        namerow.append(HTMLgen.TD(namefield, **attrs('class',
                                                     'configuration')))
        configrows.append(namerow)
        config_table.append(*configrows)
        config_form.append(config_table)
        config_section.append(config_form)
        config_section.append(
            navigation(request_path, "reload", self.schedule.url))
        config_section.append(
            navigation(request_path, "back", self.schedule.parent.url))
        document.append(config_section)
        return str(document)
Esempio n. 12
0
class AnyAdapts(object):
    implements(IB)
    adapts(None, INoB)
    def __init__(self, a, b):
        self.contexts = [a, b]
    def show(self, name = 'shane'):
        for context in self.contexts:
            try: context.say(name)
            except AttributeError:
                print 'Context %s has no say!' % context
Esempio n. 13
0
class DomDocument(DomElement):
    __doc__ = IDomDocument.__doc__

    implements(IDomDocument)
    adapts(IRootNode)

    def __init__(self, node):
        super(DomDocument, self).__init__(node)
        self._type = dom.Node.DOCUMENT_NODE

    # See mpx.www.w3c.dom.interfaces.IDomDocument
    def __get_document_element(self):
        # Root is this object's node.
        return IDomNode(self.node)

    documentElement = property(__get_document_element)

    def __get_nodespace(self):
        return self.node.get_nodespace()

    nodespace = property(__get_nodespace)

    def getElementById(self, id):
        """
            ID is the node URL.
        """
        return IDomNode(self.nodespace.as_node(id))

    def createElement(self, tagName):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")

    def createElementNS(self, namespaceURI, tagName):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")

    def createTextNode(self, data):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")

    def createComment(self, data):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")

    def createProcessingInstruction(self, target, data):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")

    def createAttribute(self, name):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")

    def createAttributeNS(self, namespaceURI, qualifiedName):
        "See mpx.www.w3c.dom.interfaces.IDomDocument"
        raise Exception("Not implemented")
Esempio n. 14
0
class BroadwayConfigurableGenerator(object):
    implements(IBroadways)
    adapts(IConfigurableNode)

    nodeopen = "<node name='%s' node_id='%s' module='%s.%s' config_builder=''  inherant='false' description=''>"
    nodeclose = "</node>"
    configopen = "\t<config>"
    configclose = "\t</config>"
    propertyopenclose = "\t\t<property name='%s' value='%s'/>"

    def __init__(self, node):
        self.node = node

    def _xml_lines(self, levels=None):
        realnode = self.node
        while isinstance(realnode, OGConfigurableNeodeAdapter):
            realnode = realnode.node
        classname = realnode.__class__.__name__
        module = realnode.__class__.__module__
        xmllines = [self.nodeopen % (self.node.name, 0, module, classname)]
        xmllines.append(self.configopen)
        configuration = self.node.configuration()
        if configuration.has_key('parent'):
            del (configuration['parent'])
        if configuration.has_key('name'):
            del (configuration['name'])
        for name, value in configuration.items():
            if not isinstance(value, str):
                value = str(value)
            value = encode_xml(value)
            xmllines.append(self.propertyopenclose % (name, value))
        xmllines.append(self.configclose)
        xmllines.append(self.nodeclose)
        return xmllines

    def dumps(self, levels=None):
        return string.join(self._xml_lines(levels), '\n')

    def loads(self, data):
        datastream = StringIO.StringIO(data)
        xmlroot = parse_xml(datastream)
        xmlroot.parent = self.node.url
        crawler = Iterator(xmlroot)
        nodecount = 0
        while crawler.has_more():
            xmlnode = crawler.get_next_node()
            config = xmlnode.get_config()
            print 'Loading node %d: %s' % (nodecount, config)
            node = load_node(config)
            node.configure(config)
            nodecount += 1
        return nodecount

    def dump(self, datastream, levels=None):
        return datastream.write(self.dumps(levels))
Esempio n. 15
0
class DataContainterDOM(LeafNodeDOM):
    implements(IDOMish)
    adapts(IDataContainer)
    def getTagById(self, id):
        result = super(DataContainterDOM,self).getTagById(id)
        if result is None:
            for tag in self.tag.data:
                result = domish(tag).getTagById(id)
                if result is not None:
                    return result
        return result
Esempio n. 16
0
class HTMLRoleManagerForm(HTMLSimpleManagerForm):
    adapts(IRoleManager)

    def add_child_form(self, content):
        popup = HTMLgen.Form("#")
        popup.submit.value = "+"
        popup.submit.name = "Add Role"
        popup.submit.onClick = "return popup_form(this, '%s', true)" % addform
        content.append(popup)

    def get_allowed_additions(self):
        return ['Role']
Esempio n. 17
0
class PickleAdapter(object):
    implements(IPickles)
    adapts(Interface)

    def __init__(self, context):
        self.context = context

    def __getinitargs__(self):
        return self.context

    def __call__(self):
        return self.context
Esempio n. 18
0
class HTMLRoleForm(object):
    implements(IWebContent)
    adapts(IRole)

    def __init__(self, role):
        self.role = role
        self.base_doc = HTMLgen.SimpleDocument(title='Role Editor')

    def render(self, request_path):
        attrs = KeyWordAssist()
        document = self.base_doc.copy()
        encoded = cgi.escape(self.role.parent.name)
        manager = HTMLgen.Input(name='manager', type='hidden', value=encoded)
        encoded = cgi.escape(self.role.name)
        node = HTMLgen.Input(name='node', type='hidden', value=encoded)
        config_form = HTMLgen.Form(request_path)
        config_form.append(manager)
        config_form.append(node)
        config_form.submit.value = 'commit'
        hidden = HTMLgen.Input(name="actionName",
                               type='hidden',
                               value="configure")
        config_form.append(hidden)
        config_section = HTMLgen.Div(**attrs('class', 'section'))
        config_table = HTMLgen.TableLite(**attrs('class', 'configuration'))
        headrow = HTMLgen.TR(**attrs('class', 'table-header'))
        for header in ['Attribute', 'Value']:
            headcell = HTMLgen.TH(header,
                                  scope="col",
                                  abbr=header,
                                  id="%sheader" % header)
            if header == "Value":
                setattr(headcell, "class", "control")
            headrow.append(headcell)
        config_table.append(headrow)

        configrows = []
        rowclasses = ['light', 'dark']
        config = Dictionary(self.role.configuration())

        namerow = HTMLgen.TR(**attrs('class', rowclasses[len(configrows) % 2]))
        namerow.append(HTMLgen.TH('Role Name'))
        namefield = HTMLgen.Input(value=config.pop('name'),
                                  name='configure.name')
        namefield.onFocus = "this.readOnly=true;this.style.color='grey'"
        namerow.append(HTMLgen.TD(namefield, **attrs('class', 'control')))
        configrows.append(namerow)

        config_table.append(*configrows)
        config_form.append(config_table)
        config_section.append(adorn(config_form, id="main"))
        document.append(config_section)
        return str(document)
Esempio n. 19
0
class ListenerAdapter(object):
    implements(IMessageChannel)
    adapts(IMessageListener)

    def __init__(self, listener):
        self.listener = listener
        super(ListenerAdapter, self).__init__()

    def send(self, message):
        self.listener.handle_message(message)

    def __eq__(self, other):
        return self.listener == other.listener
Esempio n. 20
0
class ChannelAdapter(object):
    """
        Wrap Channel instance with message listener interface.
    """
    implements(IMessageListener)
    adapts(IMessageChannel)

    def __init__(self, channel):
        self.channel = channel
        super(ChannelAdapter, self).__init__()

    def handle_message(self, message):
        self.channel.send(message)

    def __eq__(self, other):
        return self.channel == other.channel
Esempio n. 21
0
class IOGRemoteNodeSecurityAdapter(object):
    implements(ISecure)
    adapts(IOGRemoteNode, IUser)

    def __init__(self, facade, user):
        directly_provides(self, *tuple(provided_by(facade)))
        self.__dict__['facade'] = facade
        self.__dict__['user'] = user

    def __getattr__(self, name):
        return getattr(self.facade, name)

    def __setattr__(self, name, value):
        if name == '__provides__':
            return super(IOGRemoteNodeSecurityAdapter,
                         self).__setattr__(name, value)
        return setattr(self.facade, name, value)
Esempio n. 22
0
class TriggerPickler(object):
    implements(IPickles)
    adapts(ITrigger)

    def __init__(self, trigger):
        self.trigger = trigger

    def __getstate__(self):
        trigger = self.trigger
        if not hasattr(trigger, '__picklestate'):
            state = {
                'class': type(trigger),
                'url': trigger.url,
                'config': trigger.configuration()
            }
            trigger.__picklestate = state
        state = trigger.__picklestate
        state['targets'] = []
        targets = trigger.get_targets(True)
        for target in targets:
            if not isinstance(target, str):
                target = target.url
            state['targets'].append(target)
        state['running'] = trigger.is_running()
        return state

    def __setstate__(self, state):
        self.trigger = None
        self.state = state

    def __call__(self):
        if self.trigger is None:
            try:
                self.trigger = as_node(self.state['url'])
            except KeyError:
                self.trigger = self.state.get('class')()
            config = self.state['config']
            parent = as_node(config['parent'])
            config.setdefault('nodespace', parent.nodespace)
            self.trigger.configure(config)
            if self.state['running']:
                self.trigger.start()
        for target in self.state.get('targets', []):
            self.trigger.add_target(target)
        return self.trigger
Esempio n. 23
0
class ExporterPickler(object):
    implements(IPickles)
    adapts(IAlarmExporter)

    def __init__(self, exporter):
        self.exporter = exporter

    def __getstate__(self):
        exporter = self.exporter
        if not hasattr(exporter, '__picklestate'):
            state = {
                'class': type(exporter),
                'url': exporter.url,
                'config': exporter.configuration()
            }
            exporter.__picklestate = state
        state = exporter.__picklestate
        sources = self.exporter.get_sources()
        state['sources'] = {}
        for source in sources:
            state['sources'][source.url] = self.exporter.get_event_names(
                source)
        return state

    def __setstate__(self, state):
        self.exporter = None
        self.state = state

    def __call__(self):
        if self.exporter is None:
            try:
                self.exporter = as_node(self.state['url'])
            except KeyError:
                self.exporter = self.state.get('class')()
            config = self.state['config']
            parent = as_node(config['parent'])
            config.setdefault('nodespace', parent.nodespace)
            self.exporter.configure(config)
            self.exporter.start()
        for source, args in self.state.get('sources', {}).items():
            try:
                self.exporter.add_source(source, *args)
            except:
                msglog.exception()
        return self.exporter
Esempio n. 24
0
class DomConfigurableNode(object):
    __doc__ = IDomNode.__doc__

    implements(IDomNode)
    adapts(IConfigurableNode)

    def __init__(self, node):
        self.node = node
        self._type = dom.Node.ELEMENT_NODE
        super(DomConfigurableNode, self).__init__(node)

    # See mpx.www.w3c.dom.interfaces.IDomNode
    def __get_node_class(self):
        return type(self.node)

    nodeClass = property(__get_node_class)

    def __get_node_classname(self):
        klass = self.nodeClass
        return string.join((klass.__module__, klass.__name__), '.')

    nodeClassName = property(__get_node_classname)

    def __get_node_id(self):
        return self.node.url

    nodeID = property(__get_node_id)

    def __get_node_type(self):
        return self._type

    nodeType = property(__get_node_type)

    # See mpx.www.w3c.dom.interfaces.IDomNode
    def __get_parent_node(self):
        if self.node.parent is None:
            return None
        try:
            parent = IDomNode(self.node.parent)
        except TypeError, error:
            print 'IDomNode(node.parent) failed: ' + str(error)
            print '\treturning None for parent.'
            parent = None
        return parent
Esempio n. 25
0
class Pickleable(object):
    implements(IPickleable)
    adapts(IPersistent)

    excludes = {'__dict__': None, '__weakref__': None}
    context = None

    def __init__(self, context):
        self.contexttype = type(context)
        self.contextstate = context.__dict__
        self.context = context

    def __getstate__(self):
        names = filter(self.should_persist, self.contextstate.keys())
        values = map(self.contextstate.get, names)
        return {'type': self.contexttype, 'state': dict(zip(names, values))}

    def __setstate__(self, state):
        print 'Pickleable.__setstate__'
        contexttype = state['type']
        contextstate = state['state']
        print '\tContext type: %s' % (contexttype, )
        print '\tState: %s' % (contextstate, )
        context = self.instantiate(contexttype)
        context.__dict__.update(contextstate)
        self.contexttype = contexttype
        self.contextstate = context.__dict__
        self.context = context
        print 'Pickleable instantiated %s' % self.context.name

    def instantiate(self, contexttype):
        return contexttype.__new__(contexttype)

    def write_object(self):
        return self

    def read_object(self):
        print 'Pickleable %s read object %s' % (self, self.context)
        return self.context

    def should_persist(self, key):
        return not (self.excludes.has_key(key)
                    or key.startswith('__persistence'))
Esempio n. 26
0
class BroadwayCompositeGenerator(BroadwayConfigurableGenerator):
    implements(IBroadways)
    adapts(ICompositeNode)

    def dumps(self, levels=None):
        xmllines = super(BroadwayCompositeGenerator, self)._xml_lines(levels)
        nodeclose = xmllines.pop()
        if levels is not None:
            levels -= 1
        childdumps = []
        if levels != 0:
            children = self.node.children_nodes()
            generators = map(IBroadways, children)
            childdumps = [generator.dumps(levels) for generator in generators]
        xmllines.extend(childdumps)
        xmllines.append(nodeclose)
        return string.join(xmllines, '\n')

    def dump(self, datastream, levels=None):
        pass
Esempio n. 27
0
class ExtendedModifiableAdapter(object):
    implements(IExtendedModifiable)
    adapts(IModifiable)

    def __init__(self, inspectable):
        self.context = inspectable

    def setattr(self, name, value, conversion=None):
        self.context.setattr(name, value, conversion)

    def delattr(self, name):
        self.context.delattr(name)

    def setattrs(self, names, values, conversions=[]):
        if not conversions:
            conversions = [None] * len(names)
        map(self.setattr, names, values, conversions)

    def delattrs(self, names):
        map(self.delattr, names)
Esempio n. 28
0
class HTMLPolicyManagerForm(HTMLSimpleManagerForm):
    adapts(IPolicyManager)

    def add_child_form(self, content):
        popup = HTMLgen.Form("#")
        popup.submit.value = "+"
        popup.submit.name = "Add Policy"
        popup.submit.onClick = "return popup_form(this, '%s', true)" % addform
        content.append(popup)

    def get_row_actions(self, child):
        actions = []
        if child.is_configurable():
            actions.append('edit')
            actions.append('permissions')
        if child.is_removable():
            actions.append('remove')
        return actions

    def get_allowed_additions(self):
        return ['Policy']
Esempio n. 29
0
class ConfigurableNodePickler(object):
    implements(IPickles)
    adapts(IConfigurableNode)

    def __init__(self, node):
        self.node = node

    def __getstate__(self):
        node = self.node
        while isinstance(node, OGConfigurableNeodeAdapter):
            node = node.node
        state = {
            'class': type(node),
            'url': self.node.url,
            'config': self.node.configuration()
        }
        return state

    def __setstate__(self, state):
        self.node = None
        self.state = state

    def __call__(self):
        if self.node is None:
            try:
                self.node = _node.rootspace.as_node(self.state['url'])
            except KeyError:
                self.node = self.state.get('class')()
            else:
                try:
                    self.node.stop()
                except:
                    pass
            config = self.state['config']
            parent = _node.rootspace.as_node(config['parent'])
            config.setdefault('nodespace', parent.nodespace)
            self.node.configure(config)
            self.node.start()
        return self.node
Esempio n. 30
0
class HTMLUserManagerForm(HTMLSimpleManagerForm):
    adapts(IUserManager)

    def render(self, *args):
        content = super(HTMLUserManagerForm, self).render(*args)
        popup = HTMLgen.Form("#")
        popup.submit.value = " + "
        popup.submit.name = "Add User"
        popup.submit.onClick = "return popup_form(this, '%s', true)" % addform
        return "\n".join([content, str(popup)])

    def get_row_actions(self, child):
        actions = []
        if not hasattr(child, 'is_configurable') or child.is_configurable():
            actions.append('edit')
        actions.append("roles")
        if not hasattr(child, 'is_removable') or child.is_removable():
            actions.append('remove')
        return actions

    def get_allowed_additions(self):
        """Special handling of User addition appended to form by render."""
        return []