当前位置: 首页>>代码示例>>Python>>正文


Python forms.ClearableFileInput类代码示例

本文整理汇总了Python中django.forms.ClearableFileInput的典型用法代码示例。如果您正苦于以下问题:Python ClearableFileInput类的具体用法?Python ClearableFileInput怎么用?Python ClearableFileInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClearableFileInput类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_clear_input_checked_returns_false_only_if_not_required

    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.assertEqual(value, field)
开发者ID:,项目名称:,代码行数:11,代码来源:

示例2: test_render_custom_template

 def test_render_custom_template(self):
     widget = ClearableFileInput()
     widget.template_with_initial = (
         '%(initial_text)s: <img src="%(initial_url)s" alt="%(initial)s" /> '
         '%(clear_template)s<br />%(input_text)s: %(input)s'
     )
     self.assertHTMLEqual(
         widget.render('myfile', FakeFieldFile()),
         'Currently: <img src="something" alt="something" /> '
         '<input type="checkbox" name="myfile-clear" id="myfile-clear_id" /> '
         '<label for="myfile-clear_id">Clear</label><br />Change: <input type="file" name="myfile" />'
     )
开发者ID:Hwesta,项目名称:django,代码行数:12,代码来源:test_widgets.py

示例3: test_clear_input_renders_only_if_not_required

 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">
         """
     ))
开发者ID:MattBlack85,项目名称:django,代码行数:13,代码来源:test_clearablefileinput.py

示例4: test_html_does_not_mask_exceptions

    def test_html_does_not_mask_exceptions(self):
        """
        A ClearableFileInput should not mask exceptions produced while
        checking that it has a value.
        """
        @python_2_unicode_compatible
        class FailingURLFieldFile(object):
            @property
            def url(self):
                raise RuntimeError('Canary')

            def __str__(self):
                return 'value'

        widget = ClearableFileInput()
        field = FailingURLFieldFile()
        with self.assertRaisesMessage(RuntimeError, 'Canary'):
            widget.render('myfile', field)
开发者ID:Matt-Deacalion,项目名称:django,代码行数:18,代码来源:test_clearablefileinput.py

示例5: test_html_escaped

    def test_html_escaped(self):
        """
        A ClearableFileInput should escape name, filename, and URL
        when rendering HTML (#15182).
        """
        @python_2_unicode_compatible
        class StrangeFieldFile(object):
            url = "something?chapter=1&sect=2&copy=3&lang=en"

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

        widget = ClearableFileInput()
        field = StrangeFieldFile()
        output = widget.render('my<div>file', field)
        self.assertNotIn(field.url, output)
        self.assertIn('href="something?chapter=1&amp;sect=2&amp;copy=3&amp;lang=en"', output)
        self.assertNotIn(six.text_type(field), output)
        self.assertIn('something&lt;div onclick=&quot;alert(&#39;oops&#39;)&quot;&gt;.jpg', output)
        self.assertIn('my&lt;div&gt;file', output)
        self.assertNotIn('my<div>file', output)
开发者ID:01-,项目名称:django,代码行数:21,代码来源:test_clearablefileinput.py

示例6: test_value_omitted_from_data

 def test_value_omitted_from_data(self):
     widget = ClearableFileInput()
     self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
     self.assertIs(widget.value_omitted_from_data({}, {'field': 'x'}, 'field'), False)
     self.assertIs(widget.value_omitted_from_data({'field-clear': 'y'}, {}, 'field'), False)
开发者ID:MattBlack85,项目名称:django,代码行数:5,代码来源:test_clearablefileinput.py

示例7: render

 def render(self, name, value, attrs=None):
     output = ClearableFileInput.render(self, name, value, attrs)
     output += self.output_extra_data(value)
     return mark_safe(output)
开发者ID:kfarr2,项目名称:django-file-resubmit,代码行数:4,代码来源:admin.py

示例8: test_accept

    def test_accept(self):
        widget = ClearableFileInput()
        assert 'accept' not in widget.render(name='file', value='test.jpg')
        assert ["starts-with", "$Content-Type", ""] in widget.get_conditions(None)

        widget = ClearableFileInput(attrs={'accept': 'image/*'})
        assert 'accept="image/*"' in widget.render(name='file', value='test.jpg')
        assert ["starts-with", "$Content-Type", "image/"] in widget.get_conditions('image/*')

        widget = ClearableFileInput(attrs={'accept': 'image/jpeg'})
        assert 'accept="image/jpeg"' in widget.render(name='file', value='test.jpg')
        assert {"Content-Type": 'image/jpeg'} in widget.get_conditions('image/jpeg')

        widget = ClearableFileInput(attrs={'accept': 'application/pdf,image/*'})
        assert 'accept="application/pdf,image/*"' in widget.render(name='file', value='test.jpg')
        assert ["starts-with", "$Content-Type", ""] in widget.get_conditions(
            'application/pdf,image/*')
        assert {"Content-Type": 'application/pdf'} not in widget.get_conditions(
            'application/pdf,image/*')
开发者ID:codingjoe,项目名称:django-s3file,代码行数:19,代码来源:test_forms.py


注:本文中的django.forms.ClearableFileInput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。