Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 3499:230fb5d49c19
CSV encoding support [SF#1240848]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 25 Jan 2006 03:14:40 +0000 |
| parents | a4167cc55cb4 |
| children | 7fb8cfe3c737 |
comparison
equal
deleted
inserted
replaced
| 3498:8fcb2237a8ae | 3499:230fb5d49c19 |
|---|---|
| 1 #$Id: actions.py,v 1.54 2006-01-23 03:42:27 richard Exp $ | 1 #$Id: actions.py,v 1.55 2006-01-25 03:14:40 richard Exp $ |
| 2 | 2 |
| 3 import re, cgi, StringIO, urllib, Cookie, time, random, csv | 3 import re, cgi, StringIO, urllib, Cookie, time, random, csv, codecs |
| 4 | 4 |
| 5 from roundup import hyperdb, token, date, password | 5 from roundup import hyperdb, token, date, password |
| 6 from roundup.i18n import _ | 6 from roundup.i18n import _ |
| 7 import roundup.exceptions | 7 import roundup.exceptions |
| 8 from roundup.cgi import exceptions, templating | 8 from roundup.cgi import exceptions, templating |
| 959 re.findall(r'\b\w{2,25}\b', request.search_text), klass) | 959 re.findall(r'\b\w{2,25}\b', request.search_text), klass) |
| 960 else: | 960 else: |
| 961 matches = None | 961 matches = None |
| 962 | 962 |
| 963 h = self.client.additional_headers | 963 h = self.client.additional_headers |
| 964 h['Content-Type'] = 'text/csv' | 964 h['Content-Type'] = 'text/csv; charset=%s' % self.client.charset |
| 965 # some browsers will honor the filename here... | 965 # some browsers will honor the filename here... |
| 966 h['Content-Disposition'] = 'inline; filename=query.csv' | 966 h['Content-Disposition'] = 'inline; filename=query.csv' |
| 967 | 967 |
| 968 self.client.header() | 968 self.client.header() |
| 969 | 969 |
| 970 if self.client.env['REQUEST_METHOD'] == 'HEAD': | 970 if self.client.env['REQUEST_METHOD'] == 'HEAD': |
| 971 # all done, return a dummy string | 971 # all done, return a dummy string |
| 972 return 'dummy' | 972 return 'dummy' |
| 973 | 973 |
| 974 writer = csv.writer(self.client.request.wfile) | 974 wfile = self.client.request.wfile |
| 975 if self.client.charset != self.client.STORAGE_CHARSET: | |
| 976 wfile = codecs.EncodedFile(wfile, | |
| 977 self.client.STORAGE_CHARSET, self.client.charset, 'replace') | |
| 978 | |
| 979 writer = csv.writer(wfile) | |
| 975 writer.writerow(columns) | 980 writer.writerow(columns) |
| 976 | 981 |
| 977 # and search | 982 # and search |
| 978 for itemid in klass.filter(matches, filterspec, sort, group): | 983 for itemid in klass.filter(matches, filterspec, sort, group): |
| 979 writer.writerow([str(klass.get(itemid, col)) for col in columns]) | 984 writer.writerow([str(klass.get(itemid, col)) for col in columns]) |
