Remove field type in command Form result

darcs-hash:20070711161705-86b55-1265875501a6d3aa36818ce67704e0315a4b562c.gz
This commit is contained in:
David Rousselie
2007-07-11 18:17:05 +02:00
parent 0f4424b68a
commit f50516181b
2 changed files with 34 additions and 17 deletions

View File

@@ -28,11 +28,17 @@ from pyxmpp.jabber.dataforms import Form, Field
import jcl import jcl
from jcl.lang import Lang from jcl.lang import Lang
from jcl.jabber.disco import DiscoHandler, RootDiscoGetInfoHandler from jcl.jabber.disco import DiscoHandler, RootDiscoGetInfoHandler
import jcl.model as model from jcl.model import account
from jcl.model.account import Account from jcl.model.account import Account
COMMAND_NS = "http://jabber.org/protocol/commands" COMMAND_NS = "http://jabber.org/protocol/commands"
class FieldNoType(Field):
def complete_xml_element(self, xmlnode, doc):
result = Field.complete_xml_element(self, xmlnode, doc)
result.unsetProp("type")
return result
class CommandManager(object): class CommandManager(object):
"""Handle Ad-Hoc commands""" """Handle Ad-Hoc commands"""
@@ -64,11 +70,12 @@ class CommandManager(object):
def list_commands(self, disco_items, lang_class): def list_commands(self, disco_items, lang_class):
"""Return DiscoItem for each supported commands""" """Return DiscoItem for each supported commands"""
for command_name in self.commands: for command_name in self.commands:
command_desc = self.get_command_desc(command_name,
lang_class)
DiscoItem(disco_items, DiscoItem(disco_items,
self.component.jid, self.component.jid,
command_name, command_name,
self.get_command_desc(command_name, command_desc)
lang_class))
return disco_items return disco_items
def get_command_info(self, disco_info, command_name, lang_class): def get_command_info(self, disco_info, command_name, lang_class):
@@ -120,7 +127,7 @@ class JCLCommandManager(CommandManager):
"http://jabber.org/protocol/admin#get-active-users-num", "http://jabber.org/protocol/admin#get-active-users-num",
"http://jabber.org/protocol/admin#get-idle-users-num", "http://jabber.org/protocol/admin#get-idle-users-num",
"http://jabber.org/protocol/admin#get-registered-users-list", "http://jabber.org/protocol/admin#get-registered-users-list",
"http://jabber.org/protocol/admin#get-disabled-users-list" "http://jabber.org/protocol/admin#get-disabled-users-list",
"http://jabber.org/protocol/admin#get-online-users", "http://jabber.org/protocol/admin#get-online-users",
"http://jabber.org/protocol/admin#get-active-users", "http://jabber.org/protocol/admin#get-active-users",
"http://jabber.org/protocol/admin#get-idle-users", "http://jabber.org/protocol/admin#get-idle-users",
@@ -143,18 +150,14 @@ class JCLCommandManager(CommandManager):
#command_node.setProp("sessionid", "????") # TODO #command_node.setProp("sessionid", "????") # TODO
result_form = Form(xmlnode_or_type="result", result_form = Form(xmlnode_or_type="result",
title="Registered account") # TODO : add to Lang title="Registered account") # TODO : add to Lang
result_form.reported_fields.append(Field(name="name", result_form.reported_fields.append(FieldNoType(name="name",
field_type="fixed",
label="Account name")) # TODO: add to Lang label="Account name")) # TODO: add to Lang
bare_from_jid = unicode(info_query.get_from().bare()) bare_from_jid = unicode(info_query.get_from().bare())
model.db_connect() for _account in account.get_accounts(bare_from_jid):
accounts = Account.select(Account.q.user_jid == bare_from_jid) print "Adding account : " + str(_account)
for _account in accounts: fields = [FieldNoType(name="name",
fields = [Field(name="name",
field_type="fixed",
value=_account.name)] value=_account.name)]
result_form.add_item(fields) result_form.add_item(fields)
model.db_disconnect()
result_form.as_xml(command_node) result_form.as_xml(command_node)
return [response] return [response]

View File

@@ -22,8 +22,21 @@
import unittest import unittest
from pyxmpp.jabber.dataforms import Form, Field
from pyxmpp.iq import Iq
from jcl.lang import Lang from jcl.lang import Lang
import jcl.jabber.command as command import jcl.jabber.command as command
from jcl.jabber.command import FieldNoType
class FieldNoType_TestCase(unittest.TestCase):
def test_complete_xml_element(self):
fake_iq = Iq(stanza_type="get",
from_jid="user1@test.com")
field = FieldNoType(name="name",
label="Account name")
field.complete_xml_element(fake_iq.xmlnode, None)
self.assertFalse(fake_iq.xmlnode.hasProp("type"))
class CommandManager_TestCase(unittest.TestCase): class CommandManager_TestCase(unittest.TestCase):
def test_get_long_command_desc(self): def test_get_long_command_desc(self):
@@ -40,6 +53,7 @@ class CommandManager_TestCase(unittest.TestCase):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(CommandManager_TestCase, 'test')) suite.addTest(unittest.makeSuite(CommandManager_TestCase, 'test'))
suite.addTest(unittest.makeSuite(FieldNoType_TestCase, 'test'))
return suite return suite
if __name__ == '__main__': if __name__ == '__main__':