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
6f628968
Commit
6f628968
authored
May 24, 2015
by
Petrus J.v.Rensburg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a basic GeoAlchemy example.
parent
45b8a953
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
0 deletions
+106
-0
README.rst
examples/geo-alchemy/README.rst
+39
-0
__init__.py
examples/geo-alchemy/__init__.py
+0
-0
app.py
examples/geo-alchemy/app.py
+45
-0
requirements.txt
examples/geo-alchemy/requirements.txt
+6
-0
index.html
examples/geo-alchemy/templates/admin/index.html
+16
-0
No files found.
examples/geo-alchemy/README.rst
0 → 100644
View file @
6f628968
SQLAlchemy model backend integration examples.
To run this example:
1. Clone the repository::
git clone https://github.com/flask-admin/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/geo-alchemy/requirements.txt'
4. Setup the database::
psql postgres
CREATE DATABASE flask_admin_geo;
CREATE ROLE flask_admin_geo LOGIN PASSWORD 'flask_admin_geo';
GRANT ALL PRIVILEGES ON DATABASE flask_admin_geo TO flask_admin_geo;
\q
psql flask_admin_geo
CREATE EXTENSION postgis;
\q
5. Run the application::
python examples/sqla/app.py
6. You will notice that the maps are not rendered. To see them, you will have
to register for a free account at `Mapbox <https://www.mapbox.com/>`_ and set
the *MAPBOX_MAP_ID* and *MAPBOX_ACCESS_TOKEN* config variables accordingly.
\ No newline at end of file
examples/geo-alchemy/__init__.py
0 → 100644
View file @
6f628968
examples/geo-alchemy/app.py
0 → 100644
View file @
6f628968
from
flask
import
Flask
from
flask_sqlalchemy
import
SQLAlchemy
import
flask_admin
as
admin
from
geoalchemy2.types
import
Geometry
from
flask_admin.contrib.geoa
import
ModelView
# Create application
app
=
Flask
(
__name__
)
# Create dummy secrey key so we can use sessions
app
.
config
[
'SECRET_KEY'
]
=
'123456790'
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'postgresql+psycopg2://flask_admin_geo:flask_admin_geo@localhost/flask_admin_geo'
app
.
config
[
'SQLALCHEMY_ECHO'
]
=
True
db
=
SQLAlchemy
(
app
)
app
.
config
[
'MAPBOX_MAP_ID'
]
=
"..."
app
.
config
[
'MAPBOX_ACCESS_TOKEN'
]
=
"..."
class
Location
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
64
),
unique
=
True
)
point
=
db
.
Column
(
Geometry
(
"POINT"
))
# Flask views
@
app
.
route
(
'/'
)
def
index
():
return
'<a href="/admin/">Click me to get to Admin!</a>'
# Create admin
admin
=
admin
.
Admin
(
app
,
name
=
'Example: GeoAlchemy'
)
# Add views
admin
.
add_view
(
ModelView
(
Location
,
db
.
session
))
if
__name__
==
'__main__'
:
db
.
create_all
()
# Start app
app
.
run
(
debug
=
True
)
examples/geo-alchemy/requirements.txt
0 → 100644
View file @
6f628968
Flask
Flask-Admin
Flask-SQLAlchemy
shapely
geoalchemy2
psycopg2
\ No newline at end of file
examples/geo-alchemy/templates/admin/index.html
0 → 100644
View file @
6f628968
{% extends 'admin/master.html' %}
{% block body %}
{{ super() }}
<div
class=
"row"
>
<div
class=
"span10 offset1"
>
<h1>
Flask-Admin example
</h1>
<p
class=
"lead"
>
GeoAlchemy model view.
</p>
<p>
This example shows how to manage spatial information in a GIS database.
</p>
<a
class=
"btn btn-primary"
href=
"/"
><i
class=
"icon-arrow-left icon-white"
></i>
Back
</a>
</div>
</div>
{% endblock body %}
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