本文整理匯總了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
示例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"
示例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)
示例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'}),
)
示例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)
示例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.
)
示例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
示例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)
示例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,
})
示例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)
示例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."
)
示例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)
示例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)
示例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)
示例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'}))