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


Python sqlhtml.OptionsWidget类代码示例

本文整理汇总了Python中gluon.sqlhtml.OptionsWidget的典型用法代码示例。如果您正苦于以下问题:Python OptionsWidget类的具体用法?Python OptionsWidget怎么用?Python OptionsWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: widget

    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
开发者ID:aferhati,项目名称:plug-and-play-1.0-RC,代码行数:29,代码来源:a_widgets.py

示例2: _select_field

    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)
开发者ID:michaelhowden,项目名称:aidiq,代码行数:27,代码来源:s3report.py

示例3: _select_field

    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)
开发者ID:volator,项目名称:eden,代码行数:27,代码来源:s3report.py

示例4: _select_method

    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)
开发者ID:volator,项目名称:eden,代码行数:31,代码来源:s3report.py

示例5: axis_options

    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)
开发者ID:LMcule,项目名称:eden,代码行数:59,代码来源:s3report2.py

示例6: rating_widget

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))
开发者ID:AndreMassashi,项目名称:web2py-recipes-source,代码行数:9,代码来源:plugin_rating.py

示例7: time_options

    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",
                                    )
开发者ID:coder006,项目名称:eden,代码行数:55,代码来源:s3timeplot.py

示例8: create_widget

    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
开发者ID:shenjiawei19,项目名称:plugin_ajaxselect,代码行数:13,代码来源:plugin_ajaxselect.py

示例9: widget

    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)
开发者ID:1nn7erplay,项目名称:Movuca,代码行数:49,代码来源:widgets.py

示例10: widget

 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
开发者ID:rubenmunozm,项目名称:antioquiacc,代码行数:15,代码来源:plugin_jqueryui.py

示例11: _field_select

    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)
开发者ID:sanyam5,项目名称:eden,代码行数:44,代码来源:s3report.py

示例12: widget

 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
开发者ID:Khaledgarbaya,项目名称:reform_tn_site,代码行数:21,代码来源:_select_or_add_widget.py

示例13: get_custom_element_function

 def get_custom_element_function(self,field):
     from gluon.sqlhtml import OptionsWidget
     if OptionsWidget.has_options(field):
         widget=SQLFORM.widgets.options.widget(field,'no_selection').xml()
         script= """
              function (value, options) {
                    var el = document.createElement('div');
                    el.innerHTML='%s'.replace('>'+value+'<',' selected="selected">'+value+'<');
                    el.children[0].style.width="100%%";
                    return el;
              }""" % widget;
         return script;
     elif field.type=='boolean':
         return "get_bool_widget"
     else:        
         if field.type=='time':
             calendar="el.children[0].onfocus=function(){time_setup(this.attributes['id'].value);};"
         elif field.type=='date':
             calendar="el.children[0].onfocus=function(){calendar_setup_date(this.attributes['id'].value);};"
         elif field.type=='datetime':
             calendar="el.children[0].onfocus=function(){calendar_setup_datetime(this.attributes['id'].value);};"
         elif field.type=='double':
             calendar="el.children[0].onfocus=function(){double_setup(this);};"
         elif field.type=='integer':
             calendar="el.children[0].onfocus=function(){integer_setup(this);};"
         else:
             calendar=""
         if field.widget:
             widget=field.widget(field,'a_value').xml().replace('<','\<').replace('>','\>').replace("'","\\'")
         else:
             widget=SQLFORM.widgets[field.type].widget(field,'a_value').xml()
         
         str="""
            function (value, options) {var el = document.createElement('div');  el.innerHTML='%s'.replace('a_value',value);  
            %s
            el.children[0].style.width="100%%";
            return el;
            }""" 
         return str% (widget,calendar);
开发者ID:pkom,项目名称:gesiesweb_web2py,代码行数:39,代码来源:plugin_editable_jqgrid.py

示例14: widget

    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
开发者ID:francielsilvestrini,项目名称:soupport,代码行数:38,代码来源:h5_widgets.py

示例15: type

                        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):
开发者ID:monotasker,项目名称:plugin_ajaxselect,代码行数:31,代码来源:plugin_ajaxselect.py


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