From 7391f717b149244549d88803170e8ffff13805a8 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 25 Mar 2004 00:44:28 +0000 Subject: [PATCH] added CSV download of index / search results git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2180 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 5 ++++ roundup/cgi/actions.py | 38 ++++++++++++++++++++++++- roundup/cgi/client.py | 25 ++++++++-------- templates/classic/html/issue.index.html | 3 ++ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2c9f6ef..1353736 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/roundup/cgi/actions.py b/roundup/cgi/actions.py index 4cf0992..5fbbf22 100755 --- a/roundup/cgi/actions.py +++ b/roundup/cgi/actions.py @@ -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' + diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 045dce1..a07e721 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -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. diff --git a/templates/classic/html/issue.index.html b/templates/classic/html/issue.index.html index 8deb1c1..aff82ae 100644 --- a/templates/classic/html/issue.index.html +++ b/templates/classic/html/issue.index.html @@ -82,6 +82,9 @@ You are not allowed to view this page. +Download as CSV +
-- 2.30.2