當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.BoundField方法代碼示例

本文整理匯總了Python中django.forms.BoundField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.BoundField方法的具體用法?Python forms.BoundField怎麽用?Python forms.BoundField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.BoundField方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_bound_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def get_bound_field(self, form, field_name):
        bound_field = BoundField(form, self, field_name)

        # Modify the QuerySet of the field before we return it. Limit choices to any
        # data already bound: Options will be populated on-demand via the APISelect
        # widget
        data = self.prepare_value(bound_field.data or bound_field.initial)
        if data:
            filter = self.filter(
                field_name=self.to_field_name or "pk", queryset=self.queryset
            )
            self.queryset = filter.filter(self.queryset, data)
        else:
            self.queryset = self.queryset.none()

        # Set the data URL on the APISelect widget (if not already set)
        widget = bound_field.field.widget
        if not widget.attrs.get("data-url"):
            data_url = reverse(
                f"{self.queryset.model._meta.app_label}-api:{self.queryset.model._meta.model_name}-list"
            )
            widget.attrs["data-url"] = data_url

        return bound_field 
開發者ID:respawner,項目名稱:peering-manager,代碼行數:26,代碼來源:forms.py

示例2: get_bound_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def get_bound_field(self, form, field_name):
        """
        For Django 1.9+

        Return a BoundField instance that will be used when accessing the form
        field in a template.
        """
        return PrefixedBoundField(form, self, field_name) 
開發者ID:MarkusH,項目名稱:django-osm-field,代碼行數:10,代碼來源:forms.py

示例3: test_display_choice_verbose

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def test_display_choice_verbose(self):
        form = MockForm(data=self.data)
        field = form.fields.get('type')
        bf = forms.BoundField(form, field, 'type')
        value = filters.display_choice_verbose(bf)
        assert value == 'Group' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:8,代碼來源:test_filters.py

示例4: test_field_value

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def test_field_value(self):
        form = MockForm(data=self.data)
        field = form.fields.get('type')
        bf = forms.BoundField(form, field, 'type')
        value = filters.field_value(bf)
        assert value == 'GR' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:8,代碼來源:test_filters.py

示例5: test_field_value_file_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def test_field_value_file_field(self):
        form = MockForm(
            data=self.data,
            files={'file': SimpleUploadedFile('test.txt', b'some content')}
        )
        field = form.fields.get('file')
        bf = forms.BoundField(form, field, 'file')
        value = filters.field_value(bf)
        assert value.name == 'test.txt' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:11,代碼來源:test_filters.py

示例6: test_blank_file_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def test_blank_file_field(self):
        form = MockForm(data=self.data)
        field = form.fields.get('file')
        bf = forms.BoundField(form, field, 'file')
        value = filters.field_value(bf)
        assert value == '' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:8,代碼來源:test_filters.py

示例7: test_field_value_as_callable

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def test_field_value_as_callable(self):
        form = MockForm()
        field = form.fields.get('date')
        bf = forms.BoundField(form, field, 'date')
        value = filters.field_value(bf)
        assert isinstance(value, datetime.datetime) 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:8,代碼來源:test_filters.py

示例8: test_set_parsley_sanitize

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def test_set_parsley_sanitize(self):
        form = MockForm(data={'name', 'Test'})
        field = form.fields.get('name')
        bf = forms.BoundField(form, field, 'name')
        filters.set_parsley_sanitize(bf)
        assert bf.field.widget.attrs == {'data-parsley-sanitize': '1'} 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:8,代碼來源:test_filters.py

示例9: get_unbound_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def get_unbound_field(field: Union[BoundField, Field]) -> Field:
    """
    Unwraps a bound Django Forms field, returning the unbound field.

    Bound fields often don't give you the same level of access to the field's underlying attributes,
    so sometimes it helps to have access to the underlying field object.
    """
    while isinstance(field, BoundField):
        field = field.field

    return field 
開發者ID:python-discord,項目名稱:site,代碼行數:13,代碼來源:wiki_extra.py

示例10: get_field_options

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def get_field_options(context: Context, field: BoundField) -> str:
    """
    Retrieves the field options for a multiple choice field, and stores it in the context.

    This tag exists because we can't call functions within Django templates directly, and is
    only made use of in the template for ModelChoice (and derived) fields - but would work fine
    with anything that makes use of your standard `<select>` element widgets.

    This stores the parsed options under `options` in the context, which will subsequently
    be available in the template.

    Usage:

    ```django
    {% get_field_options field_object %}

    {% if options %}
      {% for group_name, group_choices, group_index in options %}
        ...
      {% endfor %}
    {% endif %}
    ```
    """
    widget = field.field.widget

    if field.value() is None:
        value: List[str] = []
    else:
        value = [str(field.value())]

    context["options"] = widget.optgroups(field.name, value)
    return "" 
開發者ID:python-discord,項目名稱:site,代碼行數:34,代碼來源:wiki_extra.py

示例11: column_mapping_fields

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def column_mapping_fields(self) -> List[BoundField]:
        """
        Convenience method to be used in the front-end to render import template
        table.

        :return: List of BoundField objects that are visible and part of the
                 columns mapping fields.
        """
        return [field for field in self.visible_fields() if field.name.startswith('__column_')] 
開發者ID:vitorfs,項目名稱:colossus,代碼行數:11,代碼來源:forms.py

示例12: import_settings_fields

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BoundField [as 別名]
def import_settings_fields(self) -> List[BoundField]:
        """
        Convenience method to be used in the front-end to list visible fields
        not related to columns mapping.

        :return: List of BoundField objects that are visible and not part of the
                 columns mapping fields.
        """
        return [field for field in self.visible_fields() if not field.name.startswith('__column_')] 
開發者ID:vitorfs,項目名稱:colossus,代碼行數:11,代碼來源:forms.py


注:本文中的django.forms.BoundField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。