当前位置: 首页>>代码示例>>Python>>正文


Python html.SELECT属性代码示例

本文整理汇总了Python中gluon.html.SELECT属性的典型用法代码示例。如果您正苦于以下问题:Python html.SELECT属性的具体用法?Python html.SELECT怎么用?Python html.SELECT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在gluon.html的用法示例。


在下文中一共展示了html.SELECT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: widget

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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) 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:22,代码来源:sqlhtml.py

示例2: callback

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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, '') 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:35,代码来源:sqlhtml.py

示例3: formstyle_bootstrap3_stacked

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap3_stacked(form, fields):
    """ bootstrap 3 format form layout

    Note:
        Experimental!
    """
    parent = CAT()
    for id, label, controls, help in fields:
        # wrappers
        _help = SPAN(help, _class='help-block')
        # embed _help into _controls
        _controls = CAT(controls, _help)
        if isinstance(controls, INPUT):
            if controls['_type'] == 'submit':
                controls.add_class('btn btn-primary')
            if controls['_type'] == 'button':
                controls.add_class('btn btn-default')
            elif controls['_type'] == 'file':
                controls.add_class('input-file')
            elif controls['_type'] in ('text', 'password'):
                controls.add_class('form-control')
            elif controls['_type'] == 'checkbox':
                label['_for'] = None
                label.insert(0, controls)
                _controls = DIV(label, _help, _class="checkbox")
                label = ''
            elif isinstance(controls, (SELECT, TEXTAREA)):
                controls.add_class('form-control')

        elif isinstance(controls, SPAN):
            _controls = P(controls.components)

        elif isinstance(controls, UL):
            for e in controls.elements("input"):
                e.add_class('form-control')

        if isinstance(label, LABEL):
            label['_class'] = add_class(label.get('_class'),'control-label')

        parent.append(DIV(label, _controls, _class='form-group', _id=id))
    return parent 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:43,代码来源:sqlhtml.py

示例4: callback

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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, '') 
开发者ID:StuffShare,项目名称:StuffShare,代码行数:33,代码来源:sqlhtml.py

示例5: formstyle_bootstrap3_stacked

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap3_stacked(form, fields):
    """ bootstrap 3 format form layout

    Note:
        Experimental!
    """
    parent = CAT()
    for id, label, controls, help in fields:
        # wrappers
        _help = SPAN(help, _class='help-block')
        # embed _help into _controls
        _controls = CAT(controls, _help)
        if isinstance(controls, INPUT):
            if controls['_type'] == 'submit':
                controls.add_class('btn btn-primary')
            if controls['_type'] == 'button':
                controls.add_class('btn btn-default')
            elif controls['_type'] == 'file':
                controls.add_class('input-file')
            elif controls['_type'] == 'text':
                controls.add_class('form-control')
            elif controls['_type'] == 'password':
                controls.add_class('form-control')
            elif controls['_type'] == 'checkbox':
                label['_for'] = None
                label.insert(0, controls)
                _controls = DIV(label, _help, _class="checkbox")
                label = ''
            elif isinstance(controls, SELECT):
                controls.add_class('form-control')
            elif isinstance(controls, TEXTAREA):
                controls.add_class('form-control')

        elif isinstance(controls, SPAN):
             _controls = P(controls.components)

        if isinstance(label, LABEL):
            label['_class'] = 'control-label'

        parent.append(DIV(label, _controls, _class='form-group', _id=id))
    return parent 
开发者ID:StuffShare,项目名称:StuffShare,代码行数:43,代码来源:sqlhtml.py

示例6: formstyle_bootstrap

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap(form, fields):
    """ bootstrap 2.3.x format form layout """
    form.add_class('form-horizontal')
    parent = FIELDSET()
    for id, label, controls, help in fields:
        # wrappers
        _help = SPAN(help, _class='help-block')
        # embed _help into _controls
        _controls = DIV(controls, _help, _class='controls')
        # submit unflag by default
        _submit = False

        if isinstance(controls, INPUT):
            controls.add_class('span4')
            if controls['_type'] == 'submit':
                # flag submit button
                _submit = True
                controls['_class'] = 'btn btn-primary'
            if controls['_type'] == 'file':
                controls['_class'] = 'input-file'

        # For password fields, which are wrapped in a CAT object.
        if isinstance(controls, CAT) and isinstance(controls[0], INPUT):
            controls[0].add_class('span4')

        if isinstance(controls, SELECT):
            controls.add_class('span4')

        if isinstance(controls, TEXTAREA):
            controls.add_class('span4')

        if isinstance(label, LABEL):
            label['_class'] = add_class(label.get('_class'), 'control-label')

        if _submit:
            # submit button has unwrapped label and controls, different class
            parent.append(DIV(label, controls, _class='form-actions', _id=id))
            # unflag submit (possible side effect)
            _submit = False
        else:
            # unwrapped label
            parent.append(DIV(label, _controls, _class='control-group', _id=id))
    return parent 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:45,代码来源:sqlhtml.py

示例7: formstyle_bootstrap3_stacked

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap3_stacked(form, fields):
    """ bootstrap 3 format form layout

    Note:
        Experimental!
    """
    parent = CAT()
    for id, label, controls, help in fields:
        # wrappers
        _help = SPAN(help, _class='help-block')
        # embed _help into _controls
        _controls = CAT(controls, _help)
        if isinstance(controls, INPUT):
            if controls['_type'] == 'submit':
                controls.add_class('btn btn-primary')
            if controls['_type'] == 'button':
                controls.add_class('btn btn-default')
            elif controls['_type'] == 'file':
                controls.add_class('input-file')
            elif controls['_type'] in ('text', 'password'):
                controls.add_class('form-control')
            elif controls['_type'] == 'checkbox':
                label['_for'] = None
                label.insert(0, controls)
                label.insert(0, ' ')
                _controls = DIV(label, _help, _class="checkbox")
                label = ''
            elif isinstance(controls, (SELECT, TEXTAREA)):
                controls.add_class('form-control')

        elif isinstance(controls, SPAN):
            _controls = P(controls.components)

        elif isinstance(controls, UL):
            for e in controls.elements("input"):
                e.add_class('form-control')

        elif isinstance(controls, CAT) and isinstance(controls[0], INPUT):
            controls[0].add_class('form-control')

        if isinstance(label, LABEL):
            label['_class'] = add_class(label.get('_class'), 'control-label')

        parent.append(DIV(label, _controls, _class='form-group', _id=id))
    return parent 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:47,代码来源:sqlhtml.py

示例8: formstyle_bootstrap3_inline_factory

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap3_inline_factory(col_label_size=3):
    """ bootstrap 3 horizontal form layout

    Note:
        Experimental!
    """
    def _inner(form, fields):
        form.add_class('form-horizontal')
        label_col_class = "col-sm-%d" % col_label_size
        col_class = "col-sm-%d" % (12 - col_label_size)
        offset_class = "col-sm-offset-%d" % col_label_size
        parent = CAT()
        for id, label, controls, help in fields:
            # wrappers
            _help = SPAN(help, _class='help-block')
            # embed _help into _controls
            _controls = DIV(controls, _help, _class="%s" % (col_class))
            if isinstance(controls, INPUT):
                if controls['_type'] == 'submit':
                    controls.add_class('btn btn-primary')
                    _controls = DIV(controls, _class="%s %s" % (col_class, offset_class))
                if controls['_type'] == 'button':
                    controls.add_class('btn btn-default')
                elif controls['_type'] == 'file':
                    controls.add_class('input-file')
                elif controls['_type'] in ('text', 'password'):
                    controls.add_class('form-control')
                elif controls['_type'] == 'checkbox':
                    label['_for'] = None
                    label.insert(0, controls)
                    label.insert(1, ' ')
                    _controls = DIV(DIV(label, _help, _class="checkbox"),
                                    _class="%s %s" % (offset_class, col_class))
                    label = ''
                elif isinstance(controls, (SELECT, TEXTAREA)):
                    controls.add_class('form-control')

            elif isinstance(controls, SPAN):
                _controls = P(controls.components,
                              _class="form-control-static %s" % col_class)
            elif isinstance(controls, UL):
                for e in controls.elements("input"):
                    e.add_class('form-control')
            elif isinstance(controls, CAT) and isinstance(controls[0], INPUT):
                    controls[0].add_class('form-control')
            if isinstance(label, LABEL):
                label['_class'] = add_class(label.get('_class'), 'control-label %s' % label_col_class)

            parent.append(DIV(label, _controls, _class='form-group', _id=id))
        return parent
    return _inner 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:53,代码来源:sqlhtml.py

示例9: tz_nice_detector_widget

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def tz_nice_detector_widget(field, value, **attributes):
    options = []
    value_missing = True
    for tzn in TZSETS:
        #retrieve offset
        localized = datetime.datetime.now(pytz.timezone(tzn[0]))
        if value == tzn[0]:
            # This is the preselected value.
            value_missing = False
            options.append(
                OPTION(tzn[1], _value=tzn[0], _selected="selected",
                       data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))))
        else:
            options.append(
                OPTION(tzn[1], _value=tzn[0],
                       data=dict(localized=localized.strftime('%Y-%m-%d %H:%M'))))


    _id = '%s_%s' % (field._tablename, field.name)
    _name = field.name
    
    if value_missing and 'autodetect' in attributes and attributes.pop('autodetect') is True:
        current.response.files.append(URL('static', 'plugin_timezone/jstz.min.js'))
        script = """
jQuery(document).ready(function () {
  var tz = jstz.determine();
  var nice_tz_select = jQuery('#%(_id)s');
  nice_tz_select.on('change.plugin_timezone', function(e, data) {
      var localized = jQuery('#%(_id)s option:selected').data('localized');
      var placeholder = '#plugin_timezone_localized';
      if (!jQuery(placeholder).length) nice_tz_select.after('<span id="plugin_timezone_localized" style="display: block" />');
      if (typeof (data) !== 'undefined') {
        localized = 'auto: ' + localized;
      }
      else {
        manual = 'auto: ' + localized;
      }
      // jQuery(placeholder).html(localized);
  });
  if (typeof (tz) !== 'undefined') {
      var name = tz.name();
      nice_tz_select.val(name).trigger('change.plugin_timezone', [name]);
  }
});
    """ % dict(_id=_id)
        return CAT(SELECT(*options, _id=_id, _name=_name, **attributes), SCRIPT(script))
    return SELECT(*options, _id=_id, _name=_name, **attributes) 
开发者ID:lucadealfaro,项目名称:true_review,代码行数:49,代码来源:__init__.py

示例10: formstyle_bootstrap

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap(form, fields):
    """ bootstrap 2.3.x format form layout """
    form.add_class('form-horizontal')
    parent = FIELDSET()
    for id, label, controls, help in fields:
        # wrappers
        _help = SPAN(help, _class='help-block')
        # embed _help into _controls
        _controls = DIV(controls, _help, _class='controls')
        # submit unflag by default
        _submit = False

        if isinstance(controls, INPUT):
            controls.add_class('span4')
            if controls['_type'] == 'submit':
                # flag submit button
                _submit = True
                controls['_class'] = 'btn btn-primary'
            if controls['_type'] == 'file':
                controls['_class'] = 'input-file'

        # For password fields, which are wrapped in a CAT object.
        if isinstance(controls, CAT) and isinstance(controls[0], INPUT):
            controls[0].add_class('span4')

        if isinstance(controls, SELECT):
            controls.add_class('span4')

        if isinstance(controls, TEXTAREA):
            controls.add_class('span4')

        if isinstance(label, LABEL):
            label['_class'] = add_class(label.get('_class'),'control-label')

        if _submit:
            # submit button has unwrapped label and controls, different class
            parent.append(DIV(label, controls, _class='form-actions', _id=id))
            # unflag submit (possible side effect)
            _submit = False
        else:
            # unwrapped label
            parent.append(DIV(label, _controls, _class='control-group', _id=id))
    return parent 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:45,代码来源:sqlhtml.py

示例11: callback

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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, '') 
开发者ID:TechMaz,项目名称:Problematica-public,代码行数:51,代码来源:sqlhtml.py

示例12: formstyle_bootstrap3_stacked

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [as 别名]
def formstyle_bootstrap3_stacked(form, fields):
    """ bootstrap 3 format form layout

    Note:
        Experimental!
    """
    parent = CAT()
    for id, label, controls, help in fields:
        # wrappers
        _help = SPAN(help, _class='help-block')
        # embed _help into _controls
        _controls = CAT(controls, _help)
        if isinstance(controls, INPUT):
            if controls['_type'] == 'submit':
                controls.add_class('btn btn-primary')
            if controls['_type'] == 'button':
                controls.add_class('btn btn-default')
            elif controls['_type'] == 'file':
                controls.add_class('input-file')
            elif controls['_type'] in ('text', 'password'):
                controls.add_class('form-control')
            elif controls['_type'] == 'checkbox':
                label['_for'] = None
                label.insert(0, controls)
                label.insert(0, ' ')
                _controls = DIV(label, _help, _class="checkbox")
                label = ''
            elif isinstance(controls, (SELECT, TEXTAREA)):
                controls.add_class('form-control')

        elif isinstance(controls, SPAN):
            _controls = P(controls.components)

        elif isinstance(controls, UL):
            for e in controls.elements("input"):
                e.add_class('form-control')

        if isinstance(label, LABEL):
            label['_class'] = add_class(label.get('_class'),'control-label')

        parent.append(DIV(label, _controls, _class='form-group', _id=id))
    return parent 
开发者ID:TechMaz,项目名称:Problematica-public,代码行数:44,代码来源:sqlhtml.py

示例13: callback

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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, '') 
开发者ID:slugiot,项目名称:slugiot-client,代码行数:51,代码来源:sqlhtml.py

示例14: callback

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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, '') 
开发者ID:dz0,项目名称:web2py_grand_helpers,代码行数:47,代码来源:plugin_GrandTranslator.py

示例15: callback_NEWw2p

# 需要导入模块: from gluon import html [as 别名]
# 或者: from gluon.html import SELECT [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, '') 
开发者ID:dz0,项目名称:web2py_grand_helpers,代码行数:62,代码来源:plugin_GrandTranslator.py


注:本文中的gluon.html.SELECT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。