Mercurial > libervia-pubsub
comparison idavoll/data_form.py @ 100:0228725b705b
Initial revision
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 02 Jan 2005 20:09:31 +0000 |
parents | |
children | fee92e499d6d |
comparison
equal
deleted
inserted
replaced
99:886caecb0030 | 100:0228725b705b |
---|---|
1 from twisted.xish import domish | |
2 | |
3 NS_X_DATA = 'jabber:x:data' | |
4 | |
5 class Field(domish.Element): | |
6 def __init__(self, type="text-single", var=None, label=None): | |
7 domish.Element.__init__(self, (NS_X_DATA, 'field')) | |
8 self["type"] = type | |
9 if var is not None: | |
10 self["var"] = var | |
11 if label is not None: | |
12 self["label"] = label | |
13 | |
14 def set_value(self, value): | |
15 # TODO: handle *-multi types | |
16 | |
17 if self["type"] == 'boolean': | |
18 value = str(int(bool(value))) | |
19 else: | |
20 value = str(value) | |
21 | |
22 try: | |
23 value_element = self.value | |
24 value_element.children = [] | |
25 except: | |
26 value_element = self.addElement("value") | |
27 | |
28 value_element.addContent(value) | |
29 | |
30 class Form(domish.Element): | |
31 def __init__(self, type, form_type): | |
32 domish.Element.__init__(self, (NS_X_DATA, 'x'), | |
33 attribs={'type': type}) | |
34 self.add_field_single(type="hidden", var="FORM_TYPE", value=form_type) | |
35 | |
36 def add_field_single(self, type="text-single", var=None, label=None, | |
37 value=None): | |
38 field = Field(type, var, label) | |
39 if value is not None: | |
40 field.set_value(value) | |
41 self.addChild(field) |