Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
d7e18a50
Kaydet (Commit)
d7e18a50
authored
Kas 22, 2018
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29978 -- Catched GDALException in GeometryField.to_python
üst
31408446
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
fields.py
django/contrib/gis/forms/fields.py
+5
-1
test_geoforms.py
tests/gis_tests/test_geoforms.py
+20
-8
No files found.
django/contrib/gis/forms/fields.py
Dosyayı görüntüle @
d7e18a50
from
django
import
forms
from
django.contrib.gis.gdal
import
GDALException
from
django.contrib.gis.geos
import
GEOSException
,
GEOSGeometry
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -36,7 +37,10 @@ class GeometryField(forms.Field):
if
not
isinstance
(
value
,
GEOSGeometry
):
if
hasattr
(
self
.
widget
,
'deserialize'
):
value
=
self
.
widget
.
deserialize
(
value
)
try
:
value
=
self
.
widget
.
deserialize
(
value
)
except
GDALException
:
value
=
None
else
:
try
:
value
=
GEOSGeometry
(
value
)
...
...
tests/gis_tests/test_geoforms.py
Dosyayı görüntüle @
d7e18a50
...
...
@@ -69,19 +69,31 @@ class GeometryFieldTest(SimpleTestCase):
def
test_to_python
(
self
):
"""
Testing to_python
returns a correct GEOSGeometry object or
a ValidationError
to_python() either
returns a correct GEOSGeometry object or
a ValidationError
.
"""
good_inputs
=
[
'POINT(5 23)'
,
'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))'
,
'LINESTRING(0 0, 1 1)'
,
]
bad_inputs
=
[
'POINT(5)'
,
'MULTI POLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))'
,
'BLAH(0 0, 1 1)'
,
'{"type": "FeatureCollection", "features": ['
'{"geometry": {"type": "Point", "coordinates": [508375, 148905]}, "type": "Feature"}]}'
,
]
fld
=
forms
.
GeometryField
()
# to_python returns the same GEOSGeometry for a WKT
for
wkt
in
(
'POINT(5 23)'
,
'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))'
,
'LINESTRING(0 0, 1 1)'
)
:
with
self
.
subTest
(
wkt
=
wk
t
):
self
.
assertEqual
(
GEOSGeometry
(
wkt
,
srid
=
fld
.
widget
.
map_srid
),
fld
.
to_python
(
wk
t
))
for
geo_input
in
good_inputs
:
with
self
.
subTest
(
geo_input
=
geo_inpu
t
):
self
.
assertEqual
(
GEOSGeometry
(
geo_input
,
srid
=
fld
.
widget
.
map_srid
),
fld
.
to_python
(
geo_inpu
t
))
# but raises a ValidationError for any other string
for
wkt
in
(
'POINT(5)'
,
'MULTI POLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))'
,
'BLAH(0 0, 1 1)'
)
:
with
self
.
subTest
(
wkt
=
wk
t
):
for
geo_input
in
bad_inputs
:
with
self
.
subTest
(
geo_input
=
geo_inpu
t
):
with
self
.
assertRaises
(
forms
.
ValidationError
):
fld
.
to_python
(
wk
t
)
fld
.
to_python
(
geo_inpu
t
)
def
test_to_python_different_map_srid
(
self
):
f
=
forms
.
GeometryField
(
widget
=
OpenLayersWidget
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment