Skip to content

Commit 4ed91f0

Browse files
committed
fixes arteria#70
1 parent 6f284f3 commit 4ed91f0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

cmsplugin_contact_plus/actions.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import csv
1+
import csv
22
import six
33
from six import text_type
44

55
from django.http import HttpResponse
66

77

88
class LUT(object):
9-
9+
1010
def __init__(self):
1111
self.lut = []
12-
12+
1313
def add_field(self, field_name):
1414
""" """
1515
if field_name not in self.lut:
1616
self.lut.append(field_name)
17-
17+
1818
def get_idx(self, field_name):
1919
""" """
2020
return self.lut.index(field_name)
21-
22-
23-
21+
22+
23+
2424
def export_as_csv_action(description="Export selected objects as CSV file",
2525
fields=None, exclude=None, header=True, json_fields=None):
2626
"""
2727
This function returns an export csv action
2828
'fields' and 'exclude' work like in django ModelForm
2929
'header' is whether or not to output the column names as the first row
30-
30+
3131
json_fields will be exploaded to rows.
3232
"""
3333

@@ -50,7 +50,7 @@ def export_as_csv(modeladmin, request, queryset):
5050

5151
response = HttpResponse(content_type='text/csv')
5252
response['Content-Disposition'] = 'attachment; filename=%s.csv' % text_type(opts).replace('.', '_')
53-
53+
5454
writer = csv.writer(response)
5555
"""
5656
if header:
@@ -74,13 +74,13 @@ def export_as_csv(modeladmin, request, queryset):
7474
j = getattr(obj, field)
7575
for l in j:
7676
try:
77-
for k, v in l.iteritems():
77+
for k, v in l.items():
7878
lut.add_field(k)
7979
except AttributeError:
8080
pass
8181
else:
8282
lut.add_field(field)
83-
83+
8484
if header:
8585
writer.writerow(lut.lut)
8686
for obj in queryset:
@@ -89,7 +89,7 @@ def export_as_csv(modeladmin, request, queryset):
8989
if field in json_fields:
9090
j = getattr(obj, field)
9191
for l in j:
92-
for k, v in l.iteritems():
92+
for k, v in l.items():
9393
try:
9494
s = text_type(v)
9595
if six.PY2:
@@ -102,8 +102,8 @@ def export_as_csv(modeladmin, request, queryset):
102102
for field in many_to_many_field_names:
103103
row[lut.get_idx(field)] = text_type(getattr(obj, field).all())
104104
writer.writerow(row)
105-
106-
105+
106+
107107
return response
108108
export_as_csv.short_description = description
109-
return export_as_csv
109+
return export_as_csv

0 commit comments

Comments
 (0)