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