當前位置: 首頁>>代碼示例>>Python>>正文


Python widgets.CheckboxInput方法代碼示例

本文整理匯總了Python中django.forms.widgets.CheckboxInput方法的典型用法代碼示例。如果您正苦於以下問題:Python widgets.CheckboxInput方法的具體用法?Python widgets.CheckboxInput怎麽用?Python widgets.CheckboxInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms.widgets的用法示例。


在下文中一共展示了widgets.CheckboxInput方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: render

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def render(self, name, value, attrs=None,):

        substitutions = {
            'clear_checkbox_label': self.clear_checkbox_label,
            'initial' : '<img class="img-responsive img-thumbnail" width="%s" src="%s">' % (
                force_text('100%'),
                force_text(get_thumbnailer(value)['medium'].url if value and hasattr(value, 'url') else static('images/placeholder.svg'))
            )
        }
        template = '%(initial)s%(input)s'

        substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)

        if not self.is_required:
            template = '%(initial)s%(clear_template)s%(input)s'
            checkbox_name = self.clear_checkbox_name(name)
            checkbox_id = self.clear_checkbox_id(checkbox_name)
            substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
            substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
            substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
            substitutions['clear_template'] = self.clear_checkbox_name(checkbox_name)

        return mark_safe(template % substitutions) 
開發者ID:freedomvote,項目名稱:freedomvote,代碼行數:25,代碼來源:widgets.py

示例2: __init__

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [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

示例3: test_DictCharWidget_renders_with_empty_string_as_input_data

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def test_DictCharWidget_renders_with_empty_string_as_input_data(self):
        names = [factory.make_string(), factory.make_string()]
        initials = []
        labels = [factory.make_string(), factory.make_string()]
        widget = DictCharWidget(
            [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
            names,
            initials,
            labels,
            skip_check=True,
        )
        name = factory.make_string()
        html_widget = fromstring(
            "<root>" + widget.render(name, "") + "</root>"
        )
        widget_names = XPath("fieldset/input/@name")(html_widget)
        widget_labels = XPath("fieldset/label/text()")(html_widget)
        expected_names = [
            "%s_%s" % (name, widget_name) for widget_name in names
        ]
        self.assertEqual(
            [expected_names, labels], [widget_names, widget_labels]
        ) 
開發者ID:maas,項目名稱:maas,代碼行數:25,代碼來源:test_config_forms.py

示例4: bootstrap_input_type

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def bootstrap_input_type(field):
    """
    Return input type to use for field
    """
    try:
        widget = field.field.widget
    except:
        raise ValueError("Expected a Field, got a %s" % type(field))
    input_type = getattr(widget, 'bootstrap_input_type', None)
    if input_type:
        return str(input_type)
    if isinstance(widget, TextInput):
        return u'text'
    if isinstance(widget, CheckboxInput):
        return u'checkbox'
    if isinstance(widget, CheckboxSelectMultiple):
        return u'multicheckbox'
    if isinstance(widget, RadioSelect):
        return u'radioset'
    return u'default' 
開發者ID:mediafactory,項目名稱:yats,代碼行數:22,代碼來源:bootstrap_toolkit.py

示例5: is_checkbox

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def is_checkbox(field):
  return isinstance(field.field.widget, CheckboxInput) 
開發者ID:google,項目名稱:starthinker,代碼行數:4,代碼來源:website_app.py

示例6: value_from_datadict

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def value_from_datadict(self, data, files, name):
        """
        Modify value_from_datadict, so that delete takes precedence over
        upload.
        """
        file_value = super(widgets.ClearableFileInput, self)\
            .value_from_datadict(data, files, name)
        checkbox_value = widgets.CheckboxInput()\
            .value_from_datadict(data, files, self.clear_checkbox_name(name))
        if not self.is_required and checkbox_value:
            return False
        return file_value 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:14,代碼來源:widgets.py

示例7: test_DictCharWidget_renders_fieldset_with_label_and_field_names

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def test_DictCharWidget_renders_fieldset_with_label_and_field_names(self):
        names = [factory.make_string(), factory.make_string()]
        initials = []
        labels = [factory.make_string(), factory.make_string()]
        values = [factory.make_string(), factory.make_string()]
        widget = DictCharWidget(
            [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
            names,
            initials,
            labels,
            skip_check=True,
        )
        name = factory.make_string()
        html_widget = fromstring(
            "<root>" + widget.render(name, values) + "</root>"
        )
        widget_names = XPath("fieldset/input/@name")(html_widget)
        widget_labels = XPath("fieldset/label/text()")(html_widget)
        widget_values = XPath("fieldset/input/@value")(html_widget)
        expected_names = [
            "%s_%s" % (name, widget_name) for widget_name in names
        ]
        self.assertEqual(
            [expected_names, labels, values],
            [widget_names, widget_labels, widget_values],
        ) 
開發者ID:maas,項目名稱:maas,代碼行數:28,代碼來源:test_config_forms.py

示例8: test_empty_DictCharWidget_renders_as_empty_string

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def test_empty_DictCharWidget_renders_as_empty_string(self):
        widget = DictCharWidget(
            [widgets.CheckboxInput], [], [], [], skip_check=True
        )
        self.assertEqual("", widget.render(factory.make_string(), "")) 
開發者ID:maas,項目名稱:maas,代碼行數:7,代碼來源:test_config_forms.py

示例9: render

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import CheckboxInput [as 別名]
def render(self, name, value, attrs=None, renderer=None):
        html_id = attrs and attrs.get('id', name) or name
        has_image_set = self.is_initial(value)
        is_required = self.is_required

        file_placeholder = ugettext('Select a picture from your local folder.')
        file_input = super().render(name, None, {
            'id': html_id,
            'class': 'form-control form-control-file'
        })

        if has_image_set:
            file_name = basename(value.name)
            file_url = conditional_escape(value.url)
        else:
            file_name = ""
            file_url = ""

        text_input = widgets.TextInput().render('__noname__', file_name, {
            'class': 'form-control form-control-file-dummy',
            'placeholder': file_placeholder,
            'tabindex': '-1',
            'id': 'text-{}'.format(html_id)
        })

        checkbox_id = self.clear_checkbox_id(name)
        checkbox_name = self.clear_checkbox_name(name)
        checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {
            'id': checkbox_id,
            'class': 'clear-image',
            'data-upload-clear': html_id,
        })

        context = {
            'id': html_id,
            'has_image_set': has_image_set,
            'is_required': is_required,
            'file_url': file_url,
            'file_input': file_input,
            'file_id': html_id + '-file',
            'text_input': text_input,
            'checkbox_input': checkbox_input,
            'checkbox_id': checkbox_id
        }

        return loader.render_to_string(
            'a4images/image_upload_widget.html',
            context
        ) 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:51,代碼來源:widgets.py


注:本文中的django.forms.widgets.CheckboxInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。