diff options
-rw-r--r-- | app/locations/admin.py | 3 | ||||
-rw-r--r-- | app/posts/admin.py | 21 | ||||
-rw-r--r-- | app/sightings/admin.py | 11 | ||||
-rw-r--r-- | app/utils/util.py | 6 | ||||
-rw-r--r-- | app/utils/widgets.py | 26 |
5 files changed, 39 insertions, 28 deletions
diff --git a/app/locations/admin.py b/app/locations/admin.py index 03f0696..03a51d9 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin +from django.contrib.gis.admin import GISModelAdmin from .models import Region, Country, Location, State, Route, LuxCheckIn, Campsite, GPXFile, GPXTrack, Track @@ -160,7 +161,7 @@ class StateAdmin(admin.ModelAdmin): @admin.register(Location) -class LocationAdmin(admin.ModelAdmin): +class LocationAdmin(OLAdminBase): list_display = ('name', 'pub_date', 'parent', 'state', 'slug') prepopulated_fields = {'slug': ('name',)} search_fields = ('name', 'state') diff --git a/app/posts/admin.py b/app/posts/admin.py index 5c27f64..96883f6 100644 --- a/app/posts/admin.py +++ b/app/posts/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin +from django.contrib.gis.admin import GISModelAdmin from django import forms from django.contrib.contenttypes.admin import GenericStackedInline @@ -10,7 +11,7 @@ from utils.util import get_latlon @admin.register(Post) -class PostAdmin(admin.ModelAdmin): +class PostAdmin(GISModelAdmin): form = LGEntryForm def get_queryset(self, request): @@ -76,15 +77,15 @@ class PostAdmin(admin.ModelAdmin): ) # options for OSM map Using custom ESRI topo map lat, lon = get_latlon() - default_lon = lon - default_lat = lat - default_zoom = 10 - units = True - scrollable = False - map_width = 700 - map_height = 425 - map_template = 'gis/admin/osm.html' - openlayers_url = '/static/admin/js/OpenLayers.js' + gis_widget_kwargs = { + "attrs": { + "default_lon": lon, + "default_lat": lat, + "default_zoom": 6, + "map_width": 700, + "map_height": 425, + } + } class Media: js = ('image-loader.js', 'next-prev-links.js') diff --git a/app/sightings/admin.py b/app/sightings/admin.py index e5e5aaf..681568d 100644 --- a/app/sightings/admin.py +++ b/app/sightings/admin.py @@ -106,15 +106,16 @@ class SightingAdmin(GISModelAdmin): autocomplete_fields = ["ap"] # options for OSM map Using custom ESRI topo map lat, lon = get_latlon() + print(lat, lon) gis_widget_kwargs = { "attrs": { "default_lon": lon, "default_lat": lat, - "default_zoom": 6, - "map_width": 700, - "map_height": 425, - "map_template": 'gis/admin/osm.html', - "openlayers_url": '/static/admin/js/OpenLayers.js' + "default_zoom": 13, + "map_width": 900, + "map_height": 625, + #"map_template": 'gis/admin/osm.html', + #"openlayers_url": '/static/admin/js/OpenLayers.js' } } diff --git a/app/utils/util.py b/app/utils/util.py index d9b2318..32a9838 100644 --- a/app/utils/util.py +++ b/app/utils/util.py @@ -36,8 +36,10 @@ def convertll(lat, lon): def get_latlon(): loc = apps.get_model('locations', 'LuxCheckIn').objects.latest() - lat_converted, lon_converted = convertll(loc.lat, loc.lon) - return lat_converted, lon_converted + # as of django 5, this isn't necessary anymore: + #lat_converted, lon_converted = convertll(loc.lat, loc.lon) + lat, lon = loc.point.y, loc.point.x + return lat, lon def extract_main_image(markdown): diff --git a/app/utils/widgets.py b/app/utils/widgets.py index 61f1722..897d428 100644 --- a/app/utils/widgets.py +++ b/app/utils/widgets.py @@ -1,6 +1,8 @@ import os from django import forms from django.contrib import admin + +from django.contrib.gis.admin import GISModelAdmin from django.contrib.admin.widgets import AdminFileWidget from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ @@ -13,6 +15,7 @@ import markdown from bs4 import BeautifulSoup from django.utils.module_loading import import_string +from utils.util import get_latlon class CustomSelectMultiple(SelectMultiple): @@ -129,15 +132,18 @@ class LGEntryFormSmall(forms.ModelForm): } -class OLAdminBase(admin.ModelAdmin): - default_lon = -9285175 - default_lat = 4025046 - default_zoom = 15 - units = True - scrollable = False - map_width = 700 - map_height = 425 - map_template = 'gis/admin/osm.html' - openlayers_url = '/static/admin/js/OpenLayers.js' +class OLAdminBase(GISModelAdmin): + lat, lon = get_latlon() + gis_widget_kwargs = { + "attrs": { + "default_lon": lon, + "default_lat": lat, + "default_zoom": 13, + "map_width": 900, + "map_height": 625, + #"map_template": 'gis/admin/osm.html', + #"openlayers_url": '/static/admin/js/OpenLayers.js' + } + } |