def list(request): if request.method == 'POST': taxon = request.POST.get('taxon') site = request.POST.get('site') submit_type = request.POST.get('submit') if submit_type == 'Download CSV': return download_csv(request, taxon, site) species_list = get_spp_list(taxon, site) else: species_list = [] site = None taxon = None sites = get_site_list() # Render list page with the documents and the form return render_to_response('list.html', { 'sites': sites, 'groups': groups, 'species_list': species_list, 'selected_site': site, 'selected_group': taxon }, context_instance=RequestContext(request))
def download_csv(request, taxon, site): species_list = get_spp_list(taxon, site) response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=%s.%s.csv' % (site, taxon) writer = csv.writer(response) writer.writerow(['site_id','spp_id','sci_name','com_name']) for species in species_list: writer.writerow((site,) + species) return response
def download_csv(request, taxon, site): species_list = get_spp_list(taxon, site) response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=%s.%s.csv' % ( site, taxon) writer = csv.writer(response) writer.writerow(['site_id', 'spp_id', 'sci_name', 'com_name']) for species in species_list: writer.writerow((site, ) + species) return response
def list(request): if request.method == 'POST': taxon = request.POST.get('taxon') site = request.POST.get('site') submit_type = request.POST.get('submit') if submit_type == 'Download CSV': return download_csv(request, taxon, site) species_list = get_spp_list(taxon, site) else: species_list = [] site = None taxon = None sites = get_site_list() # Render list page with the documents and the form return render_to_response( 'list.html', {'sites': sites, 'groups':groups, 'species_list': species_list, 'selected_site': site, 'selected_group': taxon}, context_instance=RequestContext(request) )