Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
2b379ac4
Commit
2b379ac4
authored
Oct 24, 2016
by
Serge S. Koval
Committed by
GitHub
Oct 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1362 from jmagnusson/revert-mapbox-flip-coordinates
Revert PR #1231
parents
f9840980
9679330c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
79 deletions
+8
-79
fields.py
flask_admin/contrib/geoa/fields.py
+8
-34
test_basic.py
flask_admin/tests/geoa/test_basic.py
+0
-45
No files found.
flask_admin/contrib/geoa/fields.py
View file @
2b379ac4
import
warnings
import
geoalchemy2
from
flask
import
current_app
from
shapely.geometry
import
shape
from
sqlalchemy
import
func
...
...
@@ -25,39 +22,18 @@ class GeoJSONField(JSONField):
self
.
geometry_type
=
geometry_type
.
upper
()
self
.
session
=
session
def
_flip_coordinates
(
self
,
other_func
):
if
current_app
.
config
.
get
(
'MAPBOX_FIX_COORDINATES_ORDER'
):
return
func
.
ST_FlipCoordinates
(
other_func
)
else
:
warnings
.
warn
(
'Consider setting the Flask config option '
'MAPBOX_FIX_COORDINATES_ORDER as the current implementation '
'passes lng/lat coordinates in the wrong order to '
'Leaflet. Without this setting any coordinates saved will '
'have flipped coordinates in your database. '
'Please note that this will become the standard behavior in '
'the next major version of Flask-Admin.'
)
return
other_func
def
_value
(
self
):
if
self
.
raw_data
:
return
self
.
raw_data
[
0
]
if
type
(
self
.
data
)
is
geoalchemy2
.
elements
.
WKBElement
:
if
self
.
srid
is
-
1
:
return
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
self
.
_flip_coordinates
(
self
.
data
)
)
)
return
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
self
.
data
))
else
:
return
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
self
.
_flip_coordinates
(
func
.
ST_Transform
(
self
.
data
,
self
.
web_srid
)
)
)
)
else
:
return
''
...
...
@@ -68,7 +44,6 @@ class GeoJSONField(JSONField):
if
self
.
data
is
not
None
:
web_shape
=
self
.
session
.
scalar
(
func
.
ST_AsText
(
self
.
_flip_coordinates
(
func
.
ST_Transform
(
func
.
ST_GeomFromText
(
shape
(
self
.
data
)
.
wkt
,
...
...
@@ -78,5 +53,4 @@ class GeoJSONField(JSONField):
)
)
)
)
self
.
data
=
'SRID='
+
str
(
self
.
srid
)
+
';'
+
str
(
web_shape
)
flask_admin/tests/geoa/test_basic.py
View file @
2b379ac4
...
...
@@ -125,51 +125,6 @@ def test_model():
eq_
(
db
.
session
.
query
(
GeoModel
)
.
count
(),
0
)
def
test_mapbox_fix_point_coordinates
():
app
,
db
,
admin
=
setup
()
app
.
config
[
'MAPBOX_FIX_COORDINATES_ORDER'
]
=
True
GeoModel
=
create_models
(
db
)
db
.
create_all
()
GeoModel
.
query
.
delete
()
db
.
session
.
commit
()
view
=
ModelView
(
GeoModel
,
db
.
session
)
admin
.
add_view
(
view
)
# Make some test clients
client
=
app
.
test_client
()
rv
=
client
.
post
(
'/admin/geomodel/new/'
,
data
=
{
"name"
:
"test1"
,
"point"
:
'{"type": "Point", "coordinates": [125.8, 10.0]}'
,
"line"
:
'{"type": "LineString", "coordinates": [[50.2345, 94.2], [50.21, 94.87]]}'
,
"polygon"
:
'{"type": "Polygon", "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}'
,
"multi"
:
'{"type": "MultiPoint", "coordinates": [[100.0, 0.0], [101.0, 1.0]]}'
,
})
model
=
db
.
session
.
query
(
GeoModel
)
.
first
()
# Notice how the coordinates are reversed here, i.e. longitude first which
# is the way it's stored in PostGIS columns.
eq_
(
list
(
to_shape
(
model
.
point
)
.
coords
),
[(
10.0
,
125.8
)])
eq_
(
list
(
to_shape
(
model
.
line
)
.
coords
),
[(
94.2
,
50.2345
),
(
94.87
,
50.21
)])
eq_
(
list
(
to_shape
(
model
.
polygon
)
.
exterior
.
coords
),
[(
0.0
,
100.0
),
(
0.0
,
101.0
),
(
1.0
,
101.0
),
(
1.0
,
100.0
),
(
0.0
,
100.0
)])
eq_
(
list
(
to_shape
(
model
.
multi
)
.
geoms
[
0
]
.
coords
),
[(
0.0
,
100.0
)])
eq_
(
list
(
to_shape
(
model
.
multi
)
.
geoms
[
1
]
.
coords
),
[(
1.0
,
101.0
)])
rv
=
client
.
get
(
'/admin/geomodel/'
)
eq_
(
rv
.
status_code
,
200
)
html
=
rv
.
data
.
decode
(
'utf-8'
)
pattern
=
r'(.|\n)+({.*"type": ?"Point".*})</textarea>(.|\n)+'
group
=
re
.
match
(
pattern
,
html
)
.
group
(
2
)
p
=
json
.
loads
(
group
)
# Reversed order again, so that it's parsed correctly by leaflet
eq_
(
p
[
'coordinates'
][
0
],
10.0
)
eq_
(
p
[
'coordinates'
][
1
],
125.8
)
def
test_none
():
app
,
db
,
admin
=
setup
()
GeoModel
=
create_models
(
db
)
...
...
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