Code

added CSV download of index / search results
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Thu, 25 Mar 2004 00:44:28 +0000 (00:44 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Thu, 25 Mar 2004 00:44:28 +0000 (00:44 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2180 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/cgi/actions.py
roundup/cgi/client.py
templates/classic/html/issue.index.html

index 2c9f6ef13a087d2bd55ad99ebedfa3f6dad1998c..1353736a86681d01589c3d6cb1b4b9599fb3a748 100644 (file)
@@ -1,6 +1,11 @@
 This file contains the changes to the Roundup system over time. The entries
 are given with the most recent entry first.
 
+2004-??-?? 0.7.0b2
+Feature:
+- added CSV export to index pages
+
+
 2004-03-24 0.7.0b1
 Major new features:
 - added postgresql backend (originally from sf patch 761740, many changes
index 4cf09927736e9d217105f2e55f42c08025e46dac..5fbbf228ef1b569ca3f8896e152a248677a02a48 100755 (executable)
@@ -9,7 +9,7 @@ from roundup.mailgw import uidFromAddress
 __all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction',
            'EditCSVAction', 'EditItemAction', 'PassResetAction',
            'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction',
-           'NewItemAction']
+           'NewItemAction', 'ExportCSVAction']
 
 # used by a couple of routines
 chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
@@ -801,3 +801,39 @@ class LoginAction(Action):
         if not password and not stored:
             return 1
         return 0
+
+class ExportCSVAction(Action):
+    name = 'export'
+    permissionType = 'View'
+
+    def handle(self):
+        ''' Export the specified search query as CSV. '''
+        # figure the request
+        request = HTMLRequest(self)
+        filterspec = request.filterspec
+        sort = request.sort
+        group = request.group
+        columns = request.columns
+        klass = self.db.getclass(request.classname)
+
+        # full-text search
+        if request.search_text:
+            matches = self.db.indexer.search(
+                re.findall(r'\b\w{2,25}\b', request.search_text), klass)
+        else:
+            matches = None
+
+        h = self.additional_headers
+        h['Content-Type'] = 'text/csv'
+        # some browsers will honor the filename here...
+        h['Content-Disposition'] = 'inline; filename=query.csv'
+        self.header()
+        writer = rcsv.writer(self.request.wfile)
+        writer.writerow(columns)
+
+        # and search
+        for itemid in klass.filter(matches, filterspec, sort, group):
+            writer.writerow([str(klass.get(itemid, col)) for col in columns])
+
+        return '\n'
+
index 045dce12990b8afc8828b541e46bd35fe82e4f32..a07e72160d0759b0deced98495bf3a17dbe1e6ce 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: client.py,v 1.167 2004-03-24 06:18:59 richard Exp $
+# $Id: client.py,v 1.168 2004-03-25 00:44:28 richard Exp $
 
 """WWW request handler (also used in the stand-alone server).
 """
@@ -520,17 +520,18 @@ class Client:
 
     # these are the actions that are available
     actions = (
-        ('edit',     EditItemAction),
-        ('editcsv',  EditCSVAction),
-        ('new',      NewItemAction),
-        ('register', RegisterAction),
-        ('confrego', ConfRegoAction),
-        ('passrst',  PassResetAction),
-        ('login',    LoginAction),
-        ('logout',   LogoutAction),
-        ('search',   SearchAction),
-        ('retire',   RetireAction),
-        ('show',     ShowAction),
+        ('edit',        EditItemAction),
+        ('editcsv',     EditCSVAction),
+        ('new',         NewItemAction),
+        ('register',    RegisterAction),
+        ('confrego',    ConfRegoAction),
+        ('passrst',     PassResetAction),
+        ('login',       LoginAction),
+        ('logout',      LogoutAction),
+        ('search',      SearchAction),
+        ('retire',      RetireAction),
+        ('show',        ShowAction),
+        ('export_csv',  ExportCSVAction),
     )
     def handle_action(self):
         ''' Determine whether there should be an Action called.
index 8deb1c18c8bb9f41557fd8b370b789c795613535..aff82ae27fa306cd97d1c6819d594f9678eea2f9 100644 (file)
@@ -82,6 +82,9 @@ You are not allowed to view this page.
  </tr>
 </table>
 
+<a tal:attributes="href python:request.indexargs_url('issue',
+            {'@action':'csv_export'})">Download as CSV</a>
+
 <form method="GET" id="index-controls" tal:attributes="action request/classname">
  
  <table class="form">