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


Python ClearableFileInput.render方法代碼示例

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


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

示例1: test_html_does_not_mask_exceptions

# 需要導入模塊: from django.forms import ClearableFileInput [as 別名]
# 或者: from django.forms.ClearableFileInput import render [as 別名]
    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,代碼行數:20,代碼來源:test_clearablefileinput.py

示例2: test_accept

# 需要導入模塊: from django.forms import ClearableFileInput [as 別名]
# 或者: from django.forms.ClearableFileInput import render [as 別名]
    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,代碼行數:21,代碼來源:test_forms.py

示例3: test_render_custom_template

# 需要導入模塊: from django.forms import ClearableFileInput [as 別名]
# 或者: from django.forms.ClearableFileInput import render [as 別名]
 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,代碼行數:14,代碼來源:test_widgets.py

示例4: test_html_escaped

# 需要導入模塊: from django.forms import ClearableFileInput [as 別名]
# 或者: from django.forms.ClearableFileInput import render [as 別名]
    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,代碼行數:23,代碼來源:test_clearablefileinput.py

示例5: render

# 需要導入模塊: from django.forms import ClearableFileInput [as 別名]
# 或者: from django.forms.ClearableFileInput import render [as 別名]
 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,代碼行數:6,代碼來源:admin.py


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