Skip to content

Commit 17be879

Browse files
author
Richard Jones
committed
added CSV download of index / search results
1 parent 0315058 commit 17be879

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

4+
2004-??-?? 0.7.0b2
5+
Feature:
6+
- added CSV export to index pages
7+
8+
49
2004-03-24 0.7.0b1
510
Major new features:
611
- added postgresql backend (originally from sf patch 761740, many changes

roundup/cgi/actions.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction',
1010
'EditCSVAction', 'EditItemAction', 'PassResetAction',
1111
'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction',
12-
'NewItemAction']
12+
'NewItemAction', 'ExportCSVAction']
1313

1414
# used by a couple of routines
1515
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
@@ -801,3 +801,39 @@ def verifyPassword(self, userid, password):
801801
if not password and not stored:
802802
return 1
803803
return 0
804+
805+
class ExportCSVAction(Action):
806+
name = 'export'
807+
permissionType = 'View'
808+
809+
def handle(self):
810+
''' Export the specified search query as CSV. '''
811+
# figure the request
812+
request = HTMLRequest(self)
813+
filterspec = request.filterspec
814+
sort = request.sort
815+
group = request.group
816+
columns = request.columns
817+
klass = self.db.getclass(request.classname)
818+
819+
# full-text search
820+
if request.search_text:
821+
matches = self.db.indexer.search(
822+
re.findall(r'\b\w{2,25}\b', request.search_text), klass)
823+
else:
824+
matches = None
825+
826+
h = self.additional_headers
827+
h['Content-Type'] = 'text/csv'
828+
# some browsers will honor the filename here...
829+
h['Content-Disposition'] = 'inline; filename=query.csv'
830+
self.header()
831+
writer = rcsv.writer(self.request.wfile)
832+
writer.writerow(columns)
833+
834+
# and search
835+
for itemid in klass.filter(matches, filterspec, sort, group):
836+
writer.writerow([str(klass.get(itemid, col)) for col in columns])
837+
838+
return '\n'
839+

roundup/cgi/client.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.167 2004-03-24 06:18:59 richard Exp $
1+
# $Id: client.py,v 1.168 2004-03-25 00:44:28 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -520,17 +520,18 @@ def renderContext(self):
520520

521521
# these are the actions that are available
522522
actions = (
523-
('edit', EditItemAction),
524-
('editcsv', EditCSVAction),
525-
('new', NewItemAction),
526-
('register', RegisterAction),
527-
('confrego', ConfRegoAction),
528-
('passrst', PassResetAction),
529-
('login', LoginAction),
530-
('logout', LogoutAction),
531-
('search', SearchAction),
532-
('retire', RetireAction),
533-
('show', ShowAction),
523+
('edit', EditItemAction),
524+
('editcsv', EditCSVAction),
525+
('new', NewItemAction),
526+
('register', RegisterAction),
527+
('confrego', ConfRegoAction),
528+
('passrst', PassResetAction),
529+
('login', LoginAction),
530+
('logout', LogoutAction),
531+
('search', SearchAction),
532+
('retire', RetireAction),
533+
('show', ShowAction),
534+
('export_csv', ExportCSVAction),
534535
)
535536
def handle_action(self):
536537
''' Determine whether there should be an Action called.

templates/classic/html/issue.index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
</tr>
8383
</table>
8484

85+
<a tal:attributes="href python:request.indexargs_url('issue',
86+
{'@action':'csv_export'})">Download as CSV</a>
87+
8588
<form method="GET" id="index-controls" tal:attributes="action request/classname">
8689

8790
<table class="form">

0 commit comments

Comments
 (0)