Skip to content

Commit

Permalink
Added django-leaflet widget to GeoModelAdmin #152
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Sep 28, 2014
1 parent a74cf48 commit fecbb3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
13 changes: 13 additions & 0 deletions nodeshot/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
# 3d parthy django apps
'rest_framework',
'rest_framework_swagger',
'leaflet',
'south',
'smuggler',
'reversion',
Expand Down Expand Up @@ -325,3 +326,15 @@
LOGIN_URL = '/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL = '/'

# ------ DJANGO-LEAFLET SETTINGS ------ #

LEAFLET_CONFIG = {
'DEFAULT_CENTER': (49.06775, 30.62011),
'DEFAULT_ZOOM': 4,
'MIN_ZOOM': 1,
'MAX_ZOOM': 18,
'TILES': 'http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png',
'ATTRIBUTION_PREFIX': '<a href="http://github.com/ninuxorg/nodeshot">Nodeshot</a> - Maps thank to <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
'RESET_VIEW': False
}
31 changes: 1 addition & 30 deletions nodeshot/core/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,8 @@
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.contrib.gis.admin import ModelAdmin as GeoModelAdmin

# TODO these settings at the moment are not being used
from .settings import ADMIN_MAP_COORDINATES, ADMIN_MAP_ZOOM


def _get_geodjango_map_coords():
""" point to be used by geodjango """
try:
lat, lng = ADMIN_MAP_COORDINATES
except KeyError:
raise ImproperlyConfigured("incorrect NODESHOT_ADMIN_MAP_COORDINATES setting")
return lat, lng


def _get_geodjango_map_zoom():
""" zoom level to be used by geodjango """
try:
return ADMIN_MAP_ZOOM
except KeyError:
raise ImproperlyConfigured("incorrect NODESHOT_ADMIN_MAP_ZOOM setting")
from leaflet.admin import LeafletGeoAdmin as GeoModelAdmin


class BaseAdmin(admin.ModelAdmin):
Expand All @@ -50,20 +31,10 @@ def formfield_for_dbfield(self, db_field, **kwargs):
return field


class GeoForm(forms.ModelForm):
# TODO entirely configurable
geometry = forms.GeometryField(widget=forms.OSMWidget(attrs={
'map_width': 758,
'map_height': 500,
'display_raw': settings.DEBUG
}))


class BaseGeoAdmin(BaseAdmin, GeoModelAdmin):
"""
BaseAdmin + Geodjango support
"""
form = GeoForm


class PublishActionsAdminMixin(object):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ requests
# better admin
django-grappelli==2.5.3
django-filebrowser==3.5.6
django-leaflet==0.14.1

# RESTful API and API documentation
djangorestframework==2.4.3
Expand Down

0 comments on commit fecbb3b

Please sign in to comment.