comparison roundup/cgi/actions.py @ 2163:791c66a3b738

fixed CSV export and CGI actions returning results
author Richard Jones <richard@users.sourceforge.net>
date Tue, 30 Mar 2004 06:43:08 +0000
parents 225a0a74ac25
children 12cd4fa91eb7
comparison
equal deleted inserted replaced
2162:53c600091f17 2163:791c66a3b738
1 #$Id: actions.py,v 1.20 2004-03-29 21:56:56 richard Exp $ 1 #$Id: actions.py,v 1.21 2004-03-30 06:43:08 richard Exp $
2 2
3 import re, cgi, StringIO, urllib, Cookie, time, random 3 import re, cgi, StringIO, urllib, Cookie, time, random
4 4
5 from roundup import hyperdb, token, date, password, rcsv, exceptions 5 from roundup import hyperdb, token, date, password, rcsv, exceptions
6 from roundup.i18n import _ 6 from roundup.i18n import _
29 self.user = client.user 29 self.user = client.user
30 30
31 def execute(self): 31 def execute(self):
32 """Execute the action specified by this object.""" 32 """Execute the action specified by this object."""
33 self.permission() 33 self.permission()
34 self.handle() 34 return self.handle()
35 35
36 name = '' 36 name = ''
37 permissionType = None 37 permissionType = None
38 def permission(self): 38 def permission(self):
39 """Check whether the user has permission to execute this action. 39 """Check whether the user has permission to execute this action.
831 permissionType = 'View' 831 permissionType = 'View'
832 832
833 def handle(self): 833 def handle(self):
834 ''' Export the specified search query as CSV. ''' 834 ''' Export the specified search query as CSV. '''
835 # figure the request 835 # figure the request
836 request = templating.HTMLRequest(self) 836 request = templating.HTMLRequest(self.client)
837 filterspec = request.filterspec 837 filterspec = request.filterspec
838 sort = request.sort 838 sort = request.sort
839 group = request.group 839 group = request.group
840 columns = request.columns 840 columns = request.columns
841 klass = self.db.getclass(request.classname) 841 klass = self.db.getclass(request.classname)
845 matches = self.db.indexer.search( 845 matches = self.db.indexer.search(
846 re.findall(r'\b\w{2,25}\b', request.search_text), klass) 846 re.findall(r'\b\w{2,25}\b', request.search_text), klass)
847 else: 847 else:
848 matches = None 848 matches = None
849 849
850 h = self.additional_headers 850 h = self.client.additional_headers
851 h['Content-Type'] = 'text/csv' 851 h['Content-Type'] = 'text/csv'
852 # some browsers will honor the filename here... 852 # some browsers will honor the filename here...
853 h['Content-Disposition'] = 'inline; filename=query.csv' 853 h['Content-Disposition'] = 'inline; filename=query.csv'
854 self.header() 854 self.client.header()
855 writer = rcsv.writer(self.request.wfile) 855 writer = rcsv.writer(self.client.request.wfile)
856 writer.writerow(columns) 856 writer.writerow(columns)
857 857
858 # and search 858 # and search
859 for itemid in klass.filter(matches, filterspec, sort, group): 859 for itemid in klass.filter(matches, filterspec, sort, group):
860 writer.writerow([str(klass.get(itemid, col)) for col in columns]) 860 writer.writerow([str(klass.get(itemid, col)) for col in columns])

Roundup Issue Tracker: http://roundup-tracker.org/