def test_humanize(self): """Test that fields get converted to human-readable equivalents.""" data = helpers.humanize(helpers.serialize("python", self.records)) for record in data: # ensure tags were converted self.assertEqual(record["tags"], "test, stuff, working") # ensure contact type was converted self.assertTrue(record["contact_type"] == "Email")
def test_humanize(self): """Test that fields get converted to human-readable equivalents.""" data = helpers.humanize(helpers.serialize('python', self.records)) for record in data: # ensure tags were converted self.assertEqual(record['tags'], 'test, stuff, working') # ensure communication type was converted self.assertTrue(record['contact_type'] == 'Email')
def download_report(request): """ Download report as CSV. Query String Parameters: :id: ID of the report to download :values: Fields to include in the resulting CSV, as well as the order in which to include them. :order_by: The sort order for the resulting CSV. Outputs: The report with the specified options rendered as a CSV file. """ report_id = request.GET.get('id', 0) values = request.GET.getlist('values', None) order_by = request.GET.get('order_by', None) report = get_object_or_404( get_model('myreports', 'report'), pk=report_id) if order_by: report.order_by = order_by report.save() if values: report.values = json.dumps(values) report.save() records = humanize(report.python) response = HttpResponse(content_type='text/csv') content_disposition = "attachment; filename=%s-%s.csv" response['Content-Disposition'] = content_disposition % ( report.name.replace(' ', '_'), report.pk) response.write(serialize('csv', records, values=values, order_by=order_by)) return response