本文整理汇总了Python中gluon.sqlhtml.OptionsWidget.widget方法的典型用法代码示例。如果您正苦于以下问题:Python OptionsWidget.widget方法的具体用法?Python OptionsWidget.widget怎么用?Python OptionsWidget.widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.sqlhtml.OptionsWidget
的用法示例。
在下文中一共展示了OptionsWidget.widget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _select_field
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def _select_field(self, list_fields, form_values=None, **attr):
"""
Returns a SELECT of field names
@param list_fields: the fields to include in the options list
@param attr: the HTML attributes for the SELECT
"""
resource = self.resource
name = attr["_name"]
if form_values:
value = form_values.get(name, "")
else:
value = ""
if "." not in value.split("$", 1)[0]:
value = "%s.%s" % (resource.alias, value)
table = self.table
rfields, j, l, d = resource.resolve_selectors(list_fields,
skip_components=False)
options = [(f.selector, f.label) for f in rfields
if f.show and
(f.field is None or f.field.name != table._id.name)]
dummy_field = Storage(name=name, requires=IS_IN_SET(options))
return OptionsWidget.widget(dummy_field, value, **attr)
示例2: _select_field
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def _select_field(self, list_fields, form_values=None, **attr):
"""
Returns a SELECT of field names
@param list_fields: the fields to include in the options list
@param attr: the HTML attributes for the SELECT
"""
name = attr["_name"]
if form_values:
value = form_values.get(name, "")
else:
value = ""
table = self.table
lfields, joins, left, distinct = self.resource.resolve_selectors(list_fields,
skip_components=False)
options = []
for f in lfields:
if (f.field is None or f.field.name != table._id.name) and f.show:
options.append((f.selector, f.label))
dummy_field = Storage(name=name,
requires=IS_IN_SET(options))
return OptionsWidget.widget(dummy_field, value, **attr)
示例3: widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [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
示例4: _select_method
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def _select_method(methods, form_values=None, **attr):
"""
Returns a SELECT of aggregation methods
@param methods: list of methods to show
@param attr: the HTML attributes for the SELECT
"""
supported_methods = S3Report.METHODS
if methods:
methods = [(m, supported_methods[m])
for m in methods
if m in supported_methods]
else:
methods = supported_methods.items()
name = attr["_name"]
if form_values:
value = form_values[name]
else:
value = None
options = []
for method, label in methods:
options.append((method, label))
dummy_field = Storage(name=name,
requires=IS_IN_SET(options))
return OptionsWidget.widget(dummy_field, value, **attr)
示例5: axis_options
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def axis_options(self, axis,
options=None,
get_vars=None,
widget_id=None):
"""
Construct an OptionsWidget for rows or cols axis
@param axis: "rows" or "cols"
@param options: the report options
@param get_vars: the GET vars if the request (as dict)
@param widget_id: the HTML element ID for the widget
"""
resource = self.resource
prefix = resource.prefix_selector
# Get all selectors
if options and axis in options:
fields = options[axis]
else:
fields = resource.get_config("list_fields")
if not fields:
fields = [f.name for f in resource.readable_fields()]
# Resolve the selectors
pkey = str(resource._id)
resolve_selector = resource.resolve_selector
rfields = []
append = rfields.append
for f in fields:
if isinstance(f, (tuple, list)):
label, selector = f[:2]
else:
label, selector = None, f
rfield = resolve_selector(selector)
if rfield.colname == pkey:
continue
if label:
rfield.label = label
append(rfield)
# Get current value
if get_vars and axis in get_vars:
value = get_vars[axis]
else:
value = ""
if value:
value = prefix(value)
# Dummy field
opts = [(prefix(rfield.selector), rfield.label) for rfield in rfields]
dummy_field = Storage(name=axis, requires=IS_IN_SET(opts))
# Construct widget
return OptionsWidget.widget(dummy_field,
value,
_id=widget_id,
_name=axis,
_class="pt-%s" % axis)
示例6: rating_widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def rating_widget(f,v):
from gluon.sqlhtml import OptionsWidget
import uuid
id = str(uuid.uuid4())
for path in DEPENDENCIES:
response.files.append(path)
return DIV(SPAN(_id="stars-cap"),
DIV(OptionsWidget.widget(f,v),_id=id),
SCRIPT("jQuery(function(){jQuery('#%s').stars({inputType: 'select'});});" % id))
示例7: time_options
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def time_options(self,
options=None,
get_vars=None,
widget_id=None):
T = current.T
resource = self.resource
prefix = resource.prefix_selector
# Time options:
if options and "time" in options:
opts = options["time"]
else:
# (label, start, end, slots)
# If you specify a start, then end is relative to that - without start, end is relative to now
opts = (("All up to now", "", "", ""),
("Last Year", "-1year", "", "months"),
("Last 6 Months", "-6months", "", "weeks"),
("Last Quarter", "-3months", "", "weeks"),
("Last Month", "-1month", "", "days"),
("Last Week", "-1week", "", "days"),
("All/+1 Month", "", "+1month", ""),
("All/+2 Month", "", "+2month", ""),
("-6/+3 Months", "-6months", "+9months", "months"),
("-3/+1 Months", "-3months", "+4months", "weeks"),
("-4/+2 Weeks", "-4weeks", "+6weeks", "weeks"),
("-2/+1 Weeks", "-2weeks", "+3weeks", "days"),
)
widget_opts = []
for opt in opts:
label, start, end, slots = opt
widget_opts.append(("|".join((start, end, slots)), T(label)))
# Get current value
if get_vars:
start = get_vars.get("start", "")
end = get_vars.get("end", "")
slots = get_vars.get("slots", "")
else:
start = end = slots = ""
value = "|".join((start, end, slots))
# Dummy field
dummy_field = Storage(name="time",
requires=IS_IN_SET(widget_opts))
# Construct widget
return OptionsWidget.widget(dummy_field,
value,
_id=widget_id,
_name="time",
_class="tp-time",
)
示例8: create_widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def create_widget(self, field, value, clean_val, multi, restricted, rval):
"""create either a single select widget or multiselect widget"""
if multi:
w = MultipleOptionsWidget.widget(field, value)
# TODO: Create filtered multiple options widget class
else:
if rval:
w = FilteredOptionsWidget.widget(field, value, restricted, rval)
else:
w = OptionsWidget.widget(field, value)
return w
示例9: widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def widget(self, f, v):
uid = str(uuid.uuid4())[:8]
opts = 'disabled: %s, oneVoteOnly: %s' % (str(self.disabled).lower(),
str(self.single_vote).lower())
wrapper = DIV(SPAN(_id="stars-cap"),
_id="stars-wrapper_%s" % uid)
from gluon.sqlhtml import OptionsWidget
inp = OptionsWidget.widget(f,v)
scr = SCRIPT('jQuery("#stars-wrapper_%s").stars('\
'{inputType: "select", %s});' % (uid, opts))
scr2 = SCRIPT('$("form").submit(function() {$("[name=%s]").removeAttr("disabled");});'% f.name)
wrapper.append(inp)
wrapper.append(scr)
wrapper.append(scr2)
return wrapper
示例10: _field_select
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def _field_select(self, name, options=None, form_values=None, **attr):
"""
Returns a SELECT of field names
@param name: the element name
@param options: the report options
@param form_values: the form values to populate the widget
@param attr: the HTML attributes for the widget
"""
resource = self.resource
if options and name in options:
fields = options[name]
else:
fields = self._config("list_fields", None)
if not fields:
fields = [f.name for f in resource.readable_fields()]
prefix = (
lambda v: "%s.%s" % (resource.alias, v) if "." not in v.split("$", 1)[0] else v.replace("~", resource.alias)
)
attr = Storage(attr)
if "_name" not in attr:
attr["_name"] = name
if "_id" not in attr:
attr["_id"] = "report-%s" % name
if form_values:
value = form_values.get(name, "")
else:
value = ""
if value:
value = prefix(value)
table = self.table
rfields, j, l, d = resource.resolve_selectors(fields)
opts = [
(prefix(f.selector), f.label)
for f in rfields
if f.show and (f.field is None or f.field.name != table._id.name)
]
dummy_field = Storage(name=name, requires=IS_IN_SET(opts))
return OptionsWidget.widget(dummy_field, value, **attr)
示例11: widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def widget(self, field, value):
#generate the standard widget for this field
from gluon.sqlhtml import OptionsWidget
select_widget = OptionsWidget.widget(field, value)
#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(T(self.button_text), _id=my_select_id+"_option_add_trigger")
#create javascript for creating and opening the dialog
js = 'jQuery( "#%s_dialog-form" ).dialog({autoOpen: false, show: "blind", hide: "explode", width: %s});' % (my_select_id, self.dialog_width)
js += 'jQuery( "#%s_option_add_trigger" ).click(function() { jQuery( "#%s_dialog-form" ).dialog( "open" );return false;}); ' % (my_select_id, my_select_id)
js += 'jQuery(function() { jQuery( "#%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
示例12: widget
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def widget(self, field, value):
LookupWidget.widget_files()
width = self.width or getattr(field, "width_lookup", None)
attr = {}
if not width:
attr["_class"] = "span4"
attr["_style"] = "height: 20px; margin-bottom: 14px;"
if width:
attr["_style"] += "width:%s;" % width
wgt_default = OptionsWidget.widget(field, value, **attr)
wgt_id = wgt_default.attributes.get("_id", "no_id")
js = """
jQuery(document).ready(function(){
jQuery('#%(field_name)s').select2();
});
""" % {
"field_name": wgt_id
}
jq_script = SCRIPT(js, _type="text/javascript")
btn_new = ""
if self.add_new:
btn_new = A(
I(_class="fa fa-plus-circle"),
_href=self.add_new,
_class="btn btn-small",
_title=current.T("New record"),
_style="margin-top: 0px; margin-left:3px;",
**{"_data-toggle": "tooltip"}
)
wrapper = DIV(_class="LookupWidget")
wrapper.components.extend([wgt_default, btn_new, jq_script])
return wrapper
示例13: type
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
opt = w.element(_value=self.value)
i = w.elements().index(opt)
w.append(opt)
del w[i - 1]
else:
print e
except Exception, e:
print e, type(e)
pprint([e["_value"] for e in w.elements()])
else:
if self.orderby or self.rval or self.restrictor:
w = FilteredOptionsWidget.widget(
self.field, self.value, orderby=self.orderby, restricted=self.restricted, rval=self.rval
)
else:
w = OptionsWidget.widget(self.field, self.value)
w["_id"] = "{}_{}".format(self.fieldset[0], self.fieldset[1])
w["_name"] = self.fieldset[1]
myclasses = "plugin_ajaxselect "
if not self.multi in [None, False, "False"]:
myclasses += "multiple "
if not self.restrictor in [None, "None", "none"]:
myclasses += "restrictor for_{} ".format(self.restrictor)
if not self.restricted in [None, "None", "none"]:
myclasses += "restricted by_{} ".format(self.restricted)
w["_class"] = myclasses
return w
def _make_refresher(self, wrappername, linktable, uargs, uvars):
示例14: register
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def register():
"""
Registration for Organisations
- custom form
"""
s3mgr.load("pr_address")
# Which type of organisation are we registering?
don = False
vol = False
if "type" in request.vars:
if request.vars.type == "don":
don = True
elif request.vars.type == "vol":
vol = True
auth.settings.registration_requires_approval = True
auth.messages.submit_button = T("I accept. Create my account.")
request.args = ["register"]
_table_user.language.default = T.accepted_language
_table_user.language.readable = False
_table_user.language.writable = False
form = auth()
form.attributes["_id"] = "regform"
# Custom class for Submit Button
form[0][-1][0][0]["_class"] = "accept-button"
# Cancel button
form[0][-1][0].append(BR())
#form[0][-1][1].append(INPUT(_type="reset", _value=T("Cancel")))
form[0][-1][0].append(INPUT(_type="button",
_value=T("Cancel"),
_class="wide-grey-button",
_onClick="javascript: history.go(-1)"))
formstyle = s3.crud.formstyle
# Organisation
if form.errors.organisation:
organisation_error = DIV(form.errors.organisation,
_id="organisation__error",
_class="error",
_style="display: block;")
else:
organisation_error = ""
if don:
label = T("Corporation/Organization Name")
else:
label = T("Organization Name")
row = formstyle(id = "organisation",
label = LABEL("%s:" % label,
SPAN(" *", _class="req")),
widget = DIV(INPUT(_name="organisation",
_id="organisation",
_class="string"),
organisation_error),
comment = "")
form[0].insert(0, row)
# Industry Sector
if vol:
hidden = True
widget = INPUT(_name="sector_id",
_id="sector_id",
_class="string")
else:
from gluon.sqlhtml import OptionsWidget
hidden = False
widget = OptionsWidget.widget(db.org_organisation.sector_id,
value="")
# dropdown
row = formstyle(id = "sector_id",
label = LABEL("%s:" % T("Industry Sector")),
widget = widget,
comment = "",
hidden = hidden)
form[0].insert(1, row)
# freetext box for not listed
row = formstyle(id = "sector_other",
label = LABEL("%s:" % T("Other Sector not listed"),
SPAN(" *", _class="req")),
widget = INPUT(_name="sector_other",
_id="org_organisation_sector_other",
_class="string"),
comment = "",
hidden = True)
form[0].insert(2, row)
table = db.org_sector
query = (table.uuid == "OTHER_UNLISTED")
other_unlisted = db(query).select(table.id,
limitby=(0, 1)).first()
if other_unlisted:
other_unlisted = other_unlisted.id
# Primary Contact Person section
row = TR(TD(LABEL(T("Primary Contact")),
_colspan="3",
_class="subheading"))
form[0][2].append(row)
#.........这里部分代码省略.........
示例15: layer_options
# 需要导入模块: from gluon.sqlhtml import OptionsWidget [as 别名]
# 或者: from gluon.sqlhtml.OptionsWidget import widget [as 别名]
def layer_options(self,
options=None,
get_vars=None,
widget_id=None):
"""
Construct an OptionsWidget for the fact layer
@param options: the report options
@param get_vars: the GET vars if the request (as dict)
@param widget_id: the HTML element ID for the widget
"""
resource = self.resource
from s3data import S3PivotTable
all_methods = S3PivotTable.METHODS
# Get all layers
layers = None
methods = None
if options:
if "methods" in options:
methods = options["methods"]
if "fact" in options:
layers = options["fact"]
if not layers:
layers = resource.get_config("list_fields")
if not layers:
layers = [f.name for f in resource.readable_fields()]
if not methods:
methods = all_methods
# Resolve layers
prefix = resource.prefix_selector
opts = []
for layer in layers:
# Extract layer option
if type(layer) is tuple and \
(isinstance(layer[0], lazyT) or layer[1] not in all_methods):
opt = [layer]
else:
opt = list(layer) \
if isinstance(layer, (tuple, list)) else [layer]
# Get field label and selector
s = opt[0]
if isinstance(s, tuple):
label, selector = s
else:
label, selector = None, s
selector = prefix(selector)
# Resolve the selector
rfield = resource.resolve_selector(selector)
if not rfield.field and not rfield.virtual:
continue
if label is not None:
rfield.label = label
# Autodetect methods?
if len(opt) == 1:
# Only field given -> auto-detect aggregation methods
is_amount = None
ftype = rfield.ftype
if ftype == "integer":
is_amount = True
requires = rfield.requires
if not isinstance(requires, (list, tuple)):
requires = [requires]
for r in requires:
if isinstance(r, IS_IN_SET) or \
isinstance(r, IS_EMPTY_OR) and \
isinstance(r.other, IS_IN_SET):
is_amount = False
elif ftype == "double":
is_amount = True
elif ftype[:9] == "reference" or \
ftype[:5] == "list:" or \
ftype in ("id", "string", "text"):
is_amount = False
if ftype in ("datetime", "date", "time"):
mopts = ["min", "max", "list"]
elif is_amount is None:
mopts = ["sum", "min", "max", "avg", "count", "list"]
elif is_amount:
mopts = ["sum", "min", "max", "avg"]
else:
mopts = ["count", "list"]
opts.extend([(rfield, selector, m)
for m in mopts if m in methods])
else:
# Explicit method specified
opt.insert(0, rfield)
opts.append(opt)
# Construct default labels
T = current.T
RECORDS = T("Records")
layer_opts = []
#.........这里部分代码省略.........