Package madrona :: Package studyregion :: Module views
[hide private]

Source Code for Module madrona.studyregion.views

 1  from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest, HttpResponseServerError, HttpResponseForbidden 
 2  from django.template import RequestContext 
 3  from django.shortcuts import get_object_or_404, render_to_response 
 4  from madrona.common import default_mimetypes as mimetypes 
 5  from madrona.common.utils import KmlWrap 
 6  from django.core.urlresolvers import reverse 
 7   
 8  from django.conf import settings 
 9   
10  from madrona.studyregion import models 
11  from django.views.decorators.cache import cache_page 
12 13 -def studyregion(request, template_name='studyregion/studyregion.html'):
14 """Main application window 15 """ 16 return render_to_response(template_name, RequestContext(request,{'api_key':settings.GOOGLE_API_KEY}))
17
18 -def show(request, pk):
19 """Display a map with the study region geometry. 20 """ 21 return render_to_response('studyregion/show.html', RequestContext(request,{'api_key':settings.GOOGLE_API_KEY, 'pk': pk}))
22
23 -def kml(request, pk):
24 """Return kml for the requested StudyRegion 25 """ 26 region = get_object_or_404(models.StudyRegion, pk=pk) 27 return HttpResponse(KmlWrap(region.kml(request.get_host())), content_type=mimetypes.KML)
28
29 @cache_page(60 * 60 * 24) 30 -def regionKml(request):
31 """Handler for AJAX regionKml request 32 """ 33 region = models.StudyRegion.objects.current() 34 35 return HttpResponse(KmlWrap(region.kml(request.get_host())), content_type=mimetypes.KML)
36
37 38 -def regionKmlChunk(request, n, s, e, w):
39 """Handler for AJAX regionKml request 40 """ 41 region = models.StudyRegion.objects.current() 42 43 return HttpResponse( 44 KmlWrap('<Document>' + region.kml_chunk(float(n), float(s), float(e), float(w)) + '</Document>'), content_type=mimetypes.KML)
45
46 47 -def regionLookAtKml(request):
48 """Handler for AJAX regionLookAtKml request 49 """ 50 region = models.StudyRegion.objects.current() 51 52 return HttpResponse(KmlWrap('<Document>' + region.lookAtKml() + '</Document>'), content_type=mimetypes.KML)
53