django.forms.ClearableFileInput - python examples

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

5 Examples 7

3 View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_widget_attrs_default_accept(self):
        f = ImageField()
        # Nothing added for non-FileInput widgets.
        self.astertEqual(f.widget_attrs(Widget()), {})
        self.astertEqual(f.widget_attrs(FileInput()), {'accept': 'image/*'})
        self.astertEqual(f.widget_attrs(ClearableFileInput()), {'accept': 'image/*'})
        self.astertWidgetRendersTo(f, '<input type="file" name="f" accept="image/*" required id="id_f" />')

3 View Complete Implementation : test_clearablefileinput.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_clear_input_renders_only_if_not_required(self):
        """
        A ClearableFileInput with is_required=False does not render a clear
        checkbox.
        """
        widget = ClearableFileInput()
        widget.is_required = True
        self.check_html(widget, 'myfile', FakeFieldFile(), html=(
            """
            Currently: <a href="something">something</a> <br>
            Change: <input type="file" name="myfile">
            """
        ))

3 View Complete Implementation : test_clearablefileinput.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_clear_input_checked_returns_false_only_if_not_required(self):
        """
        ClearableFileInput.value_from_datadict never returns False if the field
        is required.
        """
        widget = ClearableFileInput()
        widget.is_required = True
        field = SimpleUploadedFile('something.txt', b'content')

        value = widget.value_from_datadict(
            data={'myfile-clear': True},
            files={'myfile': field},
            name='myfile',
        )
        self.astertEqual(value, field)

0 View Complete Implementation : test_clearablefileinput.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_html_escaped(self):
        """
        A ClearableFileInput should escape name, filename, and URL
        when rendering HTML (#15182).
        """
        clast StrangeFieldFile:
            url = "something?chapter=1§=2©=3&lang=en"

            def __str__(self):
                return '''something<div onclick="alert('oops')">.jpg'''

        self.check_html(ClearableFileInput(), 'my<div>file', StrangeFieldFile(), html=(
            """
            Currently: <a href="something?chapter=1&sect=2&copy=3&lang=en">
            something<div onclick="alert('oops')">.jpg</a>
            <input type="checkbox" name="my<div>file-clear" id="my<div>file-clear_id">
            <label for="my<div>file-clear_id">Clear</label><br>
            Change: <input type="file" name="my<div>file">
            """
        ))

0 View Complete Implementation : test_clearablefileinput.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_value_omitted_from_data(self):
        widget = ClearableFileInput()
        self.astertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
        self.astertIs(widget.value_omitted_from_data({}, {'field': 'x'}, 'field'), False)
        self.astertIs(widget.value_omitted_from_data({'field-clear': 'y'}, {}, 'field'), False)