def note_map_kml(request, range=12): now = datetime.now(pytz.utc) yesterday = now - timedelta(seconds=3600 * range) objects = Note.get().objects.filter(show_on_map=True).filter(creation_time__lte=now).filter(creation_time__gte=yesterday) days = [] if objects: days.append({'date': now, 'notes': objects }) if days: kml_document = render_to_string( 'xgds_notes2/notes_placemark_document.kml', {'days': days}, ) return wrapKmlDjango(kml_document) return wrapKmlDjango("")
def sample_map_kml(request, range=12): now = datetime.now(pytz.utc) yesterday = now - timedelta(seconds=3600 * range) objects = SAMPLE_MODEL.get().objects.filter(collection_time__lte=now).filter(collection_time__gte=yesterday) days = [] if objects: days.append({'date': now, 'samples': objects }) if days: kml_document = render_to_string( 'xgds_sample/samples_placemark_document.kml', {'days': days, 'iconUrl': request.build_absolute_uri('/static/xgds_sample/images/sample_icon.png')}, ) return wrapKmlDjango(kml_document) return wrapKmlDjango("")
def getPlanIndexKml(request): out = StringIO() out.write('<Document>\n') plans = PLAN_MODEL.get().objects.filter(deleted=False) plans = list(reversed(sorted(plans, key=lambda plan: (plan.escapedName(),)))) for plan in plans: fname = '%s.kml' % plan.escapedName() relUrl = reverse('planner2_planExport', args=[plan.uuid, fname]) url = request.build_absolute_uri(relUrl) # print(url) out.write(""" <NetworkLink> <name>%(name)s</name> <visibility>0</visibility> <Link> <href>%(url)s</href> </Link> </NetworkLink> """ % dict(name=plan.escapedName(), url=url)) out.write('</Document>') return wrapKmlDjango(out.getvalue())