def test_writerow_unicode(self):
     fb_result = StringIO()
     fb_writer = UnicodeWriter(fb_result)
     try:
         fb_writer.writerow([u"\u2603"])
     except Exception as e:
         self.fail("Failed with exception %s" % e)
     self.assertEquals(fb_result.getvalue(), "\xe2\x98\x83\r\n")
 def test_writerow_unicode(self):
     fb_result = StringIO()
     fb_writer = UnicodeWriter(fb_result)
     try:
         fb_writer.writerow([u'\u2603'])
     except Exception as e:
         self.fail('Failed with exception %s' % e)
     self.assertEquals(fb_result.getvalue(), '\xe2\x98\x83\r\n')
Exemplo n.º 3
0
 def export_csv(self, request, queryset):
     fields = self.csv_fields or self.fields or fields_for_model(self.model).keys()
     response = HttpResponse(mimetype='text/csv')
     response['Content-Disposition'] = ('attachment; filename=%s.csv'
                                        % self.model._meta.db_table)
     writer = UnicodeWriter(response)
     writer.writerow(fields)
     for obj in queryset.all():
         writer.writerow([self.get_csvable_value(obj, field)
                          for field in fields])
     return response
 def test_writerow_float(self):
     fb_result = StringIO()
     csv_result = StringIO()
     fb_writer = UnicodeWriter(fb_result)
     csv_writer = csv.writer(csv_result)
     csv_writer.writerow([1.1])
     try:
         fb_writer.writerow([1.1])
     except Exception as e:
         self.fail("Failed with exception %s" % e)
     self.assertEquals(fb_result.getvalue(), csv_result.getvalue())
 def test_writerow_float(self):
     fb_result = StringIO()
     csv_result = StringIO()
     fb_writer = UnicodeWriter(fb_result)
     csv_writer = csv.writer(csv_result)
     csv_writer.writerow([1.1])
     try:
         fb_writer.writerow([1.1])
     except Exception as e:
         self.fail('Failed with exception %s' % e)
     self.assertEquals(fb_result.getvalue(), csv_result.getvalue())
Exemplo n.º 6
0
 def export_csv(self, request, queryset):
     fields = self.csv_fields or self.fields or fields_for_model(
         self.model).keys()
     response = HttpResponse(mimetype='text/csv')
     response['Content-Disposition'] = ('attachment; filename=%s.csv' %
                                        self.model._meta.db_table)
     writer = UnicodeWriter(response)
     writer.writerow(fields)
     for obj in queryset.all():
         writer.writerow(
             [self.get_csvable_value(obj, field) for field in fields])
     return response