當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。