diff options
Diffstat (limited to 'app/locations')
-rw-r--r-- | app/locations/admin.py | 401 | ||||
-rw-r--r--[-rwxr-xr-x] | app/locations/models.py | 126 | ||||
-rw-r--r-- | app/locations/urls.py | 2 | ||||
-rw-r--r-- | app/locations/views.py | 43 |
4 files changed, 241 insertions, 331 deletions
diff --git a/app/locations/admin.py b/app/locations/admin.py index 5e6106b..6d971f1 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -1,297 +1,232 @@ from django.contrib import admin from django.contrib.gis.admin import OSMGeoAdmin -from locations.models import Region,Country,Location,State,Route - -from django.contrib.gis.maps.google import GoogleMap +from locations.models import Region, Country, Location, State, Route from django.conf import settings -GMAP = GoogleMap(key=settings.GOOGLE_MAPS_API_KEY) - class RegionAdmin(OSMGeoAdmin): - # Standard Django Admin Options - list_display = ('name','slug') + list_display = ('name', 'slug') prepopulated_fields = {'slug': ('name',)} search_fields = ('name',) ordering = ('name',) save_as = True - search_fields = ['name',] + search_fields = ['name'] list_select_related = True fieldsets = ( - ('Region', {'fields': ('name','slug','pub_date'), 'classes': ('show','extrapretty')}), - ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), + ('Region', { + 'fields': ( + 'name', + 'slug', + 'pub_date' + ), + 'classes': ( + 'show', + 'extrapretty' + ) + } + ), + ('Editable Map View', { + 'fields': ( + 'geometry', + ), + 'classes': ( + 'show', + 'wide' + ) + } + ), ) - extra_js = [GMAP.api_url + GMAP.key] - map_template = 'gis/admin/google.html' - # Default GeoDjango OpenLayers map options - # Uncomment and modify as desired - # To learn more about this jargon visit: - # www.openlayers.org - - #default_lon = 0 - #default_lat = 0 - #default_zoom = 4 - #display_wkt = False - #display_srid = False - #extra_js = [] - #num_zoom = 18 - #max_zoom = False - #min_zoom = False - #units = False - #max_resolution = False - #max_extent = False - #modifiable = True - #mouse_position = True - #scale_text = True - #layerswitcher = True + + # options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True scrollable = False - #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX map_width = 700 - map_height = 325 - #map_srid = 4326 - #map_template = 'gis/admin/openlayers.html' - #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js' - #wms_url = 'http://labs.metacarta.com/wms/vmap0' - #wms_layer = 'basic' - #wms_name = 'OpenLayers WMS' - #debug = False - #widget = OpenLayersWidget + map_height = 425 + map_template = 'gis/admin/osm.html' + +admin.site.register(Region, RegionAdmin) -# Finally, with these options set now register the model -# associating the Options with the actual model -admin.site.register(Region,RegionAdmin) class CountryAdmin(OSMGeoAdmin): - """ - # Standard Django Admin Options - list_display = ('name','slug','region') - prepopulated_fields = {'slug': ('name',)} - search_fields = ('name',) - ordering = ('name',) - save_as = True - search_fields = ['name',] - list_select_related = True - fieldsets = ( - ('Country', {'fields': ('name','slug','abbr','region','pub_date'), 'classes': ('show','extrapretty')}), - ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), - ) - """ - - # Standard Django Admin Options - list_display = ('name','pop2005','region','subregion',) + list_display = ('name', 'pop2005', 'region', 'subregion') search_fields = ('name',) ordering = ('name',) - list_filter = ('visited','region','subregion',) + list_filter = ('visited', 'region', 'subregion') save_as = True - search_fields = ['name','iso2','iso3','subregion','region'] + search_fields = ['name', 'iso2', 'iso3', 'subregion', 'region'] list_select_related = True fieldsets = ( - ('Country Attributes', {'fields': (('name','pop2005','slug','zoom_level','visited')), 'classes': ('show','extrapretty')}), - ('Country Codes', {'fields': ('region','subregion','iso2','iso3','un',), 'classes': ('collapse',)}), - ('Area and Coordinates', {'fields': ('area','lat','lon',), 'classes': ('collapse', 'wide')}), - ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), + ('Country Attributes', + {'fields': ( + 'name', + 'pop2005', + 'slug', + 'zoom_level', + 'visited' + ), + 'classes': ( + 'show', + 'extrapretty' + ) + } + ), + ('Country Codes', + {'fields': ( + 'region', + 'subregion', + 'iso2', + 'iso3', + 'un', + ), + 'classes': ('collapse',) + } + ), + ('Area and Coordinates', + {'fields': ( + 'area', + 'lat', + 'lon', + ), + 'classes': ('collapse', 'wide') + } + ), + ('Editable Map View', + {'fields': ('geometry',), + 'classes': ('show', 'wide') + } + ), ) - extra_js = [GMAP.api_url + GMAP.key] - map_template = 'gis/admin/google.html' - # Default GeoDjango OpenLayers map options - # Uncomment and modify as desired - # To learn more about this jargon visit: - # www.openlayers.org - - #default_lon = 0 - #default_lat = 0 - #default_zoom = 4 - #display_wkt = False - #display_srid = False - #extra_js = [] - #num_zoom = 18 - #max_zoom = False - #min_zoom = False - #units = False - #max_resolution = False - #max_extent = False - #modifiable = True - #mouse_position = True - #scale_text = True - #layerswitcher = True + # Options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True scrollable = False - #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX map_width = 700 - map_height = 325 - #map_srid = 4326 - #map_template = 'gis/admin/openlayers.html' - #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js' - #wms_url = 'http://labs.metacarta.com/wms/vmap0' - #wms_layer = 'basic' - #wms_name = 'OpenLayers WMS' - #debug = False - #widget = OpenLayersWidget + map_height = 425 + map_template = 'gis/admin/osm.html' -# Finally, with these options set now register the model -# associating the Options with the actual model -admin.site.register(Country,CountryAdmin) +admin.site.register(Country, CountryAdmin) class StateAdmin(OSMGeoAdmin): - # Standard Django Admin Options - list_display = ('name','code','slug','country') + list_display = ('name', 'code', 'slug', 'country') prepopulated_fields = {'slug': ('name',)} - search_fields = ('name','country') + search_fields = ('name', 'country') ordering = ('name',) save_as = True - search_fields = ['name',] + search_fields = ['name'] list_select_related = True fieldsets = ( - ('Location', {'fields': ('name','slug','code','pub_date','country'), 'classes': ('show','extrapretty')}), - ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), + ('Location', + {'fields': ( + 'name', + 'slug', + 'code', + 'pub_date', + 'country' + ), + 'classes': ('show', 'extrapretty') + } + ), + ('Editable Map View', + {'fields': ('geometry',), + 'classes': ('show', 'wide') + } + ), ) - extra_js = [GMAP.api_url + GMAP.key] - map_template = 'gis/admin/google.html' - # Default GeoDjango OpenLayers map options - # Uncomment and modify as desired - # To learn more about this jargon visit: - # www.openlayers.org - - #default_lon = 0 - #default_lat = 0 - #default_zoom = 4 - #display_wkt = False - #display_srid = False - #extra_js = [] - #num_zoom = 18 - #max_zoom = False - #min_zoom = False - #units = False - #max_resolution = False - #max_extent = False - #modifiable = True - #mouse_position = True - #scale_text = True - #layerswitcher = True + + # Options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True scrollable = False - #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX map_width = 700 - map_height = 325 - #map_srid = 4326 - #map_template = 'gis/admin/openlayers.html' - #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js' - #wms_url = 'http://labs.metacarta.com/wms/vmap0' - #wms_layer = 'basic' - #wms_name = 'OpenLayers WMS' - #debug = False - #widget = OpenLayersWidget + map_height = 425 + map_template = 'gis/admin/osm.html' + +admin.site.register(State, StateAdmin) -# Finally, with these options set now register the model -# associating the Options with the actual model -admin.site.register(State,StateAdmin) class LocationAdmin(OSMGeoAdmin): - # Standard Django Admin Options - list_display = ('name','slug','state') + list_display = ('name', 'slug', 'state') prepopulated_fields = {'slug': ('name',)} - search_fields = ('name','state') + search_fields = ('name', 'state') ordering = ('name',) save_as = True - search_fields = ['name',] + search_fields = ['name'] list_select_related = True fieldsets = ( - ('Location', {'fields': ('name','slug','pub_date','state'), 'classes': ('show','extrapretty')}), - ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), + ('Location', + {'fields': ( + 'name', + 'slug', + 'pub_date', + 'state' + ), + 'classes': ('show', 'extrapretty') + } + ), + ('Editable Map View', + {'fields': ('geometry',), + 'classes': ('show', 'wide') + } + ), ) - extra_js = [GMAP.api_url + GMAP.key] - map_template = 'gis/admin/google.html' - # Default GeoDjango OpenLayers map options - # Uncomment and modify as desired - # To learn more about this jargon visit: - # www.openlayers.org - - #default_lon = 0 - #default_lat = 0 - #default_zoom = 4 - #display_wkt = False - #display_srid = False - #extra_js = [] - #num_zoom = 18 - #max_zoom = False - #min_zoom = False - #units = False - #max_resolution = False - #max_extent = False - #modifiable = True - #mouse_position = True - #scale_text = True - #layerswitcher = True + # options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True scrollable = False - #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX map_width = 700 - map_height = 325 - #map_srid = 4326 - #map_template = 'gis/admin/openlayers.html' - #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js' - #wms_url = 'http://labs.metacarta.com/wms/vmap0' - #wms_layer = 'basic' - #wms_name = 'OpenLayers WMS' - #debug = False - #widget = OpenLayersWidget + map_height = 425 + map_template = 'gis/admin/osm.html' + +admin.site.register(Location, LocationAdmin) -# Finally, with these options set now register the model -# associating the Options with the actual model -admin.site.register(Location,LocationAdmin) class RouteAdmin(OSMGeoAdmin): - # Standard Django Admin Options - list_display = ('name','slug',) + list_display = ('name', 'slug') prepopulated_fields = {'slug': ('name',)} search_fields = ('name',) ordering = ('name',) save_as = True - search_fields = ['name',] + search_fields = ['name'] list_select_related = True fieldsets = ( - ('Location', {'fields': ('name','slug','pub_date','template_var_name','zoom'), 'classes': ('show','extrapretty')}), - ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), + ('Location', + {'fields': ( + 'name', + 'slug', + 'pub_date', + 'template_var_name', + 'zoom' + ), + 'classes': ('show', 'extrapretty') + } + ), + ('Editable Map View', + {'fields': ('geometry',), + 'classes': ('show', 'wide') + } + ), ) - extra_js = [GMAP.api_url + GMAP.key] - map_template = 'gis/admin/google.html' - # Default GeoDjango OpenLayers map options - # Uncomment and modify as desired - # To learn more about this jargon visit: - # www.openlayers.org - - #default_lon = 0 - #default_lat = 0 - #default_zoom = 4 - #display_wkt = False - #display_srid = False - #extra_js = [] - #num_zoom = 18 - #max_zoom = False - #min_zoom = False - #units = False - #max_resolution = False - #max_extent = False - #modifiable = True - #mouse_position = True - #scale_text = True - #layerswitcher = True + + # options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True scrollable = False - #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX map_width = 700 - map_height = 325 - #map_srid = 4326 - #map_template = 'gis/admin/openlayers.html' - #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js' - #wms_url = 'http://labs.metacarta.com/wms/vmap0' - #wms_layer = 'basic' - #wms_name = 'OpenLayers WMS' - #debug = False - #widget = OpenLayersWidget - -# Finally, with these options set now register the model -# associating the Options with the actual model -admin.site.register(Route,RouteAdmin) - - + map_height = 425 + map_template = 'gis/admin/osm.html' +admin.site.register(Route, RouteAdmin) diff --git a/app/locations/models.py b/app/locations/models.py index e088697..ac8ec44 100755..100644 --- a/app/locations/models.py +++ b/app/locations/models.py @@ -1,66 +1,38 @@ -# -*- coding: utf-8 -*- -# models.py - -# All standard Django fields as well as GeoDjango geometry fields and the GeoManager() can be -# imported from django.contrib.gis.db after adding django.contrib.gis to INSTALLED_APPS from django.contrib.gis.db import models from django.contrib.sitemaps import Sitemap -# Used to display html 'help text' links within Admin App from django.utils.safestring import mark_safe + class Region(models.Model): - name = models.CharField(max_length=50, ) + """Model to define arbitrary regions based on where I've been""" + name = models.CharField(max_length=50) slug = models.SlugField() - pub_date = models.DateTimeField('Date published',null=True) + pub_date = models.DateTimeField('Date published', null=True) # GeoDjango specific Polygon Field and GeoManager geometry = models.MultiPolygonField(srid=4326, null=True) - lon = models.FloatField('Longitude',help_text="Longitude of centerpoint",null=True) - lat = models.FloatField('Latitude',help_text="Latitude of centerpoint",null=True) - zoom_level = models.CharField(max_length=2,null=True) + lon = models.FloatField('Longitude', help_text="Longitude of centerpoint", null=True) + lat = models.FloatField('Latitude', help_text="Latitude of centerpoint", null=True) + zoom_level = models.CharField(max_length=2, null=True) # GeoManager, a subclass that adds a rich set of geospatial queryset methods objects = models.GeoManager() - + def get_absolute_url(self): return "/locations/region/%s/" % (self.slug) - - def __unicode__(self): return self.name - -# imported from django.contrib.gis.db -from django.contrib.gis.db import models + def __str__(self): + return self.name -# Used to display html 'help text' links within Admin App -from django.utils.safestring import mark_safe class Country(models.Model): """ - - A geographic model based on the v3 of the simplified world borders multipolygon shapefile - from http://thematicmapping.org/downloads/world_borders.php. - - Field names, Django types, and max_lengths were autogenerated using the ogrinspect utility with hand - edits to add alternative field names and help_text. - - Imported using LayerMapping (requires GDAL) called within the load_data.py script provided - within this sample project. - - All fields match the source dataset, an ESRI format shapefile made up of several related files: - .shp - holds the vector data that is to be stored in the MultiPolygonField field named'geometry'. - .shx - spatial index file for geometries stored in the .shp. - .dbf - database file for holding attribute data (can be opened in excel and open office). - .prj - contains the spatial reference information for the geometries stored in the .shp - - + A geographic model based on the v3 of the simplified world borders multipolygon shapefile from http://thematicmapping.org/downloads/world_borders.php. """ - - # Regular Django fields corresponding to the attributes in the - # world borders shapefile name = models.CharField(max_length=50) area = models.IntegerField(help_text="Area of Country in SQ meters") pop2005 = models.IntegerField('Population 2005') fips = models.CharField('FIPS Code', max_length=2, help_text=mark_safe('<a href="http://www.census.gov/geo/www/fips/fips.html">Federal Information Processing Standard Code</a>')) - iso2 = models.CharField('2 Digit ISO', max_length=2, help_text=mark_safe('<a href="http://www.iso.org/">International Organization for Standardization</a>' )) - iso3 = models.CharField('3 Digit ISO', max_length=3,help_text=mark_safe('<a href="http://www.iso.org/">International Organization for Standardization</a>' )) + iso2 = models.CharField('2 Digit ISO', max_length=2, help_text=mark_safe('<a href="http://www.iso.org/">International Organization for Standardization</a>')) + iso3 = models.CharField('3 Digit ISO', max_length=3, help_text=mark_safe('<a href="http://www.iso.org/">International Organization for Standardization</a>')) un = models.IntegerField('United Nations Code') REGION_CODES = ( (0, 'MISC'), @@ -95,96 +67,92 @@ class Country(models.Model): (154, 'Northern Europe'), (155, 'Western Europe'), ) - region = models.IntegerField('Region Code',choices=REGION_CODES) - subregion = models.IntegerField('Sub-Region Code',choices=SUBREGION_CODES) - lon = models.FloatField('Longitude',help_text="Longitude of centerpoint") - lat = models.FloatField('Latitude',help_text="Latitude of centerpoint") - zoom_level = models.CharField(max_length=2,null=True) + region = models.IntegerField('Region Code', choices=REGION_CODES) + subregion = models.IntegerField('Sub-Region Code', choices=SUBREGION_CODES) + lon = models.FloatField('Longitude', help_text="Longitude of centerpoint") + lat = models.FloatField('Latitude', help_text="Latitude of centerpoint") + zoom_level = models.CharField(max_length=2, null=True) slug = models.SlugField(null=True) visited = models.BooleanField(default=False) lux_region = models.ForeignKey(Region, null=True) - pub_date = models.DateTimeField('Date published',null=True) - # GeoDjango-specific: a geometry field (MultiPolygonField), and - # overriding the default manager with a GeoManager instance. - geometry = models.MultiPolygonField('Country Border',srid=4326) + pub_date = models.DateTimeField('Date published', null=True) + geometry = models.MultiPolygonField('Country Border', srid=4326) objects = models.GeoManager() - - # Returns the string representation of the model. - def __unicode__(self): - return self.name - class Meta: ordering = ['name'] verbose_name_plural = 'Countries' - + + def __str__(self): + return self.name + def get_absolute_url(self): return "/locations/%s/" % (self.slug) - + class State(models.Model): + """Model to hold state boundaries""" name = models.CharField(max_length=250, blank=True, null=True,) country = models.ForeignKey(Country) slug = models.SlugField() code = models.CharField(max_length=2, null=True, blank=True) - pub_date = models.DateTimeField('Date published',null=True) - geometry = models.MultiPolygonField(srid=4326,null=True) + pub_date = models.DateTimeField('Date published', null=True) + geometry = models.MultiPolygonField(srid=4326, null=True) objects = models.GeoManager() - + class Meta: ordering = ['name'] - - class Admin: - pass - - def __unicode__(self): - return "%s" %(self.name) + + def __str__(self): + return "%s" % (self.name) def get_absolute_url(self): return "/locations/%s/%s/" % (self.country.slug, self.slug) + class Location(models.Model): + """Model to hold location shapes as arbitrarily defined by me""" state = models.ForeignKey(State) name = models.CharField(max_length=50, ) slug = models.SlugField() - pub_date = models.DateTimeField('Date published',null=True) + pub_date = models.DateTimeField('Date published', null=True) # GeoDjango specific Polygon Field and GeoManager geometry = models.MultiPolygonField(srid=4326) # GeoManager, a subclass that adds a rich set of geospatial queryset methods objects = models.GeoManager() - + + def __str__(self): + return self.name + def get_absolute_url(self): return "/locations/%s/%s/%s/" % (self.state.country.slug, self.state.slug, self.slug) - - def __unicode__(self): return self.name class Route(models.Model): + """Model to hold routes for longer trips""" name = models.CharField(max_length=200) slug = models.SlugField() zoom = models.CharField(max_length=2, null=True) template_var_name = models.CharField(max_length=10, null=True) - pub_date = models.DateTimeField('Date published',null=True) + pub_date = models.DateTimeField('Date published', null=True) # GeoDjango specific Polygon Field and GeoManager geometry = models.MultiPointField(srid=4326) # GeoManager, a subclass that adds a rich set of geospatial queryset methods objects = models.GeoManager() - + def get_absolute_url(self): return "/locations/%s/%s/%s/" % (self.slug) - - def __unicode__(self): return self.name - + def __str__(self): + return self.name class WritingbyLocationSitemap(Sitemap): changefreq = "weekly" priority = 0.6 - + def location(): - return '/writing/%s/1/' %(self.slug) - + return '/writing/%s' % self.slug + def items(self): return Location.objects.all() - diff --git a/app/locations/urls.py b/app/locations/urls.py index 8bc86aa..c7ddb74 100644 --- a/app/locations/urls.py +++ b/app/locations/urls.py @@ -1,8 +1,6 @@ - from django.conf.urls import * urlpatterns = patterns('', (r'data/(?P<id>\d+)/$', 'locations.views.data_json'), (r'^$', 'locations.views.map_list'), ) - diff --git a/app/locations/views.py b/app/locations/views.py index 234d867..5ae1ef9 100644 --- a/app/locations/views.py +++ b/app/locations/views.py @@ -1,35 +1,44 @@ -from django.shortcuts import render_to_response,get_object_or_404 +from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext - from blog.models import Entry from locations.models import Location, Country, Region, Route +from projects.shortcuts import render_to_geojson + def map_list(request): context = { - 'object_list' : Entry.objects.filter(status__exact=1), - 'country_list' : Country.objects.filter(visited=True).exclude(name='default'), - 'route_list' : Route.objects.all(), - 'region_list' : Region.objects.all() + 'object_list': Entry.objects.filter(status__exact=1), + 'country_list': Country.objects.filter(visited=True).exclude(name='default'), + 'route_list': Route.objects.all(), + 'region_list': Region.objects.all() } - return render_to_response('archives/map.html', context, context_instance=RequestContext(request)) + return render_to_response( + 'archives/map.html', + context, + context_instance=RequestContext(request) + ) + def map_data(request): context = { - 'object_list' : Entry.objects.filter(status__exact=1), - 'route_list' : Route.objects.all(), - 'country_list' : Country.objects.filter(visited=True).exclude(name='default'), - 'region_list' : Region.objects.all() + 'object_list': Entry.objects.filter(status__exact=1), + 'route_list': Route.objects.all(), + 'country_list': Country.objects.filter(visited=True).exclude(name='default'), + 'region_list': Region.objects.all() } - return render_to_response('archives/map_data.html', context, context_instance=RequestContext(request)) - -from projects.shortcuts import render_to_geojson + return render_to_response( + 'archives/map_data.html', + context, + context_instance=RequestContext(request) + ) + def data_json(request, id): qs = Route.objects.filter(pk=id) return render_to_geojson( qs, - included_fields=['id',], + included_fields=['id', ], geom_attribute='geometry', - mimetype = 'application/json', + mimetype='application/json', pretty_print=True - ) + ) |