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,
|
||||
label=label,
|
||||
name=field_name,
|
||||
value=default_func())
|
||||
value=default_func(bare_from_jid))
|
||||
if field_options is not None:
|
||||
for option_value in field_options:
|
||||
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):
|
||||
"""Default post process function: do nothing"""
|
||||
if field_value is None or str(field_value) == "":
|
||||
return default_func()
|
||||
return default_func(bare_from_jid)
|
||||
return field_value
|
||||
|
||||
def int_post_func(field_value, default_func, bare_from_jid):
|
||||
"""Return an integer from integer 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)
|
||||
|
||||
def mandatory_field(field_value):
|
||||
@@ -186,10 +186,11 @@ class PresenceAccount(Account):
|
||||
def get_possibles_actions(presence_action_field):
|
||||
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):
|
||||
return int(action)
|
||||
raise default_func()
|
||||
raise default_func(bare_from_jid)
|
||||
|
||||
def get_default_presence_action(presence_action_field):
|
||||
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: \
|
||||
is_action_possible("chat_action",
|
||||
action,
|
||||
default_func),
|
||||
lambda : get_default_presence_action("chat_action")),
|
||||
default_func,
|
||||
bare_from_jid),
|
||||
lambda bare_from_jid: get_default_presence_action("chat_action")),
|
||||
("online_action", "list-single",
|
||||
[str(action) for action in get_possibles_actions("online_action")],
|
||||
lambda action, default_func, bare_from_jid: \
|
||||
is_action_possible("online_action",
|
||||
action,
|
||||
default_func),
|
||||
lambda : get_default_presence_action("online_action")),
|
||||
default_func,
|
||||
bare_from_jid),
|
||||
lambda bare_from_jid: \
|
||||
get_default_presence_action("online_action")),
|
||||
("away_action", "list-single",
|
||||
[str(action) for action in get_possibles_actions("away_action")],
|
||||
lambda action, default_func, bare_from_jid: \
|
||||
is_action_possible("away_action",
|
||||
action,
|
||||
default_func),
|
||||
lambda : get_default_presence_action("away_action")),
|
||||
default_func,
|
||||
bare_from_jid),
|
||||
lambda bare_from_jid: get_default_presence_action("away_action")),
|
||||
("xa_action", "list-single",
|
||||
[str(action) for action in get_possibles_actions("xa_action")],
|
||||
lambda action, default_func, bare_from_jid: \
|
||||
is_action_possible("xa_action",
|
||||
action,
|
||||
default_func),
|
||||
lambda : get_default_presence_action("xa_action")),
|
||||
default_func,
|
||||
bare_from_jid),
|
||||
lambda bare_from_jid: get_default_presence_action("xa_action")),
|
||||
("dnd_action", "list-single",
|
||||
[str(action) for action in get_possibles_actions("dnd_action")],
|
||||
lambda action, default_func, bare_from_jid: \
|
||||
is_action_possible("dnd_action",
|
||||
action,
|
||||
default_func),
|
||||
lambda : get_default_presence_action("dnd_action")),
|
||||
default_func,
|
||||
bare_from_jid),
|
||||
lambda bare_from_jid: get_default_presence_action("dnd_action")),
|
||||
("offline_action", "list-single",
|
||||
[str(action) for action in get_possibles_actions("offline_action")],
|
||||
lambda action, default_func, bare_from_jid: \
|
||||
is_action_possible("offline_action",
|
||||
action,
|
||||
default_func),
|
||||
lambda : get_default_presence_action("offline_action"))]
|
||||
default_func,
|
||||
bare_from_jid),
|
||||
lambda bare_from_jid: \
|
||||
get_default_presence_action("offline_action"))]
|
||||
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
|
||||
@@ -58,18 +58,18 @@ class ExampleAccount(Account):
|
||||
[("login", "text-single", None,
|
||||
lambda field_value, default_func, bare_from_jid: \
|
||||
account.mandatory_field(field_value),
|
||||
lambda : ""),
|
||||
lambda bare_from_jid: ""),
|
||||
("password", "text-private", None,
|
||||
lambda field_value, default_func, bare_from_jid: \
|
||||
password_post_func(field_value),
|
||||
lambda : ""),
|
||||
lambda bare_from_jid: ""),
|
||||
("store_password", "boolean", None, account.default_post_func,
|
||||
lambda : True),
|
||||
lambda bare_from_jid: True),
|
||||
("test_enum", "list-single", ["choice1", "choice2", "choice3"],
|
||||
account.default_post_func,
|
||||
lambda : "choice2"),
|
||||
lambda bare_from_jid: "choice2"),
|
||||
("test_int", "text-single", None, account.int_post_func,
|
||||
lambda : 44)]
|
||||
lambda bare_from_jid: 44)]
|
||||
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
@@ -81,7 +81,7 @@ class Example2Account(Account):
|
||||
real_class = cls
|
||||
return Account.get_register_fields(real_class) + \
|
||||
[("test_new_int", "text-single", None, account.int_post_func,
|
||||
lambda : 43)]
|
||||
lambda bare_from_jid: 43)]
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
class PresenceAccountExample(PresenceAccount):
|
||||
@@ -115,7 +115,7 @@ class PresenceAccountExample(PresenceAccount):
|
||||
real_class = cls
|
||||
return PresenceAccount.get_register_fields(real_class) + \
|
||||
[("test_new_int", "text-single", None, account.int_post_func,
|
||||
lambda : 43)]
|
||||
lambda bare_from_jid: 43)]
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
class AccountModule_TestCase(unittest.TestCase):
|
||||
@@ -124,11 +124,14 @@ class AccountModule_TestCase(unittest.TestCase):
|
||||
self.assertEquals(result, "test")
|
||||
|
||||
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")
|
||||
|
||||
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")
|
||||
|
||||
def test_int_post_func(self):
|
||||
@@ -136,11 +139,13 @@ class AccountModule_TestCase(unittest.TestCase):
|
||||
self.assertEquals(result, 42)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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():
|
||||
if field_name is not None:
|
||||
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:
|
||||
# this type of error is OK
|
||||
pass
|
||||
@@ -269,11 +275,12 @@ class PresenceAccount_TestCase(InheritableAccount_TestCase):
|
||||
self.assertEquals(post_func(possible_action, default_func,
|
||||
"user1@jcl.test.com"),
|
||||
int(possible_action))
|
||||
self.assertTrue(str(default_func()) in possibles_actions)
|
||||
self.assertTrue(str(default_func("user1@jcl.test.com")) \
|
||||
in possibles_actions)
|
||||
else:
|
||||
try:
|
||||
post_func("42", default_func, "user1@jcl.test.com")
|
||||
default_func()
|
||||
default_func("user1@jcl.test.com")
|
||||
except FieldError, error:
|
||||
pass
|
||||
except Exception, exception:
|
||||
|
||||
Reference in New Issue
Block a user