Add bare JID as parameter of registration form default function
darcs-hash:20070606190135-86b55-0c8b86b74a71c48bd16fbc001a3a93a6e03a47f5.gz
This commit is contained in:
@@ -1073,7 +1073,7 @@ class AccountManager(object):
|
|||||||
field = reg_form.add_field(field_type=field_type,
|
field = reg_form.add_field(field_type=field_type,
|
||||||
label=label,
|
label=label,
|
||||||
name=field_name,
|
name=field_name,
|
||||||
value=default_func())
|
value=default_func(bare_from_jid))
|
||||||
if field_options is not None:
|
if field_options is not None:
|
||||||
for option_value in field_options:
|
for option_value in field_options:
|
||||||
lang_label_attr = "field_" + field_name + "_" + option_value
|
lang_label_attr = "field_" + field_name + "_" + option_value
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ ONLINE = "online"
|
|||||||
def default_post_func(field_value, default_func, bare_from_jid):
|
def default_post_func(field_value, default_func, bare_from_jid):
|
||||||
"""Default post process function: do nothing"""
|
"""Default post process function: do nothing"""
|
||||||
if field_value is None or str(field_value) == "":
|
if field_value is None or str(field_value) == "":
|
||||||
return default_func()
|
return default_func(bare_from_jid)
|
||||||
return field_value
|
return field_value
|
||||||
|
|
||||||
def int_post_func(field_value, default_func, bare_from_jid):
|
def int_post_func(field_value, default_func, bare_from_jid):
|
||||||
"""Return an integer from integer field value"""
|
"""Return an integer from integer field value"""
|
||||||
if field_value is None or str(field_value) == "":
|
if field_value is None or str(field_value) == "":
|
||||||
return int(default_func())
|
return int(default_func(bare_from_jid))
|
||||||
return int(field_value)
|
return int(field_value)
|
||||||
|
|
||||||
def mandatory_field(field_value):
|
def mandatory_field(field_value):
|
||||||
@@ -186,10 +186,11 @@ class PresenceAccount(Account):
|
|||||||
def get_possibles_actions(presence_action_field):
|
def get_possibles_actions(presence_action_field):
|
||||||
return real_class.get_presence_actions_fields()[presence_action_field][0]
|
return real_class.get_presence_actions_fields()[presence_action_field][0]
|
||||||
|
|
||||||
def is_action_possible(presence_action_field, action, default_func):
|
def is_action_possible(presence_action_field, action, default_func,
|
||||||
|
bare_from_jid):
|
||||||
if int(action) in get_possibles_actions(presence_action_field):
|
if int(action) in get_possibles_actions(presence_action_field):
|
||||||
return int(action)
|
return int(action)
|
||||||
raise default_func()
|
raise default_func(bare_from_jid)
|
||||||
|
|
||||||
def get_default_presence_action(presence_action_field):
|
def get_default_presence_action(presence_action_field):
|
||||||
return real_class.get_presence_actions_fields()[presence_action_field][1]
|
return real_class.get_presence_actions_fields()[presence_action_field][1]
|
||||||
@@ -203,43 +204,51 @@ class PresenceAccount(Account):
|
|||||||
lambda action, default_func, bare_from_jid: \
|
lambda action, default_func, bare_from_jid: \
|
||||||
is_action_possible("chat_action",
|
is_action_possible("chat_action",
|
||||||
action,
|
action,
|
||||||
default_func),
|
default_func,
|
||||||
lambda : get_default_presence_action("chat_action")),
|
bare_from_jid),
|
||||||
|
lambda bare_from_jid: get_default_presence_action("chat_action")),
|
||||||
("online_action", "list-single",
|
("online_action", "list-single",
|
||||||
[str(action) for action in get_possibles_actions("online_action")],
|
[str(action) for action in get_possibles_actions("online_action")],
|
||||||
lambda action, default_func, bare_from_jid: \
|
lambda action, default_func, bare_from_jid: \
|
||||||
is_action_possible("online_action",
|
is_action_possible("online_action",
|
||||||
action,
|
action,
|
||||||
default_func),
|
default_func,
|
||||||
lambda : get_default_presence_action("online_action")),
|
bare_from_jid),
|
||||||
|
lambda bare_from_jid: \
|
||||||
|
get_default_presence_action("online_action")),
|
||||||
("away_action", "list-single",
|
("away_action", "list-single",
|
||||||
[str(action) for action in get_possibles_actions("away_action")],
|
[str(action) for action in get_possibles_actions("away_action")],
|
||||||
lambda action, default_func, bare_from_jid: \
|
lambda action, default_func, bare_from_jid: \
|
||||||
is_action_possible("away_action",
|
is_action_possible("away_action",
|
||||||
action,
|
action,
|
||||||
default_func),
|
default_func,
|
||||||
lambda : get_default_presence_action("away_action")),
|
bare_from_jid),
|
||||||
|
lambda bare_from_jid: get_default_presence_action("away_action")),
|
||||||
("xa_action", "list-single",
|
("xa_action", "list-single",
|
||||||
[str(action) for action in get_possibles_actions("xa_action")],
|
[str(action) for action in get_possibles_actions("xa_action")],
|
||||||
lambda action, default_func, bare_from_jid: \
|
lambda action, default_func, bare_from_jid: \
|
||||||
is_action_possible("xa_action",
|
is_action_possible("xa_action",
|
||||||
action,
|
action,
|
||||||
default_func),
|
default_func,
|
||||||
lambda : get_default_presence_action("xa_action")),
|
bare_from_jid),
|
||||||
|
lambda bare_from_jid: get_default_presence_action("xa_action")),
|
||||||
("dnd_action", "list-single",
|
("dnd_action", "list-single",
|
||||||
[str(action) for action in get_possibles_actions("dnd_action")],
|
[str(action) for action in get_possibles_actions("dnd_action")],
|
||||||
lambda action, default_func, bare_from_jid: \
|
lambda action, default_func, bare_from_jid: \
|
||||||
is_action_possible("dnd_action",
|
is_action_possible("dnd_action",
|
||||||
action,
|
action,
|
||||||
default_func),
|
default_func,
|
||||||
lambda : get_default_presence_action("dnd_action")),
|
bare_from_jid),
|
||||||
|
lambda bare_from_jid: get_default_presence_action("dnd_action")),
|
||||||
("offline_action", "list-single",
|
("offline_action", "list-single",
|
||||||
[str(action) for action in get_possibles_actions("offline_action")],
|
[str(action) for action in get_possibles_actions("offline_action")],
|
||||||
lambda action, default_func, bare_from_jid: \
|
lambda action, default_func, bare_from_jid: \
|
||||||
is_action_possible("offline_action",
|
is_action_possible("offline_action",
|
||||||
action,
|
action,
|
||||||
default_func),
|
default_func,
|
||||||
lambda : get_default_presence_action("offline_action"))]
|
bare_from_jid),
|
||||||
|
lambda bare_from_jid: \
|
||||||
|
get_default_presence_action("offline_action"))]
|
||||||
|
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
|
|||||||
@@ -58,18 +58,18 @@ class ExampleAccount(Account):
|
|||||||
[("login", "text-single", None,
|
[("login", "text-single", None,
|
||||||
lambda field_value, default_func, bare_from_jid: \
|
lambda field_value, default_func, bare_from_jid: \
|
||||||
account.mandatory_field(field_value),
|
account.mandatory_field(field_value),
|
||||||
lambda : ""),
|
lambda bare_from_jid: ""),
|
||||||
("password", "text-private", None,
|
("password", "text-private", None,
|
||||||
lambda field_value, default_func, bare_from_jid: \
|
lambda field_value, default_func, bare_from_jid: \
|
||||||
password_post_func(field_value),
|
password_post_func(field_value),
|
||||||
lambda : ""),
|
lambda bare_from_jid: ""),
|
||||||
("store_password", "boolean", None, account.default_post_func,
|
("store_password", "boolean", None, account.default_post_func,
|
||||||
lambda : True),
|
lambda bare_from_jid: True),
|
||||||
("test_enum", "list-single", ["choice1", "choice2", "choice3"],
|
("test_enum", "list-single", ["choice1", "choice2", "choice3"],
|
||||||
account.default_post_func,
|
account.default_post_func,
|
||||||
lambda : "choice2"),
|
lambda bare_from_jid: "choice2"),
|
||||||
("test_int", "text-single", None, account.int_post_func,
|
("test_int", "text-single", None, account.int_post_func,
|
||||||
lambda : 44)]
|
lambda bare_from_jid: 44)]
|
||||||
|
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ class Example2Account(Account):
|
|||||||
real_class = cls
|
real_class = cls
|
||||||
return Account.get_register_fields(real_class) + \
|
return Account.get_register_fields(real_class) + \
|
||||||
[("test_new_int", "text-single", None, account.int_post_func,
|
[("test_new_int", "text-single", None, account.int_post_func,
|
||||||
lambda : 43)]
|
lambda bare_from_jid: 43)]
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
class PresenceAccountExample(PresenceAccount):
|
class PresenceAccountExample(PresenceAccount):
|
||||||
@@ -115,7 +115,7 @@ class PresenceAccountExample(PresenceAccount):
|
|||||||
real_class = cls
|
real_class = cls
|
||||||
return PresenceAccount.get_register_fields(real_class) + \
|
return PresenceAccount.get_register_fields(real_class) + \
|
||||||
[("test_new_int", "text-single", None, account.int_post_func,
|
[("test_new_int", "text-single", None, account.int_post_func,
|
||||||
lambda : 43)]
|
lambda bare_from_jid: 43)]
|
||||||
get_register_fields = classmethod(_get_register_fields)
|
get_register_fields = classmethod(_get_register_fields)
|
||||||
|
|
||||||
class AccountModule_TestCase(unittest.TestCase):
|
class AccountModule_TestCase(unittest.TestCase):
|
||||||
@@ -124,11 +124,14 @@ class AccountModule_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(result, "test")
|
self.assertEquals(result, "test")
|
||||||
|
|
||||||
def test_default_post_func_default_value(self):
|
def test_default_post_func_default_value(self):
|
||||||
result = account.default_post_func("", lambda : "test", "user1@jcl.test.com")
|
result = account.default_post_func("",
|
||||||
|
lambda bare_from_jid: "test", \
|
||||||
|
"user1@jcl.test.com")
|
||||||
self.assertEquals(result, "test")
|
self.assertEquals(result, "test")
|
||||||
|
|
||||||
def test_default_post_func_default_value2(self):
|
def test_default_post_func_default_value2(self):
|
||||||
result = account.default_post_func(None, lambda : "test", "user1@jcl.test.com")
|
result = account.default_post_func(None, lambda bare_from_jid: "test", \
|
||||||
|
"user1@jcl.test.com")
|
||||||
self.assertEquals(result, "test")
|
self.assertEquals(result, "test")
|
||||||
|
|
||||||
def test_int_post_func(self):
|
def test_int_post_func(self):
|
||||||
@@ -136,11 +139,13 @@ class AccountModule_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(result, 42)
|
self.assertEquals(result, 42)
|
||||||
|
|
||||||
def test_int_post_func_default_value(self):
|
def test_int_post_func_default_value(self):
|
||||||
result = account.int_post_func("", lambda : 42, "user1@jcl.test.com")
|
result = account.int_post_func("", lambda bare_from_jid: 42, \
|
||||||
|
"user1@jcl.test.com")
|
||||||
self.assertEquals(result, 42)
|
self.assertEquals(result, 42)
|
||||||
|
|
||||||
def test_int_post_func_default_value(self):
|
def test_int_post_func_default_value(self):
|
||||||
result = account.int_post_func(None, lambda : 42, "user1@jcl.test.com")
|
result = account.int_post_func(None, lambda bare_from_jid: 42, \
|
||||||
|
"user1@jcl.test.com")
|
||||||
self.assertEquals(result, 42)
|
self.assertEquals(result, 42)
|
||||||
|
|
||||||
def test_mandatory_field_empty(self):
|
def test_mandatory_field_empty(self):
|
||||||
@@ -170,7 +175,8 @@ class InheritableAccount_TestCase(unittest.TestCase):
|
|||||||
field_default_func) in self.account_class.get_register_fields():
|
field_default_func) in self.account_class.get_register_fields():
|
||||||
if field_name is not None:
|
if field_name is not None:
|
||||||
try:
|
try:
|
||||||
field_post_func(field_default_func(), field_default_func, "user1@jcl.test.com")
|
field_post_func(field_default_func("user1@jcl.test.com"),
|
||||||
|
field_default_func, "user1@jcl.test.com")
|
||||||
except FieldError, error:
|
except FieldError, error:
|
||||||
# this type of error is OK
|
# this type of error is OK
|
||||||
pass
|
pass
|
||||||
@@ -269,11 +275,12 @@ class PresenceAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
self.assertEquals(post_func(possible_action, default_func,
|
self.assertEquals(post_func(possible_action, default_func,
|
||||||
"user1@jcl.test.com"),
|
"user1@jcl.test.com"),
|
||||||
int(possible_action))
|
int(possible_action))
|
||||||
self.assertTrue(str(default_func()) in possibles_actions)
|
self.assertTrue(str(default_func("user1@jcl.test.com")) \
|
||||||
|
in possibles_actions)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
post_func("42", default_func, "user1@jcl.test.com")
|
post_func("42", default_func, "user1@jcl.test.com")
|
||||||
default_func()
|
default_func("user1@jcl.test.com")
|
||||||
except FieldError, error:
|
except FieldError, error:
|
||||||
pass
|
pass
|
||||||
except Exception, exception:
|
except Exception, exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user