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


Python widgets.Select方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def __init__(self, attrs=None, choices=(), default_unit=None):
        """
        Split the field in 2 widgets:
        - the first widget is a positive integer input,
        - the second widget is a select box to choose a pre-defined time unit (minutes, hours,
          days, weeks or months),

        e.g: 3 hours is split in: 3 (integer input) | hour (select)
        """
        self.default_unit = default_unit
        super().__init__(
            (
                widgets.NumberInput({**(attrs or {}), "min": 0}),
                widgets.Select(attrs, choices),
            )
        ) 
开发者ID:openfun,项目名称:richie,代码行数:18,代码来源:duration.py

示例2: test_raw_id_fields_widget_override

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def test_raw_id_fields_widget_override(self):
        """
        The autocomplete_fields, raw_id_fields, and radio_fields widgets may
        overridden by specifying a widget in get_formset().
        """
        class ConcertInline(TabularInline):
            model = Concert
            fk_name = 'main_band'
            raw_id_fields = ('opening_band',)

            def get_formset(self, request, obj=None, **kwargs):
                kwargs['widgets'] = {'opening_band': Select}
                return super().get_formset(request, obj, **kwargs)

        class BandAdmin(ModelAdmin):
            inlines = [ConcertInline]

        ma = BandAdmin(Band, self.site)
        band_widget = list(ma.get_formsets_with_inlines(request))[0][0]().forms[0].fields['opening_band'].widget
        # Without the override this would be ForeignKeyRawIdWidget.
        self.assertIsInstance(band_widget, Select) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:tests.py

示例3: __init__

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def __init__(self, *args, **kwargs):
        super(BootsrapForm, self).__init__(*args, **kwargs)
        for field in self.fields.values():
            # Only tweak the field if it will be displayed
            if not isinstance(field.widget, widgets.HiddenInput):
                attrs = {}
                if (
                    isinstance(field.widget, (widgets.Input, widgets.Select, widgets.Textarea)) and
                    not isinstance(field.widget, (widgets.CheckboxInput,))
                ):
                    attrs['class'] = "form-control"
                if isinstance(field.widget, (widgets.Input, widgets.Textarea)) and field.label:
                    attrs["placeholder"] = field.label
                if field.required:
                    attrs["required"] = "required"
                field.widget.attrs.update(attrs) 
开发者ID:nitmir,项目名称:django-cas-server,代码行数:18,代码来源:forms.py

示例4: create_select

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def create_select(self, name, field, value, val, choices, none_value):
        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name
        if not self.is_required:
            choices.insert(0, none_value)
        local_attrs = self.build_attrs(id=field % id_)
        s = Select(choices=choices)
        select_html = s.render(field % name, val, local_attrs)
        return select_html 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:widgets.py

示例5: __init__

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def __init__(
        self,
        attrs=None,
        choices=(),
        default_effort_unit=None,
        default_reference_unit=None,
    ):
        """
        Split the field in 3 widgets:
        - the first widget is a positive integer input,
        - the second widget is a select box to choose a pre-defined time unit (minutes, hours,
          days, weeks or months),
        - the third widget is a select box to choose the pre-defined time unit of reference.

        e.g: 3 hours/day is split in: 3 (integer input) | hour (select) | day (select)
        """
        self.default_effort_unit = default_effort_unit
        self.default_reference_unit = default_reference_unit
        super().__init__(
            (
                widgets.NumberInput({**(attrs or {}), "min": 0}),
                # Remove the last choice: it can never be chosen as it must be strictly smaller
                # than the reference time unit
                widgets.Select(attrs, choices[:-1]),
                # Remove the first choice: it can never be chosen as it must be strictly greater
                # than the effort time unit
                widgets.Select(attrs, choices[1:]),
            )
        ) 
开发者ID:openfun,项目名称:richie,代码行数:31,代码来源:effort.py

示例6: create_select

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def create_select(self, name, field, value, val, choices):
        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name
        if not (self.required and val):
            choices.insert(0, self.none_value)
        local_attrs = self.build_attrs(id=field % id_)
        s = Select(choices=choices)
        select_html = s.render(field % name, val, local_attrs)
        return select_html 
开发者ID:blackye,项目名称:luscan-devel,代码行数:13,代码来源:widgets.py

示例7: dropdown

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def dropdown(cls, choice):
        attrs = {
            "class": "extra-widget extra-widget-dropdown",
            "style": "display: none;",
        }
        return ChoiceField(
            required=False,
            choices=options_as_choices(choice),
            widget=Select(attrs=attrs),
        ) 
开发者ID:project-callisto,项目名称:callisto-core,代码行数:12,代码来源:widgets.py

示例8: __init__

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def __init__(self, attrs=None):
        _widgets = (
            TinyMCE(attrs=attrs, mce_attrs=MCE_ATTRIBUTES_SHORT),
            widgets.Select(attrs=attrs, choices=RATE_CHOICES),
        )
        super().__init__(_widgets, attrs) 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:8,代码来源:fields.py

示例9: test_default_foreign_key_widget

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def test_default_foreign_key_widget(self):
        # First, without any radio_fields specified, the widgets for ForeignKey
        # and fields with choices specified ought to be a basic Select widget.
        # ForeignKey widgets in the admin are wrapped with RelatedFieldWidgetWrapper so
        # they need to be handled properly when type checking. For Select fields, all of
        # the choices lists have a first entry of dashes.
        cma = ModelAdmin(Concert, self.site)
        cmafa = cma.get_form(request)

        self.assertEqual(type(cmafa.base_fields['main_band'].widget.widget), Select)
        self.assertEqual(
            list(cmafa.base_fields['main_band'].widget.choices),
            [('', '---------'), (self.band.id, 'The Doors')])

        self.assertEqual(type(cmafa.base_fields['opening_band'].widget.widget), Select)
        self.assertEqual(
            list(cmafa.base_fields['opening_band'].widget.choices),
            [('', '---------'), (self.band.id, 'The Doors')]
        )
        self.assertEqual(type(cmafa.base_fields['day'].widget), Select)
        self.assertEqual(
            list(cmafa.base_fields['day'].widget.choices),
            [('', '---------'), (1, 'Fri'), (2, 'Sat')]
        )
        self.assertEqual(type(cmafa.base_fields['transport'].widget), Select)
        self.assertEqual(
            list(cmafa.base_fields['transport'].widget.choices),
            [('', '---------'), (1, 'Plane'), (2, 'Train'), (3, 'Bus')]) 
开发者ID:nesdis,项目名称:djongo,代码行数:30,代码来源:tests.py

示例10: __init__

# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Select [as 别名]
def __init__(self, attrs=None):
        # create choices for days, months, years
        _attrs = attrs or {}  # default class
        _attrs['class'] = (_attrs.get('class', '') + ' w-month-year').strip()
        _widgets = [widgets.Select(attrs=_attrs, choices=MONTHS.items())]
        _attrs['class'] += " w-year"
        _widgets.append(widgets.NumberInput(attrs=_attrs))
        super(MonthSelectorWidget, self).__init__(_widgets, attrs) 
开发者ID:clearspark,项目名称:django-monthfield,代码行数:10,代码来源:widgets.py


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