本文整理汇总了Python中gluon.sqlhtml.OptionsWidget._attributes方法的典型用法代码示例。如果您正苦于以下问题:Python OptionsWidget._attributes方法的具体用法?Python OptionsWidget._attributes怎么用?Python OptionsWidget._attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.sqlhtml.OptionsWidget
的用法示例。
在下文中一共展示了OptionsWidget._attributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import _attributes [as 别名]
def widget(self, field, value,**attributes):
#generate the standard widget for this field
if self.multiple == True:
select_widget = MultipleOptionsWidget.widget(field, value, size=7)
attr = MultipleOptionsWidget._attributes(field, {'value':value}, **attributes)
else:
select_widget = OptionsWidget.widget(field, value)
attr = OptionsWidget._attributes(field, {'value':value}, **attributes)
#get the widget's id (need to know later on so can tell receiving controller what to update)
my_select_id = select_widget.attributes.get('_id', None)
add_args = [my_select_id]
#create a div that will load the specified controller via ajax
form_loader_div = DIV(LOAD(c=self.controller, f=self.function, args=add_args,ajax=True), _id=my_select_id+"_dialog-form", _title=self.form_title)
#generate the "add" button that will appear next the options widget and open our dialog
activator_button = A(XML('<button type="button" class="btn btn-primary" data-toggle="button">'+T(self.button_text)+'</button>'), _id=my_select_id+"_option_add_trigger")
#create javascript for creating and opening the dialog
js = '$( "#%s_dialog-form" ).dialog({autoOpen: false, show: "blind", hide: "explode", width: %s});' % (my_select_id, self.dialog_width)
js += '$( "#%s_option_add_trigger" ).click(function() { $( "#%s_dialog-form" ).dialog( "open" );return false;}); ' % (my_select_id, my_select_id) #decorate our activator button for good measure
js += '$(function() { $( "#%s_option_add_trigger" ).button({text: true, icons: { primary: "ui-icon-circle-plus"} }); });' % (my_select_id)
jq_script=SCRIPT(js, _type="text/javascript")
wrapper = DIV(_id=my_select_id+"_adder_wrapper")
wrapper.components.extend([select_widget, form_loader_div, activator_button, jq_script])
return wrapper
示例2: widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import _attributes [as 别名]
def widget(field, value, **attributes):
"""
generates a TABLE tag, including INPUT checkboxes (multiple allowed)
see also: :meth:`FormWidget.widget`
"""
# was values = re.compile('[\w\-:]+').findall(str(value))
if isinstance(value, (list, tuple)):
values = [str(v) for v in value]
else:
values = [str(value)]
attr = OptionsWidget._attributes(field, {}, **attributes)
requires = field.requires
if not isinstance(requires, (list, tuple)):
requires = [requires]
if requires:
if hasattr(requires[0], 'options'):
options = requires[0].options()
else:
raise SyntaxError('widget cannot determine options of %s' % field)
options = [(k, v) for k, v in options if k != '']
opts = []
cols = attributes.get('cols', 1)
totals = len(options)
mods = totals % cols
rows = totals / cols
if mods:
rows += 1
for r_index in range(rows):
tds = []
for k, v in options[r_index * cols:(r_index + 1) * cols]:
if k in values:
r_value = k
else:
r_value = []
tds.append(LI(INPUT(_type='checkbox', _id='%s%s' % (field.name, k), _name=field.name,
requires=attr.get('requires', None),
hideerror=True, _value=k,
value=r_value), LABEL(v, _for='%s%s' % (field.name, k))))
opts.append(UL(tds, _style='list-style-type: none;'))
if opts:
opts[-1][0][0]['hideerror'] = False
return DIV(*opts, **attr)