当前位置: 首页>>代码示例>>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;未经允许,请勿转载。