Skip to content

Commit 3e0970c

Browse files
committed
Try to make django-leaflet work without libgeos
1 parent 9dba074 commit 3e0970c

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

leaflet/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
GeoJSONField = type(object)
1010
try:
1111
from django.contrib.gis.db.models import GeometryField
12-
from .forms.widgets import LeafletWidget
1312
except ImportError:
1413
GeometryField = type(object)
15-
from django.forms.widgets import Textarea as LeafletWidget
14+
15+
from .forms.widgets import LeafletWidget
1616

1717

1818
class LeafletGeoAdmin(ModelAdmin):

leaflet/forms/backport.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
from django.conf import settings
3636
from django.contrib.gis import gdal
37-
from django.contrib.gis.geos import GEOSGeometry, GEOSException
3837
from django.forms.widgets import Widget
3938
from django.template import loader
4039
from django.utils import six
@@ -43,6 +42,16 @@
4342
from django.utils.translation import ugettext_lazy as _
4443
from django.core import validators
4544

45+
try:
46+
from django.contrib.gis.geos import GEOSGeometry
47+
except ImportError:
48+
from .nogeos import GEOSGeometry
49+
50+
try:
51+
from django.contrib.gis.geos import GEOSException
52+
except ImportError:
53+
from .nogeos import GEOSException
54+
4655
logger = logging.getLogger('django.contrib.gis')
4756

4857

leaflet/forms/nogeos.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
class GEOSGeometry(object):
5+
"""
6+
A simple mock of django.contrib.gis.geos.GEOSGeometry to make
7+
django-leaflet work with only django-geojson (without libgeos)
8+
"""
9+
def __init__(self, geo_input, srid=None):
10+
self.srid = srid
11+
self.geojson = geo_input
12+
return
13+
14+
15+
class GEOSException(Exception):
16+
pass

0 commit comments

Comments
 (0)