diff --git a/src/jcl/jabber/command.py b/src/jcl/jabber/command.py index 2ceb2fe..a882079 100644 --- a/src/jcl/jabber/command.py +++ b/src/jcl/jabber/command.py @@ -28,11 +28,17 @@ from pyxmpp.jabber.dataforms import Form, Field import jcl from jcl.lang import Lang from jcl.jabber.disco import DiscoHandler, RootDiscoGetInfoHandler -import jcl.model as model +from jcl.model import account from jcl.model.account import Account 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): """Handle Ad-Hoc commands""" @@ -64,11 +70,12 @@ class CommandManager(object): def list_commands(self, disco_items, lang_class): """Return DiscoItem for each supported commands""" for command_name in self.commands: + command_desc = self.get_command_desc(command_name, + lang_class) DiscoItem(disco_items, self.component.jid, command_name, - self.get_command_desc(command_name, - lang_class)) + command_desc) return disco_items 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-idle-users-num", "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-active-users", "http://jabber.org/protocol/admin#get-idle-users", @@ -143,18 +150,14 @@ class JCLCommandManager(CommandManager): #command_node.setProp("sessionid", "????") # TODO result_form = Form(xmlnode_or_type="result", title="Registered account") # TODO : add to Lang - result_form.reported_fields.append(Field(name="name", - field_type="fixed", - label="Account name")) # TODO: add to Lang + result_form.reported_fields.append(FieldNoType(name="name", + label="Account name")) # TODO: add to Lang bare_from_jid = unicode(info_query.get_from().bare()) - model.db_connect() - accounts = Account.select(Account.q.user_jid == bare_from_jid) - for _account in accounts: - fields = [Field(name="name", - field_type="fixed", - value=_account.name)] + for _account in account.get_accounts(bare_from_jid): + print "Adding account : " + str(_account) + fields = [FieldNoType(name="name", + value=_account.name)] result_form.add_item(fields) - model.db_disconnect() result_form.as_xml(command_node) return [response] diff --git a/src/jcl/jabber/tests/command.py b/src/jcl/jabber/tests/command.py index 2f9e004..fe30c9c 100644 --- a/src/jcl/jabber/tests/command.py +++ b/src/jcl/jabber/tests/command.py @@ -3,18 +3,18 @@ ## Login : David Rousselie ## Started on Wed Jun 27 08:23:04 2007 David Rousselie ## $Id$ -## +## ## Copyright (C) 2007 David Rousselie ## 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; either version 2 of the License, or ## (at your option) any later version. -## +## ## 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 @@ -22,8 +22,21 @@ import unittest +from pyxmpp.jabber.dataforms import Form, Field +from pyxmpp.iq import Iq + from jcl.lang import Lang 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): def test_get_long_command_desc(self): @@ -40,6 +53,7 @@ class CommandManager_TestCase(unittest.TestCase): def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(CommandManager_TestCase, 'test')) + suite.addTest(unittest.makeSuite(FieldNoType_TestCase, 'test')) return suite if __name__ == '__main__':