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