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


Python forms.RadioSelect方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [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

示例2: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
        Segment.panels = [
            MultiFieldPanel([
                FieldPanel('name', classname="title"),
                FieldRowPanel([
                    FieldPanel('status'),
                    FieldPanel('persistent'),
                ]),
                FieldPanel('match_any'),
                FieldPanel('type', widget=forms.RadioSelect),
                FieldPanel('count', classname='count_field'),
                FieldPanel('randomisation_percent', classname='percent_field'),
            ], heading="Segment"),
            MultiFieldPanel([
                RulePanel(
                    "{}_related".format(rule_model._meta.db_table),
                    label='{}{}'.format(
                        rule_model._meta.verbose_name,
                        ' ({})'.format(_('Static compatible')) if rule_model.static else ''
                    ),
                ) for rule_model in AbstractBaseRule.__subclasses__()
            ], heading=_("Rules")),
        ]

        super(Segment, self).__init__(*args, **kwargs) 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:27,代码来源:models.py

示例3: set_fields

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def set_fields(cls, category, products):
        choices = []
        for product in products:
            choice_text = "%s -- $%d" % (product.name, product.price)
            choices.append((product.id, choice_text))

        if not category.required:
            choices.append((0, "No selection"))

        cls.base_fields[cls.FIELD] = forms.TypedChoiceField(
            label=category.name,
            widget=forms.RadioSelect,
            choices=choices,
            empty_value=0,
            coerce=int,
        ) 
开发者ID:chrisjrn,项目名称:registrasion,代码行数:18,代码来源:forms.py

示例4: test_constructor_attrs

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def test_constructor_attrs(self):
        """
        Attributes provided at instantiation are passed to the constituent
        inputs.
        """
        widget = RadioSelect(attrs={'id': 'foo'}, choices=self.beatles)
        html = """
        <ul id="foo">
        <li>
        <label for="foo_0"><input checked type="radio" id="foo_0" value="J" name="beatle"> John</label>
        </li>
        <li><label for="foo_1"><input type="radio" id="foo_1" value="P" name="beatle"> Paul</label></li>
        <li><label for="foo_2"><input type="radio" id="foo_2" value="G" name="beatle"> George</label></li>
        <li><label for="foo_3"><input type="radio" id="foo_3" value="R" name="beatle"> Ringo</label></li>
        </ul>
        """
        self.check_html(widget, 'beatle', 'J', html=html) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:test_radioselect.py

示例5: populate_questions_inputs

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def populate_questions_inputs(self, survey, question_group_id, **kwargs):
        questions_qs = survey.get_questions().filter(
            question_group__id=question_group_id
        ).order_by('order',)

        for question in questions_qs:
            if not question.is_active:
                # skip inactive questions
                continue

            qid = question.qid
            self.fields[qid] = forms.CharField(label=question.text)

            if question.question_type == Question.RADIO:
                self.fields[qid].widget = forms.RadioSelect(choices=self.CHOICES_1_10)

            elif question.question_type == Question.BOOLEAN:
                self.fields[qid] = forms.BooleanField(label=question.text)

            elif question.question_type == Question.TEXT:
                pass  # non modifica niente 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:23,代码来源:forms.py

示例6: __init__

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

        # Per indicare con request.POST con che form/step stiamo lavorando
        self.fields['step'].initial = self.step

        # Risposte precedentemente salvate
        response_lezioni = self.survey_result.response_json['utilita_lezioni']

        # for lezione in self.course.get_lezioni_precaricate():
        for lezione in self.course.lezioni.all():
            lezione_pk = 'lezioni_pk_%s' % lezione.pk

            # Crea i campi con 10 radio-button (0-10)
            self.fields[lezione_pk] = forms.CharField(label=lezione.nome)
            self.fields[lezione_pk].widget = forms.RadioSelect(choices=self.CHOICES_1_10)

            # Valorizzare gli input se ci sono le risposte
            lezione_pk_str = str(lezione.pk)
            if lezione_pk_str in response_lezioni:
                self.fields[lezione_pk].initial = response_lezioni[lezione_pk_str] 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:23,代码来源:forms.py

示例7: is_radio

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

示例8: get_entry_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def get_entry_field(self, questionanswer=None, student=None):
        options = self.version.config.get('options', [])
        permute = self.version.config.get('permute', 'keep')
        show_no_answer = self.version.config.get('show_no_answer', 'noshow')
        if questionanswer:
            initial = questionanswer.answer.get('data', MultipleChoice.NA)
        else:
            initial = MultipleChoice.NA

        options = list(enumerate(options))  # keep original positions so the input values match that, but students see a possibly-randomized order

        if student and permute == 'permute':
            rand = self.question.quiz.random_generator(str(student.id) + '-' + str(self.question.id) + '-' + str(self.version.id))
            options = rand.permute(options)
        elif student and permute == 'not-last':
            rand = self.question.quiz.random_generator(str(student.id) + '-' + str(self.question.id) + '-' + str(self.version.id))
            last = options[-1]
            options = rand.permute(options[:-1])
            options.append(last)

        choices = [
            (OPTION_LETTERS[opos], mark_safe('<span class="mc-letter">' + OPTION_LETTERS[i] + '.</span> ') + escape(o[0]))
            for i, (opos, o)
            in enumerate(options)
        ]

        if show_no_answer == 'show':
            choices.append((MultipleChoice.NA, 'no answer'))

        field = forms.ChoiceField(required=False, initial=initial, choices=choices, widget=forms.RadioSelect())
        field.widget.attrs.update({'class': 'multiple-choice'})
        return field 
开发者ID:sfu-fas,项目名称:coursys,代码行数:34,代码来源:mc.py

示例9: make_entry_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def make_entry_field(self, fieldsubmission=None):
        the_choices = [(k, v) for k, v in self.config.items() if k.startswith("choice_") and self.config[k]]
        the_choices = sorted(the_choices, key=lambda choice: (int) (re.findall(r'\d+', choice[0])[0]))

        c = forms.ChoiceField(required=self.config['required'],
            label=self.config['label'],
            help_text=self.config['help_text'],
            choices=the_choices,
            widget=forms.RadioSelect())

        if fieldsubmission:
            initial=fieldsubmission.data['info']
            c.initial=initial

        return c 
开发者ID:sfu-fas,项目名称:coursys,代码行数:17,代码来源:select.py

示例10: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(
            label="EMR release",
            queryset=models.EMRRelease.objects.active().natural_sort_by_version(),
            required=True,
            empty_label=None,
            widget=forms.RadioSelect(
                attrs={"required": "required", "class": "radioset"}
            ),
            help_text=models.Cluster.EMR_RELEASE_HELP,
        ) 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:13,代码来源:forms.py

示例11: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
        super(ProposalVoteForm, self).__init__(*args, **kwargs)
        # Use a radio select widget instead of a dropdown for the score.
        self.fields["score"] = forms.TypedChoiceField(
            choices=ProposalVote.SCORES,
            coerce=int,
            empty_value=0,
            widget=forms.RadioSelect(),
        ) 
开发者ID:pydata,项目名称:conf_site,代码行数:11,代码来源:forms.py

示例12: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, has_recurrences, *args, **kwargs):
        super(DeleteScheduleForm, self).__init__(*args, **kwargs)
        if has_recurrences:
            choices = (
                (self.DELETE_ONLY_THIS, 'Only this instance'),
                (self.DELETE_THIS_AND_FOLLOWING, 'This and all the following events'),
                (self.DELETE_ALL, 'All events in the series'),
            )
            self.fields['action'] = forms.ChoiceField(choices=choices, label='', help_text='', widget=forms.RadioSelect) 
开发者ID:iago1460,项目名称:django-radio,代码行数:11,代码来源:forms.py

示例13: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, poll, user=None, *args, **kwargs):
        super(PollVoteManyForm, self).__init__(*args, **kwargs)
        self.auto_id = 'id_poll_{pk}_%s'.format(pk=poll.pk)  # Uniqueness "<label for=id_poll_pk_..."
        self.user = user
        self.poll = poll
        self.poll_choices = getattr(poll, 'choices', poll.poll_choices.unremoved())
        choices = ((c.pk, mark_safe(c.description)) for c in self.poll_choices)

        if poll.is_multiple_choice:
            self.fields['choices'] = forms.MultipleChoiceField(
                choices=choices,
                widget=forms.CheckboxSelectMultiple,
                label=_("Poll choices")
            )
        else:
            self.fields['choices'] = forms.ChoiceField(
                choices=choices,
                widget=forms.RadioSelect,
                label=_("Poll choices")
            ) 
开发者ID:nitely,项目名称:Spirit,代码行数:22,代码来源:forms.py

示例14: test_generates_radio_button

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def test_generates_radio_button(self):
        field = mocks.MockQuestion(self.question.serialized).make_field()
        self.assertEqual(len(field.choices), 5)
        self.assertEqual(field.choices[4][1], "This is choice 4")
        self.assertIsInstance(field.widget, forms.RadioSelect) 
开发者ID:project-callisto,项目名称:callisto-core,代码行数:7,代码来源:test_models.py

示例15: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
        """
        Add custom handling for requested_sources and override some widgets.
        """
        super().__init__(*args, **kwargs)

        source_projects = DataRequestProject.objects.filter(approved=True).exclude(
            returned_data_description=""
        )
        self.fields["requested_sources"].choices = [
            (p.id, p.name) for p in source_projects
        ]
        self.fields["requested_sources"].widget = forms.CheckboxSelectMultiple()
        self.fields["requested_sources"].required = False

        override_fields = [
            "is_study",
            "is_academic_or_nonprofit",
            "active",
            "request_username_access",
        ]

        # XXX: feels like a hack; ideally we could just override the widget in
        # the Meta class but it doesn't work (you end up with an empty option)
        for field in override_fields:
            # set the widget to a RadioSelect
            self.fields[field].widget = forms.RadioSelect()

            # filter out the empty choice
            self.fields[field].choices = [
                choice for choice in self.fields[field].choices if choice[0] != ""
            ]

            # coerce the result to a boolean
            self.fields[field].coerce = lambda x: x == "True" 
开发者ID:OpenHumans,项目名称:open-humans,代码行数:37,代码来源:forms.py


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