view idavoll/data_form.py @ 121:4f0113adb7ed

Add Node._check_node_exists() calls to all Node methods, because nodes could have been deleted in between calls. Add Node.get_subscription(). Only fire deferred (with None) on success of Node.add_subscription(). Fix Node.set_configuration() to actually work and only update the Node objects configuration when the SQL query has succeeded. Implement Node.remove_subscription(). Implement Node.is_subscribed(). Implement LeafNode methods (unchecked!).
author Ralph Meijer <ralphm@ik.nu>
date Tue, 12 Apr 2005 12:26:05 +0000
parents 0228725b705b
children fee92e499d6d
line wrap: on
line source

from twisted.xish import domish

NS_X_DATA = 'jabber:x:data'

class Field(domish.Element):
    def __init__(self, type="text-single", var=None, label=None):
        domish.Element.__init__(self, (NS_X_DATA, 'field'))
        self["type"] = type
        if var is not None:
            self["var"] = var
        if label is not None:
            self["label"] = label

    def set_value(self, value):
        # TODO: handle *-multi types

        if self["type"] == 'boolean':
            value = str(int(bool(value)))
        else:
            value = str(value)

        try:
            value_element = self.value
            value_element.children = []
        except:
            value_element = self.addElement("value")

        value_element.addContent(value)

class Form(domish.Element):
    def __init__(self, type, form_type):
        domish.Element.__init__(self, (NS_X_DATA, 'x'),
                                attribs={'type': type})
        self.add_field_single(type="hidden", var="FORM_TYPE", value=form_type)

    def add_field_single(self, type="text-single", var=None, label=None,
                         value=None):
        field = Field(type, var, label)
        if value is not None:
            field.set_value(value)
        self.addChild(field)