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


Python forms.ChoiceField方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def __init__(self, *args, **kwargs):
        super(NoteForm, self).__init__(*args, **kwargs)
        note = kwargs['instance']
        self.fields['sender'] = forms.ChoiceField(
            label=_('From'),
            choices=note.get_sender_choices(),
            widget=forms.Select(attrs={'class': 'span12'})
        )

        self.fields['body'].widget = AutocompleteTextarea(
            rows=20,
            choices=Template.templates()
        )

        if note.order:
            url = reverse('notes-render_template', args=[note.order.pk])
            self.fields['body'].widget.attrs['data-url'] = url 
开发者ID:fpsw,项目名称:Servo,代码行数:19,代码来源:notes.py

示例2: make_entry_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def make_entry_field(self, fieldsubmission=None):
        the_choices = self.get_choices()

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

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

        if not self.config['required']:
            c.choices.insert(0, ('', '\u2014'))

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

示例3: get_config

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def get_config(self, name, default=None):
        raw_value = self.event.config.get(name)
        field = self.CONFIG_FIELDS[name]

        try:
            if raw_value is None:
                if field.initial is not None and field.initial != '':
                    return field.to_python(field.initial)
                else:
                    return default
            else:
                return field.to_python(raw_value)
        except forms.ValidationError:
            # XXX: A hack to get around ChoiceField stuff. The idea is that if the value is in
            #      the config field, then it was most likely valid when the event was created.
            return raw_value 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:base.py

示例4: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def __init__(self, *args, **kwargs):
        current_league = kwargs.pop('current_league')
        leagues = kwargs.pop('leagues')
        boards = kwargs.pop('boards')
        teams = kwargs.pop('teams')
        super(TvFilterForm, self).__init__(*args, **kwargs)

        self.fields['league'] = forms.ChoiceField(
            choices=[('all', 'All Leagues')] + [(l.tag, l.name) for l in leagues],
            initial=current_league.tag)
        if boards is not None and len(boards) > 0:
            self.fields['board'] = forms.ChoiceField(
                choices=[('all', 'All Boards')] + [(n, 'Board %d' % n) for n in boards])
        if teams is not None and len(teams) > 0:
            self.fields['team'] = forms.ChoiceField(
                choices=[('all', 'All Teams')] + [(team.number, team.name) for team in teams]) 
开发者ID:cyanfish,项目名称:heltour,代码行数:18,代码来源:forms.py

示例5: __init__

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

        if settings.NETBOX_API:
            self.fields["netbox_device_id"] = forms.ChoiceField(
                label="NetBox Device",
                choices=[(0, "--------")]
                + [
                    (device.id, device.display_name)
                    for device in NetBox().get_devices()
                ],
                widget=StaticSelect,
            )
            self.fields["netbox_device_id"].widget.attrs["class"] = " ".join(
                [
                    self.fields["netbox_device_id"].widget.attrs.get("class", ""),
                    "form-control",
                ]
            ).strip()
        else:
            self.fields["netbox_device_id"].widget = forms.HiddenInput() 
开发者ID:respawner,项目名称:peering-manager,代码行数:23,代码来源:forms.py

示例6: __init__

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

        self.groups = {}
        self.teachers = get_teacher_choises(course)
        groups_teacher = {}
        for default_teacher in DefaultTeacher.objects.filter(group__in=course.groups.all()):
            groups_teacher[default_teacher.group.id] = default_teacher.teacher.id

        for group in course.groups.all():
            group_key = "group_{0}".format(group.id)
            self.groups[group_key] = group
            self.fields[group_key] = forms.ChoiceField(
                initial=groups_teacher.get(group.id, 0),
                choices=self.teachers,
                label=group.name
            ) 
开发者ID:znick,项目名称:anytask,代码行数:19,代码来源:forms.py

示例7: get_view_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def get_view_form(metadata_class):
    model_class = metadata_class._meta.get_model('view')

    # Restrict content type choices to the models set in seo_models
    view_choices = [(key, " ".join(key.split("_"))) for key in get_seo_views(metadata_class)]
    view_choices.insert(0, ("", "---------"))

    # Get a list of fields, with _view at the start
    important_fields = ['_view'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                                  exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _view = forms.ChoiceField(label=capfirst(_("view")),
                                  choices=view_choices, required=False)

        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:whyflyru,项目名称:django-seo,代码行数:23,代码来源:admin.py

示例8: get_field_kind

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def get_field_kind(field):
  if field['kind'] == 'string':
    return forms.CharField(max_length=255, required=False)
  elif field['kind'] == 'email':
    return forms.EmailField(max_length=255, required=False)
  elif field['kind'] == 'integer':
    return forms.IntegerField(required=False)
  elif field['kind'] == 'boolean':
    return forms.BooleanField(required=False)
  elif field['kind'] == 'text':
    return forms.CharField(widget=forms.Textarea(), required=False)
  elif field['kind'] == 'choice':
    return forms.ChoiceField(choices=map(lambda c: (c,c), field['choices']))
  elif field['kind'] == 'timezones':
    return TimezoneField()
  elif field['kind'] == 'authentication':
    return SwitchField('user', 'service', required=True)
  elif field['kind'] == 'json':
    return JsonField(required=False)
  elif field['kind'] == 'integer_list':
    return CommaSeparatedIntegerField(required=False)
  elif field['kind'] == 'string_list':
    return CommaSeparatedCharField(required=False)
  else:
    return forms.CharField(max_length=255, required=False) 
开发者ID:google,项目名称:starthinker,代码行数:27,代码来源:forms_json.py

示例9: build_default_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def build_default_field(self, field, model):
        choices = getattr(field, "choices", None)
        if choices:
            return forms.ChoiceField(
                required=False,
                label=_("Default value"),
                choices=[(None, "-----------")] + list(choices),
            )
        if not (model is Member and field.name == "number"):
            if isinstance(field, models.CharField):
                return forms.CharField(required=False, label=_("Default value"))
            elif isinstance(field, models.DecimalField):
                return forms.DecimalField(
                    required=False,
                    label=_("Default value"),
                    max_digits=field.max_digits,
                    decimal_places=field.decimal_places,
                )
            elif isinstance(field, models.DateField):
                return forms.CharField(required=False, label=_("Other/fixed date")) 
开发者ID:byro,项目名称:byro,代码行数:22,代码来源:registration.py

示例10: is_update

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def is_update(self):
        '''Mark all fields not listed in UPDATE_FIELDS as readonly'''
        for field in self.fields:
            if not field in self.UPDATE_FIELDS:
                # DP NOTE: readonly doesn't work for ChoiceFields, as
                #          the user doesn't enter text, but selects a
                #          value. Using a CharField doesn't allow them
                #          to change the drop down, but still see the
                #          selected value
                if isinstance(self.fields[field], forms.ChoiceField):
                    self.fields[field] = forms.CharField()

                # DP NOTE: Using disabled means the values are not sent
                #          back to the server, which means if there is a
                #          validation error, the disabled fields will
                #          be empty and also cause validation errors
                #self.fields[field].disabled = True
                #self.fields[field].widget.attrs['disabled'] = True
                self.fields[field].widget.attrs['readonly'] = True
        return self 
开发者ID:jhuapl-boss,项目名称:boss,代码行数:22,代码来源:forms.py

示例11: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def __init__(self, *args, **kwargs):
        from .election_specific import shorten_post_label
        election = kwargs.pop('election')
        super(AddCandidacyPickPostForm, self).__init__(*args, **kwargs)
        self.fields['post'] = forms.ChoiceField(
            label=_('Post in %s') % election.name,
            choices=[('', '')] + sorted(
                [
                    (post.extra.slug,
                     shorten_post_label(post.label))
                    for post in Post.objects.select_related('extra').filter(extra__elections=election)
                ],
                key=lambda t: t[1]
            ),
            widget=forms.Select(attrs={'class': 'post-select'}),
        ) 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:18,代码来源:forms.py

示例12: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def __init__(self, *args, **kwargs):
        super(ChoiceField, self).__init__(*args, **kwargs)
        self.widget.attrs['class'] = 'span12' 
开发者ID:fpsw,项目名称:Servo,代码行数:5,代码来源:base.py

示例13: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def __init__(self, *args, **kwargs):
        from servo.lib.utils import empty
        super(GsxRepairForm, self).__init__(*args, **kwargs)
        repair = self.instance
        techs = User.techies.filter(location=repair.order.location)
        c = [(u.tech_id, u.get_full_name()) for u in techs]
        c.insert(0, ('', '-------------------',))
        self.fields['tech_id'] = forms.ChoiceField(choices=c,
                                                   required=False,
                                                   label=_('Technician'))
        self.fields['parts'].initial = repair.order.get_parts()

        if repair.can_mark_complete is False:
            del(self.fields['mark_complete'])
            del(self.fields['replacement_sn'])

        choices = Template.templates()
        for f in ('notes', 'symptom', 'diagnosis',):
            self.fields[f].widget = AutocompleteTextarea(choices=choices)

        symptom_codes = self.instance.get_symptom_code_choices()
        self.fields['symptom_code'] = forms.ChoiceField(choices=symptom_codes,
                                                        label=_('Symptom group'))

        if empty(self.instance.symptom_code):
            # default to the first choice
            self.instance.symptom_code = symptom_codes[0][0]

        issue_codes = self.instance.get_issue_code_choices()
        self.fields['issue_code'] = forms.ChoiceField(choices=issue_codes,
                                                      label=_('Issue code')) 
开发者ID:fpsw,项目名称:Servo,代码行数:33,代码来源:repairs.py

示例14: __init__

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

        if self.instance:
            product = self.instance.product
            if product.can_order_from_gsx():
                CODES = symptom_codes(product.component_code)
                self.fields['comptia_code'] = forms.ChoiceField(choices=CODES,
                                                                label=_('Symptom code'))
                self.fields['comptia_modifier'] = forms.ChoiceField(
                    choices=gsxws.MODIFIERS,
                    initial="B",
                    label=_('Symptom modifier')
                ) 
开发者ID:fpsw,项目名称:Servo,代码行数:16,代码来源:orders.py

示例15: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ChoiceField [as 别名]
def __init__(self, event=None, *args, **kwargs):
        super(DonationEntryForm, self).__init__(*args, **kwargs)
        minDonationAmount = (
            event.minimumdonation if event is not None else Decimal('1.00')
        )
        self.fields['amount'] = forms.DecimalField(
            decimal_places=2,
            min_value=minDonationAmount,
            max_value=Decimal('100000'),
            label='Donation Amount (min ${0})'.format(minDonationAmount),
            widget=tracker.widgets.NumberInput(
                attrs={
                    'id': 'iDonationAmount',
                    'min': str(minDonationAmount),
                    'step': '0.01',
                }
            ),
            required=True,
        )
        self.fields['comment'] = forms.CharField(widget=forms.Textarea, required=False)
        self.fields['requestedvisibility'] = forms.ChoiceField(
            initial='CURR',
            choices=models.Donation._meta.get_field('requestedvisibility').choices,
            label='Name Visibility',
        )
        self.fields['requestedalias'] = forms.CharField(
            max_length=32, label='Preferred Alias', required=False
        )
        self.fields['requestedemail'] = forms.EmailField(
            max_length=128, label='Preferred Email', required=False
        )
        self.fields['requestedsolicitemail'] = forms.ChoiceField(
            initial='CURR',
            choices=models.Donation._meta.get_field('requestedsolicitemail').choices,
            label='Charity Email Opt In',
        ) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:38,代码来源:forms.py


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