Skip to content

Commit 4aec197

Browse files
author
Richard Jones
committed
forward-porting of fixed edit action / parsePropsFromForm...
to handle index-page edits better
1 parent 99f864b commit 4aec197

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Fixed:
7979
- fix re-enabling queries (sf bug 861940)
8080
- use supplied content-type on file uploads before trying filename)
8181
- fixed roundup-reminder script to use default schema (thanks Klamer Schutte)
82+
- fixed edit action / parsePropsFromForm to handle index-page edits better
8283

8384

8485
2003-12-17 0.6.4

roundup/cgi/actions.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,18 @@ def handle(self):
295295
self.db.commit()
296296

297297
# redirect to the item's edit page
298-
raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base,
299-
self.classname, self.client.nodeid,
300-
urllib.quote(message),
301-
urllib.quote(self.template))
298+
# redirect to finish off
299+
url = self.base + self.classname
300+
# note that this action might have been called by an index page, so
301+
# we will want to include index-page args in this URL too
302+
if self.nodeid is not None:
303+
url += self.nodeid
304+
url += '?@ok_message=%s&@template=%s'%(urllib.quote(message),
305+
urllib.quote(self.template))
306+
if self.nodeid is None:
307+
req = templating.HTMLRequest(self)
308+
url += '&' + req.indexargs_href('', {})[1:]
309+
raise Redirect, url
302310

303311
def editItemPermission(self, props):
304312
"""Determine whether the user has permission to edit this item.
@@ -325,6 +333,37 @@ def editItemPermission(self, props):
325333
return 1
326334
return 0
327335

336+
def newItemAction(self):
337+
''' Add a new item to the database.
338+
339+
This follows the same form as the editItemAction, with the same
340+
special form values.
341+
'''
342+
# parse the props from the form
343+
try:
344+
props, links = self.parsePropsFromForm(create=True)
345+
except (ValueError, KeyError), message:
346+
self.error_message.append(_('Error: ') + str(message))
347+
return
348+
349+
# handle the props - edit or create
350+
try:
351+
# when it hits the None element, it'll set self.nodeid
352+
messages = self._editnodes(props, links)
353+
354+
except (ValueError, KeyError, IndexError), message:
355+
# these errors might just be indicative of user dumbness
356+
self.error_message.append(_('Error: ') + str(message))
357+
return
358+
359+
# commit now that all the tricky stuff is done
360+
self.db.commit()
361+
362+
# redirect to the new item's page
363+
raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base,
364+
self.classname, self.nodeid, urllib.quote(messages),
365+
urllib.quote(self.template))
366+
328367
def newItemPermission(self, props):
329368
"""Determine whether the user has permission to create (edit) this item.
330369

roundup/cgi/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.156 2004-02-11 23:55:09 richard Exp $
1+
# $Id: client.py,v 1.157 2004-02-13 01:32:37 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -637,5 +637,6 @@ def standard_message(self, to, subject, body, author=None):
637637
except MessageSendError, e:
638638
self.error_message.append(str(e))
639639

640-
def parsePropsFromForm(self):
641-
return FormParser(self).parse()
640+
def parsePropsFromForm(self, create=False):
641+
return FormParser(self).parse(create=create)
642+

roundup/cgi/form_parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, client):
3434
self.classname = client.classname
3535
self.nodeid = client.nodeid
3636

37-
def parse(self, num_re=re.compile('^\d+$')):
37+
def parse(self, create=False, num_re=re.compile('^\d+$')):
3838
""" Item properties and their values are edited with html FORM
3939
variables and their values. You can:
4040
@@ -252,6 +252,10 @@ def parse(self, num_re=re.compile('^\d+$')):
252252
# the thing this value relates to is...
253253
this = (cn, nodeid)
254254

255+
# skip implicit create if this isn't a create action
256+
if not create and nodeid is None:
257+
continue
258+
255259
# get more info about the class, and the current set of
256260
# form props for it
257261
if not all_propdef.has_key(cn):

roundup/cgi/templating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def getItem(self, itemid, num_re=re.compile('-?\d+')):
407407
''' Get an item of this class by its item id.
408408
'''
409409
# make sure we're looking at an itemid
410-
if not num_re.match(itemid):
410+
if not isinstance(itemid, type(1)) and not num_re.match(itemid):
411411
itemid = self._klass.lookup(itemid)
412412

413413
if self.classname == 'user':

0 commit comments

Comments
 (0)