本文整理汇总了Python中gluon.html.OPTION属性的典型用法代码示例。如果您正苦于以下问题:Python html.OPTION属性的具体用法?Python html.OPTION怎么用?Python html.OPTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gluon.html
的用法示例。
在下文中一共展示了html.OPTION属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: widget
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def widget(cls, field, value, **attributes):
"""
Generates a SELECT tag, including OPTIONs (only 1 option allowed)
see also: `FormWidget.widget`
"""
default = dict(value=value)
attr = cls._attributes(field, default,
**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)
opts = [OPTION(v, _value=k) for (k, v) in options]
return SELECT(*opts, **attr)
示例2: test_OPTION
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def test_OPTION(self):
self.assertEqual(OPTION('<>', _a='1', _b='2').xml(),
b'<option a="1" b="2" value="<>"><>' +
b'</option>')
示例3: test_OPTGROUP
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def test_OPTGROUP(self):
# Empty OPTGROUP test
self.assertEqual(OPTGROUP().xml(),
b'<optgroup></optgroup>')
# Not Empty OPTGROUP test
self.assertEqual(OPTGROUP('<>', _a='1', _b='2').xml(),
b'<optgroup a="1" b="2"><option value="<>"><></option></optgroup>')
# With an OPTION
self.assertEqual(OPTGROUP(OPTION('Option 1', _value='1'), _label='Group 1').xml(),
b'<optgroup label="Group 1"><option value="1">Option 1</option></optgroup>')
示例4: test_SELECT
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def test_SELECT(self):
self.assertEqual(SELECT('<>', _a='1', _b='2').xml(),
b'<select a="1" b="2">' +
b'<option value="<>"><></option></select>')
self.assertEqual(SELECT(OPTION('option 1', _value='1'),
OPTION('option 2', _value='2')).xml(),
b'<select><option value="1">option 1</option><option value="2">option 2</option></select>')
self.assertEqual(SELECT(OPTION('option 1', _value='1', _selected='selected'),
OPTION('option 2', _value='2'),
_multiple='multiple').xml(),
b'<select multiple="multiple"><option selected="selected" value="1">option 1</option><option value="2">option 2</option></select>')
# More then one select with mutilple
self.assertEqual(SELECT(OPTION('option 1', _value='1', _selected='selected'),
OPTION('option 2', _value='2', _selected='selected'),
_multiple='multiple').xml(),
b'<select multiple="multiple"><option selected="selected" value="1">option 1</option><option selected="selected" value="2">option 2</option></select>'
)
# OPTGROUP
self.assertEqual(SELECT(OPTGROUP(OPTION('option 1', _value='1'),
OPTION('option 2', _value='2'),
_label='Group 1',)).xml(),
b'<select><optgroup label="Group 1"><option value="1">option 1</option><option value="2">option 2</option></optgroup></select>')
# List
self.assertEqual(SELECT([1, 2, 3, 4, 5]).xml(),
b'<select><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>')
# Tuple
self.assertEqual(SELECT((1, 2, 3, 4, 5)).xml(),
b'<select><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>')
# String value
self.assertEqual(SELECT('Option 1', 'Option 2').xml(),
b'<select><option value="Option 1">Option 1</option><option value="Option 2">Option 2</option></select>')
# list as a value
self.assertEqual(SELECT(OPTION('option 1', _value=[1, 2, 3]),
OPTION('option 2', _value=[4, 5, 6], _selected='selected'),
_multiple='multiple').xml(),
b'<select multiple="multiple"><option value="[1, 2, 3]">option 1</option><option selected="selected" value="[4, 5, 6]">option 2</option></select>')
示例5: callback
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def callback(self):
if self.keyword in self.request.vars:
field = self.fields[0]
if settings and settings.global_settings.web2py_runtime_gae:
rows = self.db(field.__ge__(self.request.vars[self.keyword]) & field.__lt__(self.request.vars[self.keyword] + u'\ufffd')).select(orderby=self.orderby, limitby=self.limitby, *(self.fields+self.help_fields))
elif self.at_beginning:
rows = self.db(field.like(self.request.vars[self.keyword] + '%', case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
else:
rows = self.db(field.contains(self.request.vars[self.keyword], case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
if rows:
if self.is_reference:
id_field = self.fields[1]
if self.help_fields:
options = [OPTION(
self.help_string % dict([(h.name, s[h.name]) for h in self.fields[:1] + self.help_fields]),
_value=s[id_field.name], _selected=(k == 0)) for k, s in enumerate(rows)]
else:
options = [OPTION(
s[field.name], _value=s[id_field.name],
_selected=(k == 0)) for k, s in enumerate(rows)]
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*options).xml())
else:
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*[OPTION(s[field.name],
_selected=(k == 0))
for k, s in enumerate(rows)]).xml())
else:
raise HTTP(200, '')
示例6: callback
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def callback(self):
if self.keyword in self.request.vars:
field = self.fields[0]
if settings and settings.global_settings.web2py_runtime_gae:
rows = self.db(field.__ge__(self.request.vars[self.keyword]) & field.__lt__(self.request.vars[self.keyword] + u'\ufffd')).select(orderby=self.orderby, limitby=self.limitby, *(self.fields+self.help_fields))
else:
rows = self.db(field.like(self.request.vars[self.keyword] + '%', case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
if rows:
if self.is_reference:
id_field = self.fields[1]
if self.help_fields:
options = [OPTION(
self.help_string % dict([(h.name, s[h.name]) for h in self.fields[:1] + self.help_fields]),
_value=s[id_field.name], _selected=(k == 0)) for k, s in enumerate(rows)]
else:
options = [OPTION(
s[field.name], _value=s[id_field.name],
_selected=(k == 0)) for k, s in enumerate(rows)]
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*options).xml())
else:
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*[OPTION(s[field.name],
_selected=(k == 0))
for k, s in enumerate(rows)]).xml())
else:
raise HTTP(200, '')
示例7: callback
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def callback(self):
if self.keyword in self.request.vars:
field = self.fields[0]
if type(field) is Field.Virtual:
records = []
table_rows = self.db(self.db[field.tablename]).select(orderby=self.orderby)
count = 0
for row in table_rows:
if self.at_beginning:
if row[field.name].lower().startswith(self.request.vars[self.keyword]):
count += 1
records.append(row)
else:
if self.request.vars[self.keyword] in row[field.name].lower():
count += 1
records.append(row)
if count == 10:
break
rows = Rows(self.db, records, table_rows.colnames, compact=table_rows.compact)
elif settings and settings.global_settings.web2py_runtime_gae:
rows = self.db(field.__ge__(self.request.vars[self.keyword]) & field.__lt__(self.request.vars[self.keyword] + u'\ufffd')).select(orderby=self.orderby, limitby=self.limitby, *(self.fields+self.help_fields))
elif self.at_beginning:
rows = self.db(field.like(self.request.vars[self.keyword] + '%', case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
else:
rows = self.db(field.contains(self.request.vars[self.keyword], case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
if rows:
if self.is_reference:
id_field = self.fields[1]
if self.help_fields:
options = [OPTION(
self.help_string % dict([(h.name, s[h.name]) for h in self.fields[:1] + self.help_fields]),
_value=s[id_field.name], _selected=(k == 0)) for k, s in enumerate(rows)]
else:
options = [OPTION(
s[field.name], _value=s[id_field.name],
_selected=(k == 0)) for k, s in enumerate(rows)]
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*options).xml())
else:
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*[OPTION(s[field.name],
_selected=(k == 0))
for k, s in enumerate(rows)]).xml())
else:
raise HTTP(200, '')
示例8: callback
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def callback(self):
if self.keyword in self.request.vars:
field = self.fields[0]
if type(field) is FieldVirtual:
records = []
table_rows = self.db(self.db[field.tablename]).select(orderby=self.orderby)
count = 0
for row in table_rows:
if self.at_beginning:
if row[field.name].lower().startswith(self.request.vars[self.keyword]):
count += 1
records.append(row)
else:
if self.request.vars[self.keyword] in row[field.name].lower():
count += 1
records.append(row)
if count == 10:
break
rows = Rows(self.db, records, table_rows.colnames, compact=table_rows.compact)
elif settings and settings.global_settings.web2py_runtime_gae:
rows = self.db(field.__ge__(self.request.vars[self.keyword]) & field.__lt__(self.request.vars[self.keyword] + u'\ufffd')).select(orderby=self.orderby, limitby=self.limitby, *(self.fields+self.help_fields))
elif self.at_beginning:
rows = self.db(field.like(self.request.vars[self.keyword] + '%', case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
else:
rows = self.db(field.contains(self.request.vars[self.keyword], case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
if rows:
if self.is_reference:
id_field = self.fields[1]
if self.help_fields:
options = [OPTION(
self.help_string % dict([(h.name, s[h.name]) for h in self.fields[:1] + self.help_fields]),
_value=s[id_field.name], _selected=(k == 0)) for k, s in enumerate(rows)]
else:
options = [OPTION(
s[field.name], _value=s[id_field.name],
_selected=(k == 0)) for k, s in enumerate(rows)]
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*options).xml())
else:
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*[OPTION(s[field.name],
_selected=(k == 0))
for k, s in enumerate(rows)]).xml())
else:
raise HTTP(200, '')
示例9: callback
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def callback(self):
if self.keyword in self.request.vars:
field = self.fields[0]
selection = DalView(*(self.fields+self.help_fields),
translator=self.translator,
query=field.contains(self.request.vars[self.keyword], case_sensitive=False)
# query=field.like(self.request.vars[self.keyword] + '%', case_sensitive=False),
, orderby=self.orderby
# , distinct=self.distinct # FIXME TODO
, limitby=self.limitby
)
if getattr(current, 'DBG', None):
current.session.T_AutocompleteWidget_SQL = selection.get_sql()
rows = selection.execute() # compact=False
# rows.compact = True # peculiarities of DAL..
# rows = self.db(field.like(self.request.vars[self.keyword] + '%', case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
if rows:
if self.is_reference:
id_field = self.fields[1]
if self.help_fields:
options = [OPTION(
self.help_string % dict([(h.name, s[h.name]) for h in self.fields[:1] + self.help_fields]),
_value=s[id_field.name], _selected=(k == 0)) for k, s in enumerate(rows)]
else:
options = [OPTION(
s[field.name], _value=s[id_field.name],
_selected=(k == 0)) for k, s in enumerate(rows)]
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*options).xml())
else:
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*[OPTION(s[field.name],
_selected=(k == 0))
for k, s in enumerate(rows)]).xml())
else:
raise HTTP(200, '')
示例10: callback_NEWw2p
# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import OPTION [as 别名]
def callback_NEWw2p(self):
if self.keyword in self.request.vars:
field = self.fields[0]
if type(field) is Field.Virtual:
records = []
table_rows = self.db(self.db[field.tablename]).select(orderby=self.orderby)
count = 0
for row in table_rows:
if self.at_beginning:
if row[field.name].lower().startswith(self.request.vars[self.keyword]):
count += 1
records.append(row)
else:
if self.request.vars[self.keyword] in row[field.name].lower():
count += 1
records.append(row)
if count == 10:
break
rows = Rows(self.db, records, table_rows.colnames, compact=table_rows.compact)
else:
# elif settings and settings.global_settings.web2py_runtime_gae:
# rows = self.db(field.__ge__(self.request.vars[self.keyword]) & field.__lt__(self.request.vars[self.keyword] + u'\ufffd')).select(orderby=self.orderby, limitby=self.limitby, *(self.fields+self.help_fields))
# elif self.at_beginning:
# rows = self.db(field.like(self.request.vars[self.keyword] + '%', case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
# else:
# rows = self.db(field.contains(self.request.vars[self.keyword], case_sensitive=False)).select(orderby=self.orderby, limitby=self.limitby, distinct=self.distinct, *(self.fields+self.help_fields))
rows = DalView(*(self.fields + self.help_fields),
translator=self.translator,
query=field.like(self.request.vars[self.keyword] + '%', case_sensitive=False),
orderby=self.orderby,
limitby=self.limitby,
distinct=self.distinct
).execute() # compact=False
if rows:
if self.is_reference:
id_field = self.fields[1]
if self.help_fields:
options = [OPTION(
self.help_string % dict([(h.name, s[h.name]) for h in self.fields[:1] + self.help_fields]),
_value=s[id_field.name], _selected=(k == 0)) for k, s in enumerate(rows)]
else:
options = [OPTION(
s[field.name], _value=s[id_field.name],
_selected=(k == 0)) for k, s in enumerate(rows)]
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*options).xml())
else:
raise HTTP(
200, SELECT(_id=self.keyword, _class='autocomplete',
_size=len(rows), _multiple=(len(rows) == 1),
*[OPTION(s[field.name],
_selected=(k == 0))
for k, s in enumerate(rows)]).xml())
else:
raise HTTP(200, '')