comparison roundup/cgi/client.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 14a2f1529759
children c8614db86be2
comparison
equal deleted inserted replaced
1765:14a2f1529759 1767:fdaa0b751355
1 # $Id: client.py,v 1.131 2003-08-28 01:39:15 richard Exp $ 1 # $Id: client.py,v 1.132 2003-08-28 04:46:39 richard Exp $
2 2
3 __doc__ = """ 3 __doc__ = """
4 WWW request handler (also used in the stand-alone server). 4 WWW request handler (also used in the stand-alone server).
5 """ 5 """
6 6
7 import os, os.path, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib 7 import os, os.path, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib
8 import binascii, Cookie, time, random, MimeWriter, smtplib, socket, quopri 8 import binascii, Cookie, time, random, MimeWriter, smtplib, socket, quopri
9 import stat, rfc822, string 9 import stat, rfc822, string
10 10
11 from roundup import roundupdb, date, hyperdb, password, token 11 from roundup import roundupdb, date, hyperdb, password, token, rcsv
12 from roundup.i18n import _ 12 from roundup.i18n import _
13 from roundup.cgi.templating import Templates, HTMLRequest, NoTemplate 13 from roundup.cgi.templating import Templates, HTMLRequest, NoTemplate
14 from roundup.cgi import cgitb 14 from roundup.cgi import cgitb
15 from roundup.cgi.PageTemplates import PageTemplate 15 from roundup.cgi.PageTemplates import PageTemplate
16 from roundup.rfc2822 import encode_header 16 from roundup.rfc2822 import encode_header
1217 if not self.editCSVPermission(): 1217 if not self.editCSVPermission():
1218 self.error_message.append( 1218 self.error_message.append(
1219 _('You do not have permission to edit %s' %self.classname)) 1219 _('You do not have permission to edit %s' %self.classname))
1220 1220
1221 # get the CSV module 1221 # get the CSV module
1222 try: 1222 if rcsv.error:
1223 import csv 1223 self.error_message.append(_(rcsv.error))
1224 except ImportError:
1225 self.error_message.append(_(
1226 'Sorry, you need the csv module to use this function.<br>\n'
1227 'Get it from: <a href="http://www.object-craft.com.au/projects/csv/">http://www.object-craft.com.au/projects/csv/'))
1228 return 1224 return
1229 1225
1230 cl = self.db.classes[self.classname] 1226 cl = self.db.classes[self.classname]
1231 idlessprops = cl.getprops(protected=0).keys() 1227 idlessprops = cl.getprops(protected=0).keys()
1232 idlessprops.sort() 1228 idlessprops.sort()
1233 props = ['id'] + idlessprops 1229 props = ['id'] + idlessprops
1234 1230
1235 # do the edit 1231 # do the edit
1236 rows = self.form['rows'].value.splitlines() 1232 rows = StringIO.StringIO(self.form['rows'].value)
1237 p = csv.parser() 1233 reader = rcsv.reader(rows, rcsv.comma_separated)
1238 found = {} 1234 found = {}
1239 line = 0 1235 line = 0
1240 for row in rows[1:]: 1236 for values in reader:
1241 line += 1 1237 line += 1
1242 values = p.parse(row) 1238 if line == 1: continue
1243 # not a complete row, keep going
1244 if not values: continue
1245
1246 # skip property names header 1239 # skip property names header
1247 if values == props: 1240 if values == props:
1248 continue 1241 continue
1249 1242
1250 # extract the nodeid 1243 # extract the nodeid

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