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


Python widgets.AdminURLFieldWidget方法代碼示例

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


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

示例1: test_URLField

# 需要導入模塊: from django.contrib.admin import widgets [as 別名]
# 或者: from django.contrib.admin.widgets import AdminURLFieldWidget [as 別名]
def test_URLField(self):
        self.assertFormfield(Event, 'link', widgets.AdminURLFieldWidget) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:tests.py

示例2: test_render

# 需要導入模塊: from django.contrib.admin import widgets [as 別名]
# 或者: from django.contrib.admin.widgets import AdminURLFieldWidget [as 別名]
def test_render(self):
        w = widgets.AdminURLFieldWidget()
        self.assertHTMLEqual(
            w.render('test', ''),
            '<input class="vURLField" name="test" type="url">'
        )
        self.assertHTMLEqual(
            w.render('test', 'http://example.com'),
            '<p class="url">Currently:<a href="http://example.com">'
            'http://example.com</a><br>'
            'Change:<input class="vURLField" name="test" type="url" '
            'value="http://example.com"></p>'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:15,代碼來源:tests.py

示例3: test_render_idn

# 需要導入模塊: from django.contrib.admin import widgets [as 別名]
# 或者: from django.contrib.admin.widgets import AdminURLFieldWidget [as 別名]
def test_render_idn(self):
        w = widgets.AdminURLFieldWidget()
        self.assertHTMLEqual(
            w.render('test', 'http://example-äüö.com'),
            '<p class="url">Currently: <a href="http://xn--example--7za4pnc.com">'
            'http://example-äüö.com</a><br>'
            'Change:<input class="vURLField" name="test" type="url" '
            'value="http://example-äüö.com"></p>'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:tests.py

示例4: test_render_quoting

# 需要導入模塊: from django.contrib.admin import widgets [as 別名]
# 或者: from django.contrib.admin.widgets import AdminURLFieldWidget [as 別名]
def test_render_quoting(self):
        """
        WARNING: This test doesn't use assertHTMLEqual since it will get rid
        of some escapes which are tested here!
        """
        HREF_RE = re.compile('href="([^"]+)"')
        VALUE_RE = re.compile('value="([^"]+)"')
        TEXT_RE = re.compile('<a[^>]+>([^>]+)</a>')
        w = widgets.AdminURLFieldWidget()
        output = w.render('test', 'http://example.com/<sometag>some text</sometag>')
        self.assertEqual(
            HREF_RE.search(output).groups()[0],
            'http://example.com/%3Csometag%3Esome%20text%3C/sometag%3E',
        )
        self.assertEqual(
            TEXT_RE.search(output).groups()[0],
            'http://example.com/&lt;sometag&gt;some text&lt;/sometag&gt;',
        )
        self.assertEqual(
            VALUE_RE.search(output).groups()[0],
            'http://example.com/&lt;sometag&gt;some text&lt;/sometag&gt;',
        )
        output = w.render('test', 'http://example-äüö.com/<sometag>some text</sometag>')
        self.assertEqual(
            HREF_RE.search(output).groups()[0],
            'http://xn--example--7za4pnc.com/%3Csometag%3Esome%20text%3C/sometag%3E',
        )
        self.assertEqual(
            TEXT_RE.search(output).groups()[0],
            'http://example-äüö.com/&lt;sometag&gt;some text&lt;/sometag&gt;',
        )
        self.assertEqual(
            VALUE_RE.search(output).groups()[0],
            'http://example-äüö.com/&lt;sometag&gt;some text&lt;/sometag&gt;',
        )
        output = w.render('test', 'http://www.example.com/%C3%A4"><script>alert("XSS!")</script>"')
        self.assertEqual(
            HREF_RE.search(output).groups()[0],
            'http://www.example.com/%C3%A4%22%3E%3Cscript%3Ealert(%22XSS!%22)%3C/script%3E%22',
        )
        self.assertEqual(
            TEXT_RE.search(output).groups()[0],
            'http://www.example.com/%C3%A4&quot;&gt;&lt;script&gt;'
            'alert(&quot;XSS!&quot;)&lt;/script&gt;&quot;'
        )
        self.assertEqual(
            VALUE_RE.search(output).groups()[0],
            'http://www.example.com/%C3%A4&quot;&gt;&lt;script&gt;alert(&quot;XSS!&quot;)&lt;/script&gt;&quot;',
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:51,代碼來源:tests.py


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