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
5585a2a7
Commit
5585a2a7
authored
Dec 07, 2014
by
Alex Kerney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Passing 'data-widths' and 'data-height' to the Leaflet view if the keys are in `form_widget_args`
parent
6e333212
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
fields.py
flask_admin/contrib/geoa/fields.py
+9
-8
widgets.py
flask_admin/contrib/geoa/widgets.py
+4
-2
No files found.
flask_admin/contrib/geoa/fields.py
View file @
5585a2a7
...
...
@@ -37,7 +37,7 @@ class JSONField(TextAreaField):
class
GeoJSONField
(
JSONField
):
widget
=
LeafletWidget
()
def
__init__
(
self
,
label
=
None
,
validators
=
None
,
geometry_type
=
"GEOMETRY"
,
srid
=
'-1'
,
session
=
None
,
**
kwargs
):
super
(
GeoJSONField
,
self
)
.
__init__
(
label
,
validators
,
**
kwargs
)
self
.
web_srid
=
4326
...
...
@@ -48,20 +48,21 @@ class GeoJSONField(JSONField):
self
.
transform_srid
=
self
.
srid
self
.
geometry_type
=
geometry_type
.
upper
()
self
.
session
=
session
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
:
self
.
data
=
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
self
.
data
))
else
:
self
.
data
=
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
func
.
ST_Transform
(
self
.
data
,
self
.
web_srid
)))
if
self
.
srid
is
-
1
:
self
.
data
=
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
self
.
data
))
else
:
self
.
data
=
self
.
session
.
scalar
(
func
.
ST_AsGeoJson
(
func
.
ST_Transform
(
self
.
data
,
self
.
web_srid
)))
return
super
(
GeoJSONField
,
self
)
.
_value
()
def
process_formdata
(
self
,
valuelist
):
super
(
GeoJSONField
,
self
)
.
process_formdata
(
valuelist
)
print
type
(
self
.
data
)
if
str
(
self
.
data
)
is
''
:
self
.
data
=
None
if
type
(
self
.
data
)
is
not
NoneType
:
web_shape
=
self
.
session
.
scalar
(
func
.
ST_AsText
(
func
.
ST_Transform
(
func
.
ST_GeomFromText
(
shape
(
self
.
data
)
.
wkt
,
self
.
web_srid
),
self
.
transform_srid
)))
self
.
data
=
'SRID='
+
str
(
self
.
srid
)
+
';'
+
str
(
web_shape
)
flask_admin/contrib/geoa/widgets.py
View file @
5585a2a7
...
...
@@ -36,9 +36,10 @@ class LeafletWidget(TextArea):
kwargs
.
setdefault
(
'data-geometry-type'
,
gtype
)
# set optional values from constructor
if
self
.
width
:
print
kwargs
if
not
kwargs
.
has_key
(
"data-width"
):
kwargs
[
"data-width"
]
=
self
.
width
if
self
.
height
:
if
not
kwargs
.
has_key
(
"data-height"
)
:
kwargs
[
"data-height"
]
=
self
.
height
if
self
.
center
:
kwargs
[
"data-lat"
]
=
lat
(
self
.
center
)
...
...
@@ -67,4 +68,5 @@ class LeafletWidget(TextArea):
kwargs
[
"data-max-bounds-ne-lat"
]
=
maxx
kwargs
[
"data-max-bounds-ne-lng"
]
=
maxy
print
kwargs
return
super
(
LeafletWidget
,
self
)
.
__call__
(
field
,
**
kwargs
)
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