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


Python forms.PointField方法代码示例

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


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

示例1: test_pointfield

# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import PointField [as 别名]
def test_pointfield(self):
        class PointForm(forms.Form):
            p = forms.PointField()

        geom = self.geometries['point']
        form = PointForm(data={'p': geom})
        self.assertTextarea(geom, form.as_p())
        self.assertMapWidget(form)
        self.assertFalse(PointForm().is_valid())
        invalid = PointForm(data={'p': 'some invalid geom'})
        self.assertFalse(invalid.is_valid())
        self.assertTrue('Invalid geometry value' in str(invalid.errors))

        for invalid in [geom for key, geom in self.geometries.items() if key!='point']:
            self.assertFalse(PointForm(data={'p': invalid.wkt}).is_valid()) 
开发者ID:VirtualPlants,项目名称:tissuelab,代码行数:17,代码来源:test_geoforms.py

示例2: test_osm_widget

# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import PointField [as 别名]
def test_osm_widget(self):
        class PointForm(forms.Form):
            p = forms.PointField(widget=forms.OSMWidget)

        geom = self.geometries['point']
        form = PointForm(data={'p': geom})
        rendered = form.as_p()
        self.assertIn("OpenStreetMap (Mapnik)", rendered)
        self.assertIn("id: 'id_p',", rendered) 
开发者ID:VirtualPlants,项目名称:tissuelab,代码行数:11,代码来源:test_geoforms.py

示例3: test_custom_serialization_widget

# 需要导入模块: from django.contrib.gis import forms [as 别名]
# 或者: from django.contrib.gis.forms import PointField [as 别名]
def test_custom_serialization_widget(self):
        class CustomGeometryWidget(forms.BaseGeometryWidget):
            template_name = 'gis/openlayers.html'
            deserialize_called = 0
            def serialize(self, value):
                return value.json if value else ''

            def deserialize(self, value):
                self.deserialize_called += 1
                return GEOSGeometry(value)

        class PointForm(forms.Form):
            p = forms.PointField(widget=CustomGeometryWidget)

        point = GEOSGeometry("SRID=4326;POINT(9.052734375 42.451171875)")
        form = PointForm(data={'p': point})
        self.assertIn(escape(point.json), form.as_p())

        CustomGeometryWidget.called = 0
        widget = form.fields['p'].widget
        # Force deserialize use due to a string value
        self.assertIn(escape(point.json), widget.render('p', point.json))
        self.assertEqual(widget.deserialize_called, 1)

        form = PointForm(data={'p': point.json})
        self.assertTrue(form.is_valid())
        # Ensure that resulting geometry has srid set
        self.assertEqual(form.cleaned_data['p'].srid, 4326) 
开发者ID:VirtualPlants,项目名称:tissuelab,代码行数:30,代码来源:test_geoforms.py


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