X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fcgi_client.py;h=0e446d48c3416eba68af6f936306d1c5e1bed7cd;hb=cd355af47a60fa0ea49b4a42a376066dae1c7716;hp=661dbb06b9f0d153059a59127998d5b47ae52303;hpb=023725ca22cc80484cd636aaea5b5a5006c189d4;p=roundup.git
diff --git a/roundup/cgi_client.py b/roundup/cgi_client.py
index 661dbb0..0e446d4 100644
--- a/roundup/cgi_client.py
+++ b/roundup/cgi_client.py
@@ -15,7 +15,7 @@
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: cgi_client.py,v 1.102 2002-02-15 07:08:44 richard Exp $
+# $Id: cgi_client.py,v 1.103 2002-02-20 05:05:28 richard Exp $
__doc__ = """
WWW request handler (also used in the stand-alone server).
@@ -298,10 +298,88 @@ function submit_once() {
show_customization = self.customization_widget()
index = htmltemplate.IndexTemplate(self, self.instance.TEMPLATES, cn)
- index.render(filterspec, filter, columns, sort, group,
- show_customization=show_customization)
+ try:
+ index.render(filterspec, filter, columns, sort, group,
+ show_customization=show_customization)
+ except htmltemplate.MissingTemplateError:
+ self.basicClassEditPage()
self.pagefoot()
+ def basicClassEditPage(self):
+ '''Display a basic edit page that allows simple editing of the
+ nodes of the current class
+ '''
+ if self.user != 'admin':
+ raise Unauthorised
+ w = self.write
+ cn = self.classname
+ cl = self.db.classes[cn]
+ props = ['id'] + cl.getprops(protected=0).keys()
+
+ # get the CSV module
+ try:
+ import csv
+ except ImportError:
+ w(_('Sorry, you need the csv module to use this function. You may edit the contents of the
+ "%(classname)s" class using this form. Remove entries by deleting their line. Add
+ new entries by appending
+ them to the table - put an X in the id column.
\n'
+ 'Get it from: http://www.object-craft.com.au/projects/csv/'))
+ return
+
+ # do the edit
+ if self.form.has_key('rows'):
+ rows = self.form['rows'].value.splitlines()
+ p = csv.parser()
+ idlessprops = props[1:]
+ found = {}
+ for row in rows:
+ values = p.parse(row)
+ # not a complete row, keep going
+ if not values: continue
+
+ # extract the nodeid
+ nodeid, values = values[0], values[1:]
+ found[nodeid] = 1
+
+ # extract the new values
+ d = {}
+ for name, value in zip(idlessprops, values):
+ d[name] = value.strip()
+
+ # perform the edit
+ if cl.hasnode(nodeid):
+ # edit existing
+ cl.set(nodeid, **d)
+ else:
+ # new node
+ found[cl.create(**d)] = 1
+
+ # retire the removed entries
+ for nodeid in cl.list():
+ if not found.has_key(nodeid):
+ cl.retire(nodeid)
+
+ w(_('''
%s | |
---|---|
' + '%s |