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


Python forms.CheckboxInput方法代码示例

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


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

示例1: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def render(self, name, value, attrs=None, renderer=None):
        name = str(name)
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = super(forms.ClearableFileInput, self).render(name, value, attrs, renderer=renderer)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<a href="%s">%s</a>'
                                        % (escape(value.file_sub.get_file_url()),
                                           escape(value.file_sub.display_filename())))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = escape(checkbox_name)
                substitutions['clear_checkbox_id'] = escape(checkbox_id)
                substitutions['clear'] = forms.CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:other.py

示例2: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        custom_widgets = [forms.CheckboxInput, forms.RadioSelect]

        for field_name, field in self.fields.items():
            if field.widget.__class__ in custom_widgets:
                css = field.widget.attrs.get("class", "")
                field.widget.attrs["class"] = " ".join(
                    [css, "custom-control-input"]
                ).strip()
            else:
                css = field.widget.attrs.get("class", "")
                field.widget.attrs["class"] = " ".join([css, "form-control"]).strip()

            if field.required:
                field.widget.attrs["required"] = "required"
            if "placeholder" not in field.widget.attrs:
                field.widget.attrs["placeholder"] = field.label 
开发者ID:respawner,项目名称:peering-manager,代码行数:21,代码来源:forms.py

示例3: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def __init__(self, *args, **kwargs):
        key_type = kwargs.pop('key_type', None)
        value = kwargs.pop('value', None)
        super(EditKey, self).__init__(*args, **kwargs)

        if key_type == 'rich-text':
            self.fields['value'].widget = SummernoteWidget()
        elif key_type == 'boolean':
            self.fields['value'].widget = forms.CheckboxInput()
        elif key_type == 'integer':
            self.fields['value'].widget = forms.TextInput(attrs={'type': 'number'})
        elif key_type == 'file' or key_type == 'journalthumb':
            self.fields['value'].widget = forms.FileInput()
        elif key_type == 'text':
            self.fields['value'].widget = forms.Textarea()
        else:
            self.fields['value'].widget.attrs['size'] = '100%'

        self.fields['value'].initial = value
        self.fields['value'].required = False 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:22,代码来源:forms.py

示例4: value_from_datadict

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def value_from_datadict(self, data, files, name):
        if hasattr(files, 'getlist'):
            upload = files.getlist(name)
        else:
            upload = files.get(name)
            if not isinstance(upload, list):
                upload = [upload]

        checkbox_name = self.clear_checkbox_name(name) + '-'
        checkboxes = {k for k in data if checkbox_name in k}
        cleared = {
            int(checkbox.replace(checkbox_name, '')) for checkbox in checkboxes
            if CheckboxInput().value_from_datadict(data, files, checkbox)
        }

        return {
            'files': upload,
            'cleared': cleared,
        } 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:21,代码来源:fields.py

示例5: test_render_check_test

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def test_render_check_test(self):
        """
        You can pass 'check_test' to the constructor. This is a callable that
        takes the value and returns True if the box should be checked.
        """
        widget = CheckboxInput(check_test=lambda value: value.startswith('hello'))
        self.check_html(widget, 'greeting', '', html=(
            '<input type="checkbox" name="greeting">'
        ))
        self.check_html(widget, 'greeting', 'hello', html=(
            '<input checked type="checkbox" name="greeting" value="hello">'
        ))
        self.check_html(widget, 'greeting', 'hello there', html=(
            '<input checked type="checkbox" name="greeting" value="hello there">'
        ))
        self.check_html(widget, 'greeting', 'hello & goodbye', html=(
            '<input checked type="checkbox" name="greeting" value="hello &amp; goodbye">'
        )) 
开发者ID:nesdis,项目名称:djongo,代码行数:20,代码来源:test_checkboxinput.py

示例6: is_checkbox

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def is_checkbox(field):
    return isinstance(field.field.widget, forms.CheckboxInput) 
开发者ID:OpenMDM,项目名称:OpenMDM,代码行数:4,代码来源:bootstrap.py

示例7: value_from_datadict

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def value_from_datadict(self, data, files, name):
        # override to accept the case "clear + file upload" without ValidationError
        upload = super().value_from_datadict(data, files, name)
        if not self.is_required and forms.CheckboxInput().value_from_datadict(
                data, files, self.clear_checkbox_name(name)):

            #if upload:
            #    return FILE_INPUT_CONTRADICTION

            # False signals to clear any existing value, as opposed to just None
            return False
        return upload 
开发者ID:sfu-fas,项目名称:coursys,代码行数:14,代码来源:file.py

示例8: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def __init__(self):
        widgets = (
            forms.Textarea(attrs={'cols': 70, 'rows': 20}),
            forms.Select(),
            forms.CheckboxInput(),
        )
        super(MarkupContentWidget, self).__init__(widgets) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:9,代码来源:markup.py

示例9: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        has_id = attrs and 'id' in attrs
        if DJANGO_11:
            final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})
        else:
            final_attrs = self.build_attrs(attrs, name=name)
        output = []
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            cb = forms.CheckboxInput(
                final_attrs, check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_text(option_label))

            if final_attrs.get('inline', False):
                output.append(u'<label%s class="checkbox-inline">%s %s</label>' % (label_for, rendered_cb, option_label))
            else:
                output.append(u'<div class="checkbox"><label%s>%s %s</label></div>' % (label_for, rendered_cb, option_label))
        return mark_safe(u'\n'.join(output)) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:33,代码来源:widgets.py

示例10: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def __init__(self, form, field, is_first):
        self.field = form[field]  # A django.forms.BoundField instance
        self.is_first = is_first  # Whether this field is first on the line
        self.is_checkbox = isinstance(self.field.field.widget, forms.CheckboxInput) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:helpers.py

示例11: is_checkbox

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def is_checkbox(field):
    return field.field.widget.__class__.__name__ == CheckboxInput().__class__.__name__ 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:4,代码来源:custom_tags.py

示例12: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def __init__(self, form, field, is_first):
        self.field = form[field]  # A django.forms.BoundField instance
        self.is_first = is_first  # Whether this field is first on the line
        self.is_checkbox = isinstance(self.field.field.widget, forms.CheckboxInput)
        self.is_readonly = False 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:7,代码来源:helpers.py

示例13: clean

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def clean(self):
        cleaned_data = super(MovePageForm, self).clean()
        slug = cleaned_data['slug']
        just_redirect = cleaned_data.get('just_redirect', False)
        if self.instance.slug == slug:
            raise forms.ValidationError(_("The slug wasn't changed"))

        if Page.objects.filter(slug=slug).exists() and not just_redirect:
            self.fields['just_redirect'].widget = forms.CheckboxInput()
            raise forms.ValidationError(_("There is already a page with this slug"))

        return cleaned_data 
开发者ID:mgaitan,项目名称:waliki,代码行数:14,代码来源:forms.py

示例14: test_post_error_if_target_already_exist

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def test_post_error_if_target_already_exist(self):
        new_page = PageFactory(raw="hello test!", slug='target-page')
        response = self.client.post(self.move_url, {'slug': 'target-page'})
        self.assertEqual(response.status_code, 200)
        form = response.context[0]['form']
        self.assertEqual(form.errors, {'__all__': ["There is already a page with this slug"]})
        self.assertIsInstance(form.fields['just_redirect'].widget, forms.CheckboxInput) 
开发者ID:mgaitan,项目名称:waliki,代码行数:9,代码来源:test_views.py

示例15: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxInput [as 别名]
def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})
        output = []
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            cb = forms.CheckboxInput(
                final_attrs, check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_text(option_label))

            if final_attrs.get('inline', False):
                output.append(u'<label%s class="checkbox-inline">%s %s</label>' % (label_for, rendered_cb, option_label))
            else:
                output.append(u'<div class="checkbox"><label%s>%s %s</label></div>' % (label_for, rendered_cb, option_label))
        return mark_safe(u'\n'.join(output)) 
开发者ID:Superbsco,项目名称:weibo-analysis-system,代码行数:30,代码来源:widgets.py


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