import csv
from django.http import HttpResponse
+from django.utils.translation import ugettext_lazy as _
try:
unicode
str = unicode
-def export_as_csv_action(description="Export selected objects as CSV file", fields=None, exclude=None, header=True):
+def export_as_csv_action(description=_("Export selected objects as CSV file"), fields=None, exclude=None, header=True):
"""
This function returns an export csv action
'fields' and 'exclude' work like in django ModelForm
based on http://djangosnippets.org/snippets/1697/
"""
opts = modeladmin.model._meta
- field_names = [field.name for field in opts.fields]
+ field_names = fields or [field.name for field in opts.fields]
- if fields:
- for f in fields:
- if f not in field_names:
- field_names.append(f)
-
- elif exclude:
+ if exclude:
field_names = [f for f in field_names if f not in exclude]
response = HttpResponse(content_type='text/csv')
if header:
writer.writerow(field_names)
for obj in queryset:
- writer.writerow([str(getattr(obj, field)) for field in field_names])
+ row = []
+ for field in field_names:
+ value = getattr(obj, field)
+ if callable(value):
+ value = value()
+ row.append(str(value))
+ writer.writerow(row)
return response
#
msgid ""
msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
+"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-10-10 14:32+0200\n"
-"PO-Revision-Date: 2012-10-10 14:33+0100\n"
+"POT-Creation-Date: 2020-03-26 14:36+0100\n"
+"PO-Revision-Date: 2020-03-26 14:36+0100\n"
"Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"Language: \n"
+"Language: pl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+"Language-Team: \n"
+"X-Generator: Poedit 2.2.4\n"
-#: templates/fnpdjango/share.html:5
-#: templates/fnpdjango/share.html.py:7
-msgid "Share on Facebook"
-msgstr "Podziel się na Facebooku"
-
-#: templates/fnpdjango/share.html:10
-#: templates/fnpdjango/share.html.py:12
-msgid "Share on Google+"
-msgstr "Podziel się na Google+"
-
-#: templates/fnpdjango/share.html:15
-#: templates/fnpdjango/share.html.py:17
-msgid "Share on Twitter"
-msgstr "Podziel się na Twitterze"
-
-#: templates/fnpdjango/share.html:20
-#: templates/fnpdjango/share.html.py:22
-msgid "Share on NK.pl"
-msgstr "Podziel się na NK.pl"
+#: actions.py:16
+msgid "Export selected objects as CSV file"
+msgstr "Eksportuj wybrane obiekty jako plik CSV"
#: templates/fnpdjango/prevnext/next.html:13
msgid "next"
msgid "previous"
msgstr "poprzednie"
+#: templates/fnpdjango/share.html:5 templates/fnpdjango/share.html:7
+msgid "Share on Facebook"
+msgstr "Podziel się na Facebooku"
+
+#: templates/fnpdjango/share.html:10 templates/fnpdjango/share.html:12
+msgid "Share on Google+"
+msgstr "Podziel się na Google+"
+
+#: templates/fnpdjango/share.html:15 templates/fnpdjango/share.html:17
+msgid "Share on Twitter"
+msgstr "Podziel się na Twitterze"
+
+#~ msgid "Share on NK.pl"
+#~ msgstr "Podziel się na NK.pl"