Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 1767:fdaa0b751355
python2.3 CSV support, also missing thankyou in index.txt :)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 28 Aug 2003 04:46:54 +0000 |
| parents | f166cd4fd392 |
| children | 332fe2b77e1c eee2a0f99aea |
comparison
equal
deleted
inserted
replaced
| 1765:14a2f1529759 | 1767:fdaa0b751355 |
|---|---|
| 1 import sys, cgi, urllib, os, re, os.path, time, errno | 1 import sys, cgi, urllib, os, re, os.path, time, errno |
| 2 | 2 |
| 3 from roundup import hyperdb, date | 3 from roundup import hyperdb, date, rcsv |
| 4 from roundup.i18n import _ | 4 from roundup.i18n import _ |
| 5 | 5 |
| 6 try: | 6 try: |
| 7 import cPickle as pickle | 7 import cPickle as pickle |
| 8 except ImportError: | 8 except ImportError: |
| 393 return l | 393 return l |
| 394 | 394 |
| 395 def csv(self): | 395 def csv(self): |
| 396 ''' Return the items of this class as a chunk of CSV text. | 396 ''' Return the items of this class as a chunk of CSV text. |
| 397 ''' | 397 ''' |
| 398 # get the CSV module | 398 if rcsv.error: |
| 399 try: | 399 return rcsv.error |
| 400 import csv | |
| 401 except ImportError: | |
| 402 return 'Sorry, you need the csv module to use this function.\n'\ | |
| 403 'Get it from: http://www.object-craft.com.au/projects/csv/' | |
| 404 | 400 |
| 405 props = self.propnames() | 401 props = self.propnames() |
| 406 p = csv.parser() | |
| 407 s = StringIO.StringIO() | 402 s = StringIO.StringIO() |
| 408 s.write(p.join(props) + '\n') | 403 writer = rcsv.writer(s, rcsv.comma_separated) |
| 404 writer.writerow(props) | |
| 409 for nodeid in self._klass.list(): | 405 for nodeid in self._klass.list(): |
| 410 l = [] | 406 l = [] |
| 411 for name in props: | 407 for name in props: |
| 412 value = self._klass.get(nodeid, name) | 408 value = self._klass.get(nodeid, name) |
| 413 if value is None: | 409 if value is None: |
| 414 l.append('') | 410 l.append('') |
| 415 elif isinstance(value, type([])): | 411 elif isinstance(value, type([])): |
| 416 l.append(':'.join(map(str, value))) | 412 l.append(':'.join(map(str, value))) |
| 417 else: | 413 else: |
| 418 l.append(str(self._klass.get(nodeid, name))) | 414 l.append(str(self._klass.get(nodeid, name))) |
| 419 s.write(p.join(l) + '\n') | 415 writer.writerow(l) |
| 420 return s.getvalue() | 416 return s.getvalue() |
| 421 | 417 |
| 422 def propnames(self): | 418 def propnames(self): |
| 423 ''' Return the list of the names of the properties of this class. | 419 ''' Return the list of the names of the properties of this class. |
| 424 ''' | 420 ''' |
