Version 0.4: Added action to export selected records master v0.4
authorPA Parent <paparent@paparent.me>
Tue, 10 Jul 2012 18:32:09 +0000 (14:32 -0400)
committerPA Parent <paparent@paparent.me>
Tue, 10 Jul 2012 18:32:09 +0000 (14:32 -0400)
CHANGES
auf/django/export/admin.py
setup.py

diff --git a/CHANGES b/CHANGES
index f6497b4..2d25aff 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,3 +15,8 @@ auf.django.export
 ---
 
 * New feature: Added Export to ODS
+
+0.4
+---
+
+* New feature: Added an action to export only selected records
index f3750dc..a129aad 100644 (file)
@@ -32,6 +32,7 @@ def txt(msg):
 
 class ExportAdmin(admin.ModelAdmin):
     change_list_template = 'admin/export/change_list.html'
+    actions = ['export_csv', 'export_ods']
 
     def changelist_view(self, request, extra_context=None):
         """
@@ -107,13 +108,14 @@ class ExportAdmin(admin.ModelAdmin):
 
         return export_fields
 
-    def export_ods(self, request):
+    def export_ods(self, request, queryset=None):
         """
         Generate HTTP response as ODS file from export_fields property.
         """
         export_fields = self.get_export_fields()
 
-        qs = self.queryset(request)
+        if queryset is None:
+            queryset = self.queryset(request)
 
         response = HttpResponse(mimetype='application/vnd.oasis.opendocument.spreadsheet')
         response['Content-Disposition'] = 'attachment; filename=%s.ods' % unicode(self.model._meta.verbose_name_plural)
@@ -136,7 +138,7 @@ class ExportAdmin(admin.ModelAdmin):
                 p = P(stylename = style, text = txt(item))
                 tc.addElement (p)
 
-        for o in qs:
+        for o in queryset:
             tr = TableRow ()
             table.addElement (tr)
 
@@ -154,13 +156,14 @@ class ExportAdmin(admin.ModelAdmin):
         response.write(buffer.getvalue())
         return response
 
-    def export_csv(self, request):
+    def export_csv(self, request, queryset=None):
         """
         Generate HTTP response as CSV file from export_fields property.
         """
         csv_fields = self.get_export_fields()
 
-        qs = self.queryset(request)
+        if queryset is None:
+            queryset = self.queryset(request)
 
         response = HttpResponse(mimetype='text/csv')
         response['Content-Disposition'] = 'attachment; filename=%s.csv' % unicode(self.model._meta.verbose_name_plural)
@@ -172,7 +175,7 @@ class ExportAdmin(admin.ModelAdmin):
             headers.append(attr.encode('utf-8') if isinstance(attr, unicode) else attr)
         writer.writerow(headers)
 
-        for o in qs:
+        for o in queryset:
             row = []
             for attr in csv_fields:
                 value = self.get_object_value(o, attr)
index 0a88115..0bf6b58 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 from setuptools import setup, find_packages
 
 name = 'auf.django.export'
-version = '0.3'
+version = '0.4'
 
 setup(
     name=name,