Massimo DiPierro
2011-12-02 17:48:25 -06:00
parent 70d431846a
commit 789bbb4e59
2 changed files with 35 additions and 37 deletions
+1 -1
View File
@@ -1 +1 @@
Version 1.99.3 (2011-12-02 17:31:14) dev Version 1.99.3 (2011-12-02 17:48:23) dev
+34 -36
View File
@@ -60,22 +60,27 @@ def safe_float(x):
class FormWidget(object): class FormWidget(object):
""" """
helper for SQLFORM to generate form input fields (widget), helper for SQLFORM to generate form input fields
related to the fieldtype (widget), related to the fieldtype
""" """
@staticmethod _class = 'generic-widget'
def _attributes(field, widget_attributes, **attributes):
@classmethod
def _attributes(cls, field,
widget_attributes, **attributes):
""" """
helper to build a common set of attributes helper to build a common set of attributes
:param field: the field involved, some attributes are derived from this :param field: the field involved,
some attributes are derived from this
:param widget_attributes: widget related attributes :param widget_attributes: widget related attributes
:param attributes: any other supplied attributes :param attributes: any other supplied attributes
""" """
attr = dict( attr = dict(
_id = '%s_%s' % (field._tablename, field.name), _id = '%s_%s' % (field._tablename, field.name),
_class = widget_class.match(str(field.type)).group(), _class = cls._class or \
widget_class.match(str(field.type)).group(),
_name = field.name, _name = field.name,
requires = field.requires, requires = field.requires,
) )
@@ -102,7 +107,7 @@ class FormWidget(object):
raise NotImplementedError raise NotImplementedError
class StringWidget(FormWidget): class StringWidget(FormWidget):
_class = 'string'
@staticmethod @staticmethod
def widget(field, value, **attributes): def widget(field, value, **attributes):
""" """
@@ -121,36 +126,32 @@ class StringWidget(FormWidget):
class IntegerWidget(StringWidget): class IntegerWidget(StringWidget):
_class = 'integer'
pass
class DoubleWidget(StringWidget): class DoubleWidget(StringWidget):
_class = 'double'
pass
class DecimalWidget(StringWidget): class DecimalWidget(StringWidget):
_class = 'double'
pass
class TimeWidget(StringWidget): class TimeWidget(StringWidget):
_class = 'time'
pass
class DateWidget(StringWidget): class DateWidget(StringWidget):
_class = 'date'
pass
class DatetimeWidget(StringWidget): class DatetimeWidget(StringWidget):
_class = 'datetime'
pass pass
class TextWidget(FormWidget): class TextWidget(FormWidget):
_class = 'text'
@staticmethod @staticmethod
def widget(field, value, **attributes): def widget(field, value, **attributes):
@@ -160,15 +161,14 @@ class TextWidget(FormWidget):
see also: :meth:`FormWidget.widget` see also: :meth:`FormWidget.widget`
""" """
default = dict( default = dict(value = value)
value = value, attr = TextWidget._attributes(field, default,
) **attributes)
attr = TextWidget._attributes(field, default, **attributes)
return TEXTAREA(**attr) return TEXTAREA(**attr)
class BooleanWidget(FormWidget): class BooleanWidget(FormWidget):
_class = 'boolean'
@staticmethod @staticmethod
def widget(field, value, **attributes): def widget(field, value, **attributes):
@@ -178,12 +178,9 @@ class BooleanWidget(FormWidget):
see also: :meth:`FormWidget.widget` see also: :meth:`FormWidget.widget`
""" """
default=dict( default=dict(_type='checkbox', value=value)
_type='checkbox', attr = BooleanWidget._attributes(field, default,
value=value, **attributes)
)
attr = BooleanWidget._attributes(field, default, **attributes)
return INPUT(**attr) return INPUT(**attr)
@@ -207,11 +204,9 @@ class OptionsWidget(FormWidget):
see also: :meth:`FormWidget.widget` see also: :meth:`FormWidget.widget`
""" """
default = dict( default = dict(value=value)
value=value, attr = OptionsWidget._attributes(field, default,
) **attributes)
attr = OptionsWidget._attributes(field, default, **attributes)
requires = field.requires requires = field.requires
if not isinstance(requires, (list, tuple)): if not isinstance(requires, (list, tuple)):
requires = [requires] requires = [requires]
@@ -219,13 +214,13 @@ class OptionsWidget(FormWidget):
if hasattr(requires[0], 'options'): if hasattr(requires[0], 'options'):
options = requires[0].options() options = requires[0].options()
else: else:
raise SyntaxError, 'widget cannot determine options of %s' \ raise SyntaxError, 'widget cannot determine options of %s' % field
% field
opts = [OPTION(v, _value=k) for (k, v) in options] opts = [OPTION(v, _value=k) for (k, v) in options]
return SELECT(*opts, **attr) return SELECT(*opts, **attr)
class ListWidget(StringWidget): class ListWidget(StringWidget):
@staticmethod @staticmethod
def widget(field,value,**attributes): def widget(field,value,**attributes):
_id = '%s_%s' % (field._tablename, field.name) _id = '%s_%s' % (field._tablename, field.name)
@@ -413,6 +408,7 @@ class CheckboxesWidget(OptionsWidget):
class PasswordWidget(FormWidget): class PasswordWidget(FormWidget):
_class = 'password'
DEFAULT_PASSWORD_DISPLAY = 8*('*') DEFAULT_PASSWORD_DISPLAY = 8*('*')
@@ -436,6 +432,7 @@ class PasswordWidget(FormWidget):
class UploadWidget(FormWidget): class UploadWidget(FormWidget):
_class = 'upload'
DEFAULT_WIDTH = '150px' DEFAULT_WIDTH = '150px'
ID_DELETE_SUFFIX = '__delete' ID_DELETE_SUFFIX = '__delete'
@@ -535,6 +532,7 @@ class UploadWidget(FormWidget):
class AutocompleteWidget(object): class AutocompleteWidget(object):
_class = 'string'
def __init__(self, request, field, id_field=None, db=None, def __init__(self, request, field, id_field=None, db=None,
orderby=None, limitby=(0,10), orderby=None, limitby=(0,10),