From: Radek Czajka Date: Thu, 26 Mar 2020 13:37:19 +0000 (+0100) Subject: Fix for CSV export. X-Git-Tag: 0.4.5 X-Git-Url: https://git.mdrn.pl/fnpdjango.git/commitdiff_plain/465ee0b4cfa68b5d7e1bd8c8752e69a0f6783215?hp=c7680f63416bfb4e05c97d024e767ab7501c944d Fix for CSV export. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index dac26e0..3ec1475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ This document records all notable changes to fnpdjango. -## 0.4.4 (2020-03-26) +## 0.4.5 (2020-03-26) - Support for Django up do 3.0. - Added `actions.export_as_csv_action`. diff --git a/fnpdjango/actions.py b/fnpdjango/actions.py index ec0479e..1e1316a 100644 --- a/fnpdjango/actions.py +++ b/fnpdjango/actions.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import csv from django.http import HttpResponse +from django.utils.translation import ugettext_lazy as _ try: unicode @@ -12,7 +13,7 @@ else: 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 @@ -24,14 +25,9 @@ def export_as_csv_action(description="Export selected objects as CSV file", fiel 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') @@ -42,7 +38,13 @@ def export_as_csv_action(description="Export selected objects as CSV file", fiel 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 diff --git a/fnpdjango/locale/pl/LC_MESSAGES/django.mo b/fnpdjango/locale/pl/LC_MESSAGES/django.mo index 6e5d1fc..53bc202 100644 Binary files a/fnpdjango/locale/pl/LC_MESSAGES/django.mo and b/fnpdjango/locale/pl/LC_MESSAGES/django.mo differ diff --git a/fnpdjango/locale/pl/LC_MESSAGES/django.po b/fnpdjango/locale/pl/LC_MESSAGES/django.po index b43c1ce..bfc8b2a 100644 --- a/fnpdjango/locale/pl/LC_MESSAGES/django.po +++ b/fnpdjango/locale/pl/LC_MESSAGES/django.po @@ -5,37 +5,23 @@ # 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 \n" -"Language-Team: LANGUAGE \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" @@ -45,3 +31,17 @@ msgstr "następne" 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" diff --git a/setup.py b/setup.py index 7b77c83..1a392f1 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def whole_trees(package_dir, paths): setup( name='fnpdjango', - version='0.4.4', + version='0.4.5', author='Radek Czajka', author_email='radekczajka@nowoczesnapolska.org.pl', url='',