From fead1d27b689f603b7100afd89247bf0c4e10324 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 13 Feb 2004 01:32:37 +0000 Subject: [PATCH] forward-porting of fixed edit action / parsePropsFromForm to handle index-page edits better git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2078 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 1 + roundup/cgi/actions.py | 47 ++++++++++++++++++++++++++++++++++---- roundup/cgi/client.py | 7 +++--- roundup/cgi/form_parser.py | 6 ++++- roundup/cgi/templating.py | 2 +- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d7d1620..3faf275 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -79,6 +79,7 @@ Fixed: - fix re-enabling queries (sf bug 861940) - use supplied content-type on file uploads before trying filename) - fixed roundup-reminder script to use default schema (thanks Klamer Schutte) +- fixed edit action / parsePropsFromForm to handle index-page edits better 2003-12-17 0.6.4 diff --git a/roundup/cgi/actions.py b/roundup/cgi/actions.py index 994a96f..afc6a10 100755 --- a/roundup/cgi/actions.py +++ b/roundup/cgi/actions.py @@ -295,10 +295,18 @@ class EditItemAction(Action): self.db.commit() # redirect to the item's edit page - raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base, - self.classname, self.client.nodeid, - urllib.quote(message), - urllib.quote(self.template)) + # redirect to finish off + url = self.base + self.classname + # note that this action might have been called by an index page, so + # we will want to include index-page args in this URL too + if self.nodeid is not None: + url += self.nodeid + url += '?@ok_message=%s&@template=%s'%(urllib.quote(message), + urllib.quote(self.template)) + if self.nodeid is None: + req = templating.HTMLRequest(self) + url += '&' + req.indexargs_href('', {})[1:] + raise Redirect, url def editItemPermission(self, props): """Determine whether the user has permission to edit this item. @@ -325,6 +333,37 @@ class EditItemAction(Action): return 1 return 0 + def newItemAction(self): + ''' Add a new item to the database. + + This follows the same form as the editItemAction, with the same + special form values. + ''' + # parse the props from the form + try: + props, links = self.parsePropsFromForm(create=True) + except (ValueError, KeyError), message: + self.error_message.append(_('Error: ') + str(message)) + return + + # handle the props - edit or create + try: + # when it hits the None element, it'll set self.nodeid + messages = self._editnodes(props, links) + + except (ValueError, KeyError, IndexError), message: + # these errors might just be indicative of user dumbness + self.error_message.append(_('Error: ') + str(message)) + return + + # commit now that all the tricky stuff is done + self.db.commit() + + # redirect to the new item's page + raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base, + self.classname, self.nodeid, urllib.quote(messages), + urllib.quote(self.template)) + def newItemPermission(self, props): """Determine whether the user has permission to create (edit) this item. diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index f02e62f..c15b3f1 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.156 2004-02-11 23:55:09 richard Exp $ +# $Id: client.py,v 1.157 2004-02-13 01:32:37 richard Exp $ """WWW request handler (also used in the stand-alone server). """ @@ -637,5 +637,6 @@ class Client: except MessageSendError, e: self.error_message.append(str(e)) - def parsePropsFromForm(self): - return FormParser(self).parse() + def parsePropsFromForm(self, create=False): + return FormParser(self).parse(create=create) + diff --git a/roundup/cgi/form_parser.py b/roundup/cgi/form_parser.py index ded96e4..8ef534d 100755 --- a/roundup/cgi/form_parser.py +++ b/roundup/cgi/form_parser.py @@ -34,7 +34,7 @@ class FormParser: self.classname = client.classname self.nodeid = client.nodeid - def parse(self, num_re=re.compile('^\d+$')): + def parse(self, create=False, num_re=re.compile('^\d+$')): """ Item properties and their values are edited with html FORM variables and their values. You can: @@ -252,6 +252,10 @@ class FormParser: # the thing this value relates to is... this = (cn, nodeid) + # skip implicit create if this isn't a create action + if not create and nodeid is None: + continue + # get more info about the class, and the current set of # form props for it if not all_propdef.has_key(cn): diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index aab6a95..dc15309 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -407,7 +407,7 @@ class HTMLClass(HTMLInputMixin, HTMLPermissions): ''' Get an item of this class by its item id. ''' # make sure we're looking at an itemid - if not num_re.match(itemid): + if not isinstance(itemid, type(1)) and not num_re.match(itemid): itemid = self._klass.lookup(itemid) if self.classname == 'user': -- 2.30.2