Add list-single field type

darcs-hash:20070117175956-86b55-1d833aae947a048e6240a393837cfde02e918b6f.gz
This commit is contained in:
David Rousselie
2007-01-17 18:59:56 +01:00
parent 56209ddff1
commit 583679b6ed
4 changed files with 51 additions and 29 deletions

View File

@@ -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

View File

@@ -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)