当前位置: 首页>>代码示例>>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;未经允许,请勿转载。