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


Python forms.Select方法代码示例

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


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

示例1: __init__

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

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(KoScheduleForm, self).__init__(*args, **kwargs)
        # if hasattr(self.request, "project") and self.request.project is not None:
        #     xform = XForm.objects.filter(
        #         Q(user=self.request.user) | Q(fieldsightformlibrary__is_global=True) |
        #         Q(fieldsightformlibrary__project=self.request.project) |
        #         Q(fieldsightformlibrary__organization=self.request.organization))

        if hasattr(self.request, "organization") and self.request.organization is not None:
            xform = XForm.objects.filter(
                Q(user=self.request.user) |
                Q(user__user_profile__organization=self.request.organization), deleted_xform=None)
        else:
            xform = XForm.objects.filter(
                Q(user=self.request.user) | Q(fieldsightformlibrary__is_global=True), deleted_xform=None)
        self.fields['form'].choices = [(obj.id, obj.title) for obj in xform]
        self.fields['form'].empty_label = None
        self.fields['form'].label = "Select Form" 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:21,代码来源:forms.py

示例3: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, *args, **kwargs):
        """
        We change the widget of the fields
        We get the original form, register all repositories, create the list of protocols.
        If a repo exists, we check that its protocol will be in the list. Otherwise the protocol of a repo with a currently not registered protocol would be overwritten.
        """
        super().__init__(*args, **kwargs)

        # Protocol
        # Get the list with names of protocols
        protocol_registry.load()
        choices = [(key, str(value)) for key, value in protocol_registry.dct.items()]
        # If the repo uses a protocol not in the list, we add this value, otherwise it is overriden on saving
        if self.instance.protocol:
            if self.instance.protocol not in protocol_registry.dct.keys():
                choices += [(self.instance.protocol,self.instance.protocol)]
        # Sort and populate the form
        choices = sorted(choices, key=lambda protocol: protocol[1].lower(),)
        self.fields['protocol'].widget = forms.Select(choices=choices) 
开发者ID:dissemin,项目名称:dissemin,代码行数:21,代码来源:forms.py

示例4: __init__

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

示例5: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, attrs=None):
        self.time_class = "timepicker"
        if not attrs:
            attrs = {}
        if "time_class" in attrs:
            self.time_class = attrs.pop("time_class")
        if "class" not in attrs:
            attrs["class"] = "time"

        widgets = (
            forms.Select(
                attrs=attrs, choices=[(i + 1, "%02d" % (i + 1)) for i in range(0, 12)]
            ),
            forms.Select(
                attrs=attrs, choices=[(i, "%02d" % i) for i in range(00, 60, 15)]
            ),
            forms.Select(attrs=attrs, choices=[("AM", _("AM")), ("PM", _("PM"))]),
        )

        super(TimeWidget, self).__init__(widgets, attrs) 
开发者ID:GetTogetherComm,项目名称:GetTogether,代码行数:22,代码来源:forms.py

示例6: set_fields

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def set_fields(cls, category, products):
        choices = []

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

        for product in products:
            choice_text = "%s -- $%d each" % (product.name, product.price)
            choices.append((product.id, choice_text))

        cls.base_fields[cls.CHOICE_FIELD] = forms.TypedChoiceField(
            label=category.name,
            widget=forms.Select,
            choices=choices,
            initial=0,
            empty_value=0,
            coerce=int,
        )

        cls.base_fields[cls.QUANTITY_FIELD] = forms.IntegerField(
            label="Quantity",  # TODO: internationalise
            min_value=0,
            max_value=500,  # Issue #19. We should figure out real limit.
        ) 
开发者ID:chrisjrn,项目名称:registrasion,代码行数:26,代码来源:forms.py

示例7: staff_products_form_factory

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def staff_products_form_factory(user):
    ''' Creates a StaffProductsForm that restricts the available products to
    those that are available to a user. '''

    products = inventory.Product.objects.all()
    products = ProductController.available_products(user, products=products)

    product_ids = [product.id for product in products]
    product_set = inventory.Product.objects.filter(id__in=product_ids)

    class StaffProductsForm(forms.Form):
        ''' Form for allowing staff to add an item to a user's cart. '''

        product = forms.ModelChoiceField(
            widget=forms.Select,
            queryset=product_set,
        )

        quantity = forms.IntegerField(
            min_value=0,
        )

    return StaffProductsForm 
开发者ID:chrisjrn,项目名称:registrasion,代码行数:25,代码来源:forms.py

示例8: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def render(self, name, value, attrs=None):
        if not self._isiterable(value):
            value = [value]

        if len(value) <= 1:
            # delegate to main widget (Select, etc...) if not multiple values
            value = value[0] if value else ''
            return super(BaseCSVWidget, self).render(name, value, attrs)

        # if we have multiple values, we need to force render as a text input
        # (otherwise, the additional values are lost)
        surrogate = forms.TextInput()
        value = [force_text(format_value(surrogate, v)) for v in value]
        value = ','.join(list(value))

        return surrogate.render(name, value, attrs) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:18,代码来源:widgets.py

示例9: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, *args, **kwargs):
        kwargs.setdefault('label_suffix', '')
        super(PoliticianForm, self).__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            if isinstance(field.widget, forms.TextInput) or isinstance(field.widget, forms.Select) or isinstance(field.widget, forms.EmailInput):
                field.widget.attrs.update({
                    'class': 'form-control'
                })
            if field_name == 'party':
                field.choices = [('', '---------')]
                field.choices += [
                    (p.id, p.name)
                    for p
                    in Party.objects.order_by('name')
                ]

            if isinstance(field.widget, forms.Textarea):
                field.widget.attrs.update({
                    'class': 'form-control',
                    'rows': 2,
                }) 
开发者ID:freedomvote,项目名称:freedomvote,代码行数:23,代码来源:forms.py

示例10: prepare_select

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def prepare_select(self, field):
        field_attrs = field.build_field_attrs()
        widget_attrs = field.build_widget_attrs()

        field_attrs.update({
            'widget': forms.Select(attrs=widget_attrs)
        })

        if field.choice_values:
            choice_list = field.get_choices()
            if not field.required:
                choice_list.insert(0, ('', field.placeholder_text or _('Please select an option')))
            field_attrs.update({
                'choices': choice_list
            })
        return forms.ChoiceField(**field_attrs) 
开发者ID:mishbahr,项目名称:djangocms-forms,代码行数:18,代码来源:forms.py

示例11: __init__

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

        super().__init__(*args, **kwargs)

        meeting = kwargs.get("instance")
        choices = [("", _("--- Selecciona ---"))]
        choices.extend(meeting.mentor.get_meeting_formats())
        self.fields["format"].widget = Select(choices=choices)
        self.fields["format"].required = True
        self.fields["format"].label = _("Formato")

        self.fields["message"].required = True
        self.fields["message"].label = _("Mensaje")
        self.fields["message"].help_text = _(
            "En este mensaje, explica de que quieres hablar en la reunión, por qué escogiste a esta persona. Trata de dejarle saber al mentor los temas que quieres hablar durante la reunión. Piensa que el mentor se tiene que preparar y tu debes estar preparado antes de la reunión. Este mensaje debe ayudar a ambos a saber que esperar de la reunión."
        ) 
开发者ID:SoPR,项目名称:horas,代码行数:19,代码来源:forms.py

示例12: __init__

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

示例13: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, *args, **kwargs):
        widgets = [forms.Select(), forms.TextInput(attrs={'size': 8, 'maxlength': 8})]
        kwargs['widgets'] = widgets
        super(SupervisorWidget, self).__init__(*args, **kwargs) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:6,代码来源:forms.py

示例14: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, *args, **kwargs):
        widgets = [forms.Select() for c in CATEGORY_CHOICES]
        kwargs['widgets'] = widgets
        super(AccountsWidget, self).__init__(*args, **kwargs) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:6,代码来源:forms.py

示例15: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Select [as 别名]
def __init__(self, *args, **kwargs):
        super(GravityLogCreateForm, self).__init__(*args, **kwargs)
        for this_field in self.fields:
            self.fields[this_field].widget.attrs['class'] = "form-control"
        self.fields['device'] = forms.ChoiceField(required=True, choices=self.get_device_choices(),
                                                  widget=forms.Select(attrs={'class': 'form-control',
                                                                             'data-toggle': 'select'})) 
开发者ID:thorrak,项目名称:fermentrack,代码行数:9,代码来源:forms.py


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