Merge pull request #912 from ilvalle/sqlcustomtype

extend sqlcustomform to support widget/represent
This commit is contained in:
mdipierro
2015-04-15 13:01:50 -05:00

View File

@@ -1205,6 +1205,9 @@ class SQLFORM(FORM):
elif field.type == 'boolean':
inp = self.widgets.boolean.widget(
field, default, _disabled=True)
elif isinstance(field.type, SQLCustomType) and callable(field.type.represent):
# SQLCustomType has a represent, use it
inp = field.type.represent(default, record)
else:
inp = field.formatter(default)
if getattr(field, 'show_if', None):
@@ -1246,6 +1249,9 @@ class SQLFORM(FORM):
dspval = ''
elif field.type == 'blob':
continue
elif isinstance(field.type, SQLCustomType) and callable(field.type.widget):
# SQLCustomType has a widget, use it
inp = field.type.widget(field, default)
else:
field_type = widget_class.match(str(field.type)).group()
field_type = field_type in self.widgets and field_type or 'string'
@@ -2708,6 +2714,9 @@ class SQLFORM(FORM):
_href='%s/%s' % (upload, value))
else:
value = ''
elif isinstance(field.type, SQLCustomType) and callable(field.type.represent):
# SQLCustomType has a represent, use it
value = field.type.represent(value, row)
if isinstance(value, str):
value = truncate_string(value, maxlength)
elif not isinstance(value, XmlComponent):