Merge pull request #912 from ilvalle/sqlcustomtype
extend sqlcustomform to support widget/represent
This commit is contained in:
@@ -1205,6 +1205,9 @@ class SQLFORM(FORM):
|
|||||||
elif field.type == 'boolean':
|
elif field.type == 'boolean':
|
||||||
inp = self.widgets.boolean.widget(
|
inp = self.widgets.boolean.widget(
|
||||||
field, default, _disabled=True)
|
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:
|
else:
|
||||||
inp = field.formatter(default)
|
inp = field.formatter(default)
|
||||||
if getattr(field, 'show_if', None):
|
if getattr(field, 'show_if', None):
|
||||||
@@ -1246,6 +1249,9 @@ class SQLFORM(FORM):
|
|||||||
dspval = ''
|
dspval = ''
|
||||||
elif field.type == 'blob':
|
elif field.type == 'blob':
|
||||||
continue
|
continue
|
||||||
|
elif isinstance(field.type, SQLCustomType) and callable(field.type.widget):
|
||||||
|
# SQLCustomType has a widget, use it
|
||||||
|
inp = field.type.widget(field, default)
|
||||||
else:
|
else:
|
||||||
field_type = widget_class.match(str(field.type)).group()
|
field_type = widget_class.match(str(field.type)).group()
|
||||||
field_type = field_type in self.widgets and field_type or 'string'
|
field_type = field_type in self.widgets and field_type or 'string'
|
||||||
@@ -2708,6 +2714,9 @@ class SQLFORM(FORM):
|
|||||||
_href='%s/%s' % (upload, value))
|
_href='%s/%s' % (upload, value))
|
||||||
else:
|
else:
|
||||||
value = ''
|
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):
|
if isinstance(value, str):
|
||||||
value = truncate_string(value, maxlength)
|
value = truncate_string(value, maxlength)
|
||||||
elif not isinstance(value, XmlComponent):
|
elif not isinstance(value, XmlComponent):
|
||||||
|
|||||||
Reference in New Issue
Block a user