Add list-single field type
darcs-hash:20070117175956-86b55-1d833aae947a048e6240a393837cfde02e918b6f.gz
This commit is contained in:
@@ -407,8 +407,8 @@ class JCLComponent(Component, object):
|
||||
jid = name + u"@"+unicode(self.jid))
|
||||
field = None
|
||||
try:
|
||||
for (field, field_type, field_post_func, field_default_func) in \
|
||||
self.account_class.get_register_fields():
|
||||
for (field, field_type, field_options, field_post_func, \
|
||||
field_default_func) in self.account_class.get_register_fields():
|
||||
setattr(_account, field, \
|
||||
x_data.get_field_value(field, \
|
||||
field_post_func, \
|
||||
@@ -671,21 +671,31 @@ class JCLComponent(Component, object):
|
||||
var = "name", \
|
||||
required = True)
|
||||
|
||||
for (field, field_type, post_func, default_func) in \
|
||||
for (field_name, field_type, field_options, post_func, default_func) in \
|
||||
self.account_class.get_register_fields():
|
||||
if field is None:
|
||||
if field_name is None:
|
||||
# TODO : Add page when empty tuple given
|
||||
pass
|
||||
else:
|
||||
lang_label_attr = self.account_class.__name__.lower() \
|
||||
+ "_" + field
|
||||
+ "_" + field_name
|
||||
if hasattr(lang_class, lang_label_attr):
|
||||
label = getattr(lang_class, lang_label_attr)
|
||||
else:
|
||||
label = field
|
||||
field = reg_form.add_field(field_type = field_type, \
|
||||
label = label, \
|
||||
var = field)
|
||||
label = field_name
|
||||
field = reg_form.add_field(field_type = field_type, \
|
||||
label = label, \
|
||||
var = field_name)
|
||||
if field_options is not None:
|
||||
for option_value in field_options:
|
||||
lang_label_attr = self.account_class.__name__.lower() \
|
||||
+ "_" + field_name + "_" + option_value
|
||||
if hasattr(lang_class, lang_label_attr):
|
||||
label = getattr(lang_class, lang_label_attr)
|
||||
else:
|
||||
label = option_value
|
||||
field.add_option(label = label, \
|
||||
value = option_value)
|
||||
if default_func == account.mandatory_field:
|
||||
field.required = True
|
||||
## TODO : get default value if any
|
||||
|
||||
@@ -120,6 +120,7 @@ class Account(InheritableSQLObject):
|
||||
- field_name: might be the name of one of the class attribut
|
||||
- field_type: 'text-single', 'hidden', 'text-private', 'boolean',
|
||||
'list-single', ...
|
||||
- field_options:
|
||||
- field_post_func: function called to process received field
|
||||
- field_default_func: function to return default value (or error if
|
||||
field is mandatory)
|
||||
@@ -193,18 +194,24 @@ class PresenceAccount(Account):
|
||||
|
||||
# TODO : check is_action_possible with presence_actions_fields (see partial eval function)
|
||||
return Account.get_register_fields() + \
|
||||
[(None, None, None, None), \
|
||||
("chat_action", "list-single", is_action_possible, \
|
||||
mandatory_field), \
|
||||
("online_action", "list-single", is_action_possible, \
|
||||
mandatory_field), \
|
||||
("away_action", "list-single", is_action_possible, \
|
||||
mandatory_field), \
|
||||
("xa_action", "list-single", is_action_possible, \
|
||||
mandatory_field), \
|
||||
("dnd_action", "list-single", is_action_possible, \
|
||||
mandatory_field), \
|
||||
("offline_action", "list-single", is_action_possible, \
|
||||
mandatory_field)]
|
||||
[(None, None, None, None, None), \
|
||||
("chat_action", "list-single", \
|
||||
[str(action) for action in cls.possibles_actions], \
|
||||
is_action_possible, mandatory_field), \
|
||||
("online_action", "list-single", \
|
||||
[str(action) for action in cls.possibles_actions], \
|
||||
is_action_possible, mandatory_field), \
|
||||
("away_action", "list-single", \
|
||||
[str(action) for action in cls.possibles_actions], \
|
||||
is_action_possible, mandatory_field), \
|
||||
("xa_action", "list-single", \
|
||||
[str(action) for action in cls.possibles_actions], \
|
||||
is_action_possible, mandatory_field), \
|
||||
("dnd_action", "list-single", \
|
||||
[str(action) for action in cls.possibles_actions], \
|
||||
is_action_possible, mandatory_field), \
|
||||
("offline_action", "list-single", \
|
||||
[str(action) for action in cls.possibles_actions], \
|
||||
is_action_possible, mandatory_field)]
|
||||
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
|
||||
@@ -437,6 +437,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
||||
self.assertEquals(fields[4].prop("type"), "list-single")
|
||||
self.assertEquals(fields[4].prop("var"), "test_enum")
|
||||
self.assertEquals(fields[4].prop("label"), "test_enum")
|
||||
# TODO : test options
|
||||
|
||||
self.assertEquals(fields[5].prop("type"), "text-single")
|
||||
self.assertEquals(fields[5].prop("var"), "test_int")
|
||||
@@ -572,6 +573,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
||||
self.assertEquals(field.prop("label"), "test_enum")
|
||||
self.assertEquals(field.children.name, "value")
|
||||
self.assertEquals(field.children.content, "choice3")
|
||||
# TODO : test options
|
||||
field = fields[5]
|
||||
self.assertEquals(field.prop("type"), "text-single")
|
||||
self.assertEquals(field.prop("var"), "test_int")
|
||||
|
||||
@@ -44,15 +44,16 @@ class AccountExample(Account):
|
||||
return password
|
||||
|
||||
return Account.get_register_fields() + \
|
||||
[("login", "text-single", account.string_not_null_post_func, \
|
||||
[("login", "text-single", None, account.string_not_null_post_func, \
|
||||
account.mandatory_field), \
|
||||
("password", "text-private", password_post_func, \
|
||||
("password", "text-private", None, password_post_func, \
|
||||
(lambda field_name: None)), \
|
||||
("store_password", "boolean", account.boolean_post_func, \
|
||||
("store_password", "boolean", None, account.boolean_post_func, \
|
||||
lambda field_name: True), \
|
||||
("test_enum", "list-single",account.string_not_null_post_func,\
|
||||
("test_enum", "list-single", ["choice1", "choice2", "choice3"], \
|
||||
account.string_not_null_post_func,\
|
||||
lambda field_name: "choice2"), \
|
||||
("test_int", "text-single", account.int_post_func, \
|
||||
("test_int", "text-single", None, account.int_post_func, \
|
||||
lambda field_name: 44)]
|
||||
|
||||
get_register_fields = classmethod(_get_register_fields)
|
||||
@@ -60,7 +61,9 @@ class AccountExample(Account):
|
||||
|
||||
class PresenceAccountExample(PresenceAccount):
|
||||
DO_SOMETHING_ELSE = 2
|
||||
possibles_actions = [DO_SOMETHING_ELSE]
|
||||
possibles_actions = [PresenceAccount.DO_NOTHING, \
|
||||
PresenceAccount.DO_SOMETHING, \
|
||||
DO_SOMETHING_ELSE]
|
||||
|
||||
def _get_presence_actions_fields(cls):
|
||||
"""See PresenceAccount._get_presence_actions_fields
|
||||
|
||||
Reference in New Issue
Block a user