diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/blog/signals.py | 9 | ||||
-rw-r--r-- | apps/locations/admin.py | 55 | ||||
-rw-r--r-- | apps/locations/models.py | 19 | ||||
-rw-r--r-- | apps/locations/urls.py | 2 | ||||
-rw-r--r-- | apps/locations/views.py | 24 | ||||
-rw-r--r-- | apps/photos/views.py | 2 |
6 files changed, 99 insertions, 12 deletions
diff --git a/apps/blog/signals.py b/apps/blog/signals.py index 9809f6f..23e6d3f 100644 --- a/apps/blog/signals.py +++ b/apps/blog/signals.py @@ -3,7 +3,7 @@ from django.conf import settings from django.template import Context from django.db.models import get_model -from locations.models import Region,Country +from locations.models import Region,Country,Route def update_recent(sender, instance, signal, *args, **kwargs): # Update recent entries static file @@ -20,13 +20,14 @@ def update_recent(sender, instance, signal, *args, **kwargs): qs = model.objects.filter(status__exact=1) cl = Country.objects.filter(visited=True).exclude(name='default') rl = Region.objects.all() - c = Context({'object_list':qs, 'country_list':cl,'region_list':rl}) + rtl = Route.objects.all() + c = Context({'object_list':qs, 'country_list':cl,'region_list':rl, 'route_list':rtl}) t = render_to_string('includes/map_entry_list_template.html',c) - fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/map_entry_list.html') + fpath = '%s%s' %(settings.PROJ_ROOT,'media/js/mainmap.js') file = codecs.open(fpath, 'w','utf8') file.write(t) file.close() - c = Context({'country_list':cl,'region_list':rl}) + c = Context({'country_list':cl,'region_list':rl,'route_list':rtl}) t = render_to_string('includes/map_sidebar_template.html',c) fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/map_sidebar.html') file = codecs.open(fpath, 'w','utf8') diff --git a/apps/locations/admin.py b/apps/locations/admin.py index 77d1bb3..a23ef28 100644 --- a/apps/locations/admin.py +++ b/apps/locations/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin from django.contrib.gis.admin import OSMGeoAdmin -from locations.models import Region,Country,Location,State +from locations.models import Region,Country,Location,State,Route from django.contrib import databrowse from django.contrib.gis.maps.google import GoogleMap from django.conf import settings @@ -240,3 +240,56 @@ class LocationAdmin(OSMGeoAdmin): # associating the Options with the actual model admin.site.register(Location,LocationAdmin) +class RouteAdmin(OSMGeoAdmin): + # Standard Django Admin Options + list_display = ('name','slug',) + prepopulated_fields = {'slug': ('name',)} + search_fields = ('name',) + ordering = ('name',) + save_as = True + 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')}), + ) + 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 + 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) + diff --git a/apps/locations/models.py b/apps/locations/models.py index 47c5d65..e088697 100644 --- a/apps/locations/models.py +++ b/apps/locations/models.py @@ -159,6 +159,25 @@ class Location(models.Model): def __unicode__(self): return self.name +class Route(models.Model): + 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) + # 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 + + + class WritingbyLocationSitemap(Sitemap): changefreq = "weekly" priority = 0.6 diff --git a/apps/locations/urls.py b/apps/locations/urls.py index 2cad114..c49e684 100644 --- a/apps/locations/urls.py +++ b/apps/locations/urls.py @@ -2,6 +2,6 @@ from django.conf.urls.defaults import * from django.views.generic.simple import redirect_to,direct_to_template urlpatterns = patterns('', - #(r'(?P<slug>[0-9a-zA-Z_.-]+)/$', 'locations.views.list_view_region'), + (r'data/(?P<id>\d+)/$', 'locations.views.data_json'), (r'^$', direct_to_template, {'template': 'archives/map.html'}), ) diff --git a/apps/locations/views.py b/apps/locations/views.py index a59a2e5..f360429 100644 --- a/apps/locations/views.py +++ b/apps/locations/views.py @@ -2,10 +2,24 @@ 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 +from locations.models import Location, Country, Region, Route def list_view(request): - qs = Entry.objects.filter(status__exact=1) - cl = Country.objects.filter(visited=True).exclude(name='default') - rl = Region.objects.all() - return render_to_response('archives/map.html', {'object_list': qs,'country_list':cl,'region_list':rl}, context_instance=RequestContext(request))
\ No newline at end of file + context = { + 'object_list' : Entry.objects.filter(status__exact=1), + 'country_list' : Country.objects.filter(visited=True).exclude(name='default'), + 'region_list' : Region.objects.all() + } + return render_to_response('archives/map.html', context, context_instance=RequestContext(request)) + +from projects.shortcuts import render_to_geojson + +def data_json(request, id): + qs = Route.objects.filter(pk=id) + return render_to_geojson( + qs, + included_fields=['id',], + geom_attribute='geometry', + mimetype = 'application/json', + pretty_print=True + )
\ No newline at end of file diff --git a/apps/photos/views.py b/apps/photos/views.py index 861f00e..a1e3459 100644 --- a/apps/photos/views.py +++ b/apps/photos/views.py @@ -26,7 +26,7 @@ def gallery(request,slug): context = { 'object': PhotoGallery.objects.get(set_slug=slug) } - render_to_response('details/photo_galleries.html', context, context_instance = RequestContext(request)) + return render_to_response('details/photo_galleries.html', context, context_instance = RequestContext(request)) def photo_json(request, slug): p = PhotoGallery.objects.filter(set_slug=slug) |