def chemcsv(request): ''' Generates csv representation of ar5 chemistry table ''' #get date for csv file title now = datetime.datetime.now() filename = 'ar5csv_chem_%d_%d_%d.csv' % (now.day, now.month, now.year) # Create the HttpResponse object with the appropriate CSV header. response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=%s' % filename #----- Ch 09 (Models) ----- #get real models models = getModels(pubonly=True) #generate information for ar5 chemistry chemtableinfo = chemtable(models) writer = csv.writer(response) #write column headings writer.writerow(['Model ID', 'Institution', 'Land Surface Carbon Cycle implemented?', 'Ocean Bio Chemistry (Carbon Cycle) implemented?', 'Aerosol Scheme Type', 'Prognostic aerosol treatment', 'List of nutrient species', ]) #write out each row of information in turn for row in chemtableinfo: writer.writerow([row.abbrev, row.centre.name, row.lsccimplemented, row.occimplemented, row.aerscheme, row.aermoments, row.ocbiotracnuts, ]) return response
def chem(request): ''' Generates information for the 'chemistry' AR5 table ''' #get real models models = getModels(pubonly=True) #generate information for ar5 chem table chemtableinfo = chemtable(models) # set up my urls ... urls = {} urls['home'] = reverse('cmip5q.explorer.views_ar5.home', args=()) urls['chemcsv'] = reverse('cmip5q.explorer.views_ar5.chemcsv', args=()) return render_to_response('explorer/ar5/chemtable.html', {'chemtable': chemtableinfo, 'urls': urls})