Skip to content

Commit a69fed1

Browse files
author
Richard Jones
committed
better error handling
1 parent 86a6c90 commit a69fed1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

roundup/cgi_client.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: cgi_client.py,v 1.104 2002-02-20 05:45:17 richard Exp $
18+
# $Id: cgi_client.py,v 1.105 2002-02-20 05:52:10 richard Exp $
1919

2020
__doc__ = """
2121
WWW request handler (also used in the stand-alone server).
@@ -314,7 +314,9 @@ def basicClassEditPage(self):
314314
w = self.write
315315
cn = self.classname
316316
cl = self.db.classes[cn]
317-
props = ['id'] + cl.getprops(protected=0).keys()
317+
idlessprops = cl.getprops(protected=0).keys()
318+
props = ['id'] + idlessprops
319+
318320

319321
# get the CSV module
320322
try:
@@ -328,9 +330,10 @@ def basicClassEditPage(self):
328330
if self.form.has_key('rows'):
329331
rows = self.form['rows'].value.splitlines()
330332
p = csv.parser()
331-
idlessprops = props[1:]
332333
found = {}
334+
line = 0
333335
for row in rows:
336+
line += 1
334337
values = p.parse(row)
335338
# not a complete row, keep going
336339
if not values: continue
@@ -339,6 +342,11 @@ def basicClassEditPage(self):
339342
nodeid, values = values[0], values[1:]
340343
found[nodeid] = 1
341344

345+
# confirm correct weight
346+
if len(idlessprops) != len(values):
347+
w(_('Not enough values on line %(line)s'%{'line':line}))
348+
return
349+
342350
# extract the new values
343351
d = {}
344352
for name, value in zip(idlessprops, values):
@@ -358,7 +366,10 @@ def basicClassEditPage(self):
358366
cl.retire(nodeid)
359367

360368
w(_('''<p class="form-help">You may edit the contents of the
361-
"%(classname)s" class using this form.</p>
369+
"%(classname)s" class using this form. The lines are full-featured
370+
Comma-Separated-Value lines, so you may include commas and even
371+
newlines by enclosing the values in double-quotes ("). Double
372+
quotes themselves must be quoted by doubling ("").</p>
362373
<p class="form-help">Remove entries by deleting their line. Add
363374
new entries by appending
364375
them to the table - put an X in the id column.</p>''')%{'classname':cn})
@@ -1288,6 +1299,10 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
12881299

12891300
#
12901301
# $Log: not supported by cvs2svn $
1302+
# Revision 1.104 2002/02/20 05:45:17 richard
1303+
# Use the csv module for generating the form entry so it's correct.
1304+
# [also noted the sf.net feature request id in the change log]
1305+
#
12911306
# Revision 1.103 2002/02/20 05:05:28 richard
12921307
# . Added simple editing for classes that don't define a templated interface.
12931308
# - access using the admin "class list" interface

0 commit comments

Comments
 (0)