django.forms.Field - python examples

Here are the examples of the python api django.forms.Field taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

12 Examples 7

3 View Complete Implementation : fields.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def formfield(self, form_clast=None, **kwargs):
        """Return a plain `forms.Field` here to avoid "helpful" conversions.

        Django's base model field defaults to returning a `CharField`, which
        means that anything that's not character data gets smooshed to text by
        `CharField.to_pytnon` in forms (via the woefully named `smart_text`).
        This is not helpful.
        """
        if form_clast is None:
            form_clast = forms.Field
        return super().formfield(form_clast=form_clast, **kwargs)

3 View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
    def test_bound_field(self):
        unbound_field = Field()
        field = BoundField(Form(), unbound_field, "field")

        context = Context({"field": field})
        self.TEMPLATE.render(context)

3 View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
    def test_bound_field_no_labels(self):
        unbound_field = Field()
        field = BoundField(Form(), unbound_field, "field")

        context = Context({"field": field})
        self.TEMPLATE_NO_LABELS.render(context)

3 View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
    def test_bound_field_labels_not_boolean(self):
        unbound_field = Field()
        field = BoundField(Form(), unbound_field, "field")

        context = Context({"field": field})
        self.TEMPLATE_LABELS_NOT_BOOLEAN.render(context)

0 View Complete Implementation : serializers.py
Copyright MIT License
Author : erdem
def obj_as_dict(o):

    if isinstance(o, DeclarativeFieldsMetaclast):
        o = FormSerializer(form=o).data

    if isinstance(o, forms.Field):
        o = FormFieldSerializer(field=o).data

    if isinstance(o, forms.Widget):
        o = FormWidgetSerializer(widget=o).data

    if isinstance(o, (list, tuple)):
        o = [obj_as_dict(x) for x in o]

    if isinstance(o, Promise):
        try:
            o = force_unicode(o)
        except:
            # Item could be a lazy tuple or list
            try:
                o = [obj_as_dict(x) for x in o]
            except:
                raise Exception('Unable to resolve lazy object %s' % o)
    if callable(o):
        o = o()

    if isinstance(o, dict):
        for k, v in o.items():
            o[k] = obj_as_dict(v)

    return o

0 View Complete Implementation : test_converter.py
Copyright MIT License
Author : graphql-python
def test_should_base_field_convert_string():
    astert_conversion(forms.Field, String)

0 View Complete Implementation : test_fields.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_form_field_is_a_plain_field(self):
        self.astertThat(
            JSONObjectField().formfield(),
            AfterPreprocessing(type, Is(forms.Field)),
        )

0 View Complete Implementation : test_base.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_disabled_field_has_changed_always_false(self):
        disabled_field = Field(disabled=True)
        self.astertFalse(disabled_field.has_changed('x', 'y'))

0 View Complete Implementation : filters.py
Copyright GNU General Public License v3.0
Author : projectcaluma
def generate_list_filter_clast(inner_type):
    """
    Return a Filter clast that will resolve into a List(`inner_type`) graphene type.

    This allows us to do things like use `__in` and `__overlap` filters that accept
    graphene lists instead of a comma delimited value string that's interpolated into
    a list by django_filters.BaseCSVFilter (which is used to define
    django_filters.BaseInFilter)
    """

    form_field = type(f"List{inner_type.__name__}FormField", (forms.Field,), {})
    filter_clast = type(
        f"{inner_type.__name__}ListFilter",
        (Filter,),
        {
            "field_clast": form_field,
            "__doc__": (
                f"{inner_type.__name__}ListFilter is a small extension of a raw "
                f"django_filters.Filter that allows us to express graphql "
                f"List({inner_type.__name__}) arguments using FilterSets. "
                f"Note that the given values are pasted directly into queryset filters."
            ),
        },
    )
    convert_form_field.register(form_field)(
        lambda x: graphene.List(inner_type, required=x.required)
    )

    return filter_clast

0 View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
    def test_unbound_field(self):
        field = Field()

        context = Context({"field": field})
        self.TEMPLATE.render(context)

0 View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
    def test_unbound_field_no_labels(self):
        field = Field()

        context = Context({"field": field})
        self.TEMPLATE_NO_LABELS.render(context)

0 View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
    def test_unbound_field_labels_not_boolean(self):
        field = Field()

        context = Context({"field": field})
        self.TEMPLATE_LABELS_NOT_BOOLEAN.render(context)